Skip to content

Commit cfc35f4

Browse files
authored
Merge pull request #3837 from scala-steward-org/reinstate-commenting-on-superseded-PRs
Reinstate commenting on superseded PRs - now bug #3797 is fixed
2 parents 31521e9 + 0e2e992 commit cfc35f4

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.scalasteward.core.coursier.CoursierAlg
2424
import org.scalasteward.core.data.*
2525
import org.scalasteward.core.data.ProcessResult.{Created, Ignored, Updated}
2626
import org.scalasteward.core.edit.{EditAlg, EditAttempt}
27+
import org.scalasteward.core.forge.ForgeType.GitHub
2728
import org.scalasteward.core.forge.data.*
2829
import org.scalasteward.core.forge.data.NewPullRequestData.{filterLabels, labelsFor}
2930
import org.scalasteward.core.forge.{ForgeApiAlg, ForgeRepoAlg}
@@ -122,10 +123,12 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
122123
oldPr: PullRequestData[Id]
123124
): F[Unit] =
124125
logger.attemptWarn.label_(
125-
s"Closing obsolete PR ${oldPr.url.renderString} for ${oldPr.update.show} in PR #$newNumber - will not comment due to https://github.com/scala-steward-org/scala-steward/issues/3797"
126+
s"Closing obsolete PR ${oldPr.url.renderString} for ${oldPr.update.show} in PR #$newNumber"
126127
) {
127128
val oldRemoteBranch = oldPr.updateBranch.withPrefix("origin/")
128129
for {
130+
_ <- forgeApiAlg
131+
.commentPullRequest(data.repo, oldPr.number, commentForBeingSupersededBy(newNumber))
129132
oldBranchExists <- gitAlg.branchExists(data.repo, oldRemoteBranch)
130133
authors <-
131134
if (oldBranchExists) gitAlg.branchAuthors(data.repo, oldRemoteBranch, data.baseBranch)
@@ -137,6 +140,14 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
137140
} yield ()
138141
}
139142

143+
private def commentForBeingSupersededBy(newNumber: PullRequestNumber): String = config.tpe match {
144+
// If a PR is part of a list element, GitHub renders its title
145+
case GitHub => s"""|Superseded by
146+
|- ${forgeApiAlg.referencePullRequest(newNumber)}
147+
|""".stripMargin.trim
148+
case _ => s"Superseded by ${forgeApiAlg.referencePullRequest(newNumber)}."
149+
}
150+
140151
private def deleteRemoteBranch(repo: Repo, branch: Branch): F[Unit] =
141152
logger.attemptWarn.log_(s"Deleting remote branch ${branch.name} failed") {
142153
val remoteBranch = branch.withPrefix("origin/")

0 commit comments

Comments
 (0)