Skip to content

Commit a5997d1

Browse files
Merge pull request #3594 from jospint/fixGroupedPRDescriptions
fix: Grouped PR description must not include updates ignored via // scala-steward:off
2 parents 55894c7 + 7f845a8 commit a5997d1

File tree

2 files changed

+146
-8
lines changed

2 files changed

+146
-8
lines changed

modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala

+21-5
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ object NewPullRequestData {
5454
): String = {
5555
val migrations = edits.collect { case scalafixEdit: ScalafixEdit => scalafixEdit }
5656
val appliedMigrations = migrationNote(migrations)
57-
val oldVersionDetails = oldVersionNote(filesWithOldVersion, update)
57+
val updateWithEdits = filterUpdateWithEditAttempts(update, edits)
58+
val oldVersionDetails = oldVersionNote(filesWithOldVersion, updateWithEdits)
5859
val details = List(
5960
appliedMigrations,
6061
oldVersionDetails,
61-
adjustFutureUpdates(update).some,
62+
adjustFutureUpdates(updateWithEdits).some,
6263
configParsingError.map(configParsingErrorDetails)
6364
).flatten
6465

65-
val updatesText = update.on(
66+
val updatesText = updateWithEdits.on(
6667
update = u => {
6768
val artifacts = artifactsWithOptionalUrl(u, artifactIdToUrl)
6869

@@ -91,7 +92,7 @@ object NewPullRequestData {
9192
}
9293
)
9394

94-
val skipVersionMessage = update.on(
95+
val skipVersionMessage = updateWithEdits.on(
9596
_ => "If you'd like to skip this version, you can just close this PR. ",
9697
_ => ""
9798
)
@@ -120,7 +121,7 @@ object NewPullRequestData {
120121
val metadataJson =
121122
Json
122123
.obj(
123-
"Update" -> update.asJson,
124+
"Update" -> updateWithEdits.asJson,
124125
"Labels" -> Json.fromValues(labels.map(_.asJson))
125126
)
126127
.toString
@@ -135,6 +136,21 @@ object NewPullRequestData {
135136
else plainBody
136137
}
137138

139+
private def filterUpdateWithEditAttempts(update: Update, edits: List[EditAttempt]): Update =
140+
update match {
141+
case single: Update.Single => single
142+
case grouped: Update.Grouped =>
143+
grouped.copy(updates = grouped.updates.filter { update =>
144+
edits
145+
.collect { case EditAttempt.UpdateEdit(update, _) =>
146+
update.groupAndMainArtifactId
147+
}
148+
.exists { case (groupId, artifactId) =>
149+
update.groupId == groupId && update.mainArtifactId == artifactId
150+
}
151+
})
152+
}
153+
138154
def renderUpdateInfoUrls(updateInfoUrls: List[UpdateInfoUrl]): Option[String] =
139155
Option.when(updateInfoUrls.nonEmpty) {
140156
updateInfoUrls

modules/core/src/test/scala/org/scalasteward/core/forge/data/NewPullRequestDataTest.scala

+125-3
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,20 @@ class NewPullRequestDataTest extends FunSuite {
193193
val update1 = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single
194194
val update2 = ("com.example".g % "foo".a % "1.0.0" %> "2.0.0").single
195195
val update = Update.Grouped("my-group", Some("The PR title"), List(update1, update2))
196+
val edits = List(
197+
UpdateEdit(
198+
update = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single,
199+
commit = Commit(dummySha1)
200+
),
201+
UpdateEdit(
202+
update = ("com.example".g % "foo".a % "1.0.0" %> "2.0.0").single,
203+
commit = Commit(dummySha1)
204+
)
205+
)
196206

197207
val body = bodyFor(
198208
update = update,
199-
edits = List.empty,
209+
edits = edits,
200210
artifactIdToUrl = Map.empty,
201211
artifactIdToUpdateInfoUrls = Map.empty,
202212
filesWithOldVersion = List.empty,
@@ -398,6 +408,107 @@ class NewPullRequestDataTest extends FunSuite {
398408
assertEquals(body, expected)
399409
}
400410

411+
test("bodyFor() grouped update when edits does not contain an update (scala-steward:off case)") {
412+
val update1 = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single
413+
val update2 = ("com.example".g % "foo".a % "1.0.0" %> "2.0.0").single
414+
val update = Update.Grouped("my-group", Some("The PR title"), List(update1, update2))
415+
val edits = List(
416+
UpdateEdit(
417+
update = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single,
418+
commit = Commit(dummySha1)
419+
)
420+
)
421+
422+
val body = bodyFor(
423+
update = update,
424+
edits = edits,
425+
artifactIdToUrl = Map.empty,
426+
artifactIdToUpdateInfoUrls = Map.empty,
427+
filesWithOldVersion = List.empty,
428+
configParsingError = None,
429+
labels = List("library-update"),
430+
maximumPullRequestLength = 65536
431+
)
432+
val expected =
433+
s"""|## About this PR
434+
|Updates:
435+
|
436+
|* 📦 ch.qos.logback:logback-classic from `1.2.0` to `1.2.3`
437+
|
438+
|## Usage
439+
|✅ **Please merge!**
440+
|
441+
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
442+
|
443+
|If you have any feedback, just mention me in the comments below.
444+
|
445+
|Configure Scala Steward for your repository with a [`.scala-steward.conf`](https://github.com/scala-steward-org/scala-steward/blob/${org.scalasteward.core.BuildInfo.gitHeadCommit}/docs/repo-specific-configuration.md) file.
446+
|
447+
|_Have a fantastic day writing Scala!_
448+
|
449+
|<details>
450+
|<summary>⚙ Adjust future updates</summary>
451+
|
452+
|Add these to your `.scala-steward.conf` file to ignore future updates of these dependencies:
453+
|```
454+
|updates.ignore = [
455+
| { groupId = "ch.qos.logback", artifactId = "logback-classic" }
456+
|]
457+
|```
458+
|Or, add these to slow down future updates of these dependencies:
459+
|```
460+
|dependencyOverrides = [
461+
| {
462+
| pullRequests = { frequency = "30 days" },
463+
| dependency = { groupId = "ch.qos.logback", artifactId = "logback-classic" }
464+
| }
465+
|]
466+
|```
467+
|</details>
468+
|
469+
|<sup>
470+
|labels: library-update
471+
|</sup>
472+
|
473+
|<!-- scala-steward = {
474+
| "Update" : {
475+
| "Grouped" : {
476+
| "name" : "my-group",
477+
| "title" : "The PR title",
478+
| "updates" : [
479+
| {
480+
| "ForArtifactId" : {
481+
| "crossDependency" : [
482+
| {
483+
| "groupId" : "ch.qos.logback",
484+
| "artifactId" : {
485+
| "name" : "logback-classic",
486+
| "maybeCrossName" : null
487+
| },
488+
| "version" : "1.2.0",
489+
| "sbtVersion" : null,
490+
| "scalaVersion" : null,
491+
| "configurations" : null
492+
| }
493+
| ],
494+
| "newerVersions" : [
495+
| "1.2.3"
496+
| ],
497+
| "newerGroupId" : null,
498+
| "newerArtifactId" : null
499+
| }
500+
| }
501+
| ]
502+
| }
503+
| },
504+
| "Labels" : [
505+
| "library-update"
506+
| ]
507+
|} -->""".stripMargin
508+
509+
assertEquals(body, expected)
510+
}
511+
401512
test("fromTo") {
402513
val obtained = fromTo(("com.example".g % "foo".a % "1.2.0" %> "1.2.3").single)
403514
assertEquals(obtained, "from `1.2.0` to `1.2.3`")
@@ -837,6 +948,16 @@ class NewPullRequestDataTest extends FunSuite {
837948
val update1 = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single
838949
val update2 = ("com.example".g % "foo".a % "1.0.0" %> "2.0.0").single
839950
val update = Update.Grouped("my-group", None, List(update1, update2))
951+
val edits = List(
952+
UpdateEdit(
953+
update = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single,
954+
commit = Commit(dummySha1)
955+
),
956+
UpdateEdit(
957+
update = ("com.example".g % "foo".a % "1.0.0" %> "2.0.0").single,
958+
commit = Commit(dummySha1)
959+
)
960+
)
840961

841962
val data = UpdateData(
842963
repoData = RepoData(
@@ -851,8 +972,9 @@ class NewPullRequestDataTest extends FunSuite {
851972
updateBranch = Branch("update/logback-classic-1.2.3")
852973
)
853974
val obtained = from(
854-
data,
855-
"scala-steward:update/logback-classic-1.2.3",
975+
data = data,
976+
branchName = "scala-steward:update/logback-classic-1.2.3",
977+
edits = edits,
856978
addLabels = true,
857979
labels = labelsFor(data.update)
858980
)

0 commit comments

Comments
 (0)