Skip to content

Commit d051833

Browse files
committed
Include artifact differences in short report
1 parent 2cc578b commit d051833

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/main/resources/messages.properties

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ lock.status.dependencies.none=no dependencies
2020
lock.status.dependencies.singular=1 dependency
2121
lock.status.dependencies.multiple={0} dependencies
2222

23+
# lockfile short status - artifacts ============================================
24+
lock.status.artifacts.changed.none=
25+
lock.status.artifacts.changed.singular=\ \ 1 dependency artifacts changed
26+
lock.status.artifacts.changed.multiple=\ \ {0} dependency artifacts changed
27+
2328
# lockfile full status - configurations =======================================
2429

2530
lock.status.full.configs.added.none=
@@ -45,7 +50,6 @@ lock.status.full.dependencies.changed.singular=\ \ 1 dependency changed:\n{1}
4550
lock.status.full.dependencies.changed.multiple=\ \ {0} dependencies changed:\n{1}
4651

4752
# lockfile full status - artifacts ============================================
48-
4953
lock.status.full.artifacts.changed.none=
5054
lock.status.full.artifacts.changed.singular=\ \ 1 dependency artifacts changed:\n{1}
5155
lock.status.full.artifacts.changed.multiple=\ \ {0} dependency artifacts changed:\n{1}

src/main/scala/software/purpledragon/sbt/lock/model/LockFileStatus.scala

+19-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ final case class LockFileDiffers(
8080
)
8181
}
8282

83-
if (addedDependencies.nonEmpty || removedDependencies.nonEmpty || changedDependencies.nonEmpty) {
83+
val (otherChanged, artifactChanged) = separateArtifactChanges(changedDependencies)
84+
85+
if (addedDependencies.nonEmpty || removedDependencies.nonEmpty || otherChanged.nonEmpty) {
8486
errors += MessageUtil.formatMessage(
8587
"lock.status.dependencies.info",
8688
MessageUtil.formatPlural("lock.status.dependencies", addedDependencies.size),
@@ -89,6 +91,10 @@ final case class LockFileDiffers(
8991
)
9092
}
9193

94+
if (artifactChanged.nonEmpty) {
95+
errors += MessageUtil.formatPlural("lock.status.artifacts.changed", artifactChanged.size)
96+
}
97+
9298
MessageUtil.formatMessage("lock.status.failed.short", errors.mkString("\n"))
9399
}
94100

@@ -152,14 +158,13 @@ final case class LockFileDiffers(
152158
table.toString()
153159
}
154160

155-
val (depChanged, artChanged) =
156-
changedDependencies.partition(change => change.configurationsChanged || change.versionChanged)
161+
val (otherChanged, artifactChanged) = separateArtifactChanges(changedDependencies)
157162

158-
if (depChanged.nonEmpty) {
163+
if (otherChanged.nonEmpty) {
159164
errors += MessageUtil.formatPlural(
160165
"lock.status.full.dependencies.changed",
161-
depChanged.size,
162-
dumpChanges(depChanged))
166+
otherChanged.size,
167+
dumpChanges(otherChanged))
163168
}
164169

165170
def dumpArtifactChanges(changes: Seq[ChangedDependency]): String = {
@@ -196,13 +201,18 @@ final case class LockFileDiffers(
196201
changesBuilder.toString()
197202
}
198203

199-
if (artChanged.nonEmpty) {
204+
if (artifactChanged.nonEmpty) {
200205
errors += MessageUtil.formatPlural(
201206
"lock.status.full.artifacts.changed",
202-
artChanged.size,
203-
dumpArtifactChanges(artChanged))
207+
artifactChanged.size,
208+
dumpArtifactChanges(artifactChanged))
204209
}
205210

206211
MessageUtil.formatMessage("lock.status.failed.long", errors.mkString("\n"))
207212
}
213+
214+
private def separateArtifactChanges(
215+
changedDependencies: Seq[ChangedDependency]): (Seq[ChangedDependency], Seq[ChangedDependency]) = {
216+
changedDependencies.partition(change => change.configurationsChanged || change.versionChanged)
217+
}
208218
}

src/test/scala/software/purpledragon/sbt/lock/model/LockFileStatusSpec.scala

+30
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
8888
LockFileMatches.withDependencyChanges(Nil, Nil, Seq(testChangedDependency())).toShortReport shouldBe expected
8989
}
9090

91+
it should "render 2 dependency artifacts changed" in {
92+
val expected =
93+
"""Dependency lock check failed:
94+
| 2 dependency artifacts changed""".stripMargin
95+
96+
LockFileMatches
97+
.withDependencyChanges(
98+
Nil,
99+
Nil,
100+
Seq(
101+
testChangedDependencyArtifacts(
102+
"dependency-1",
103+
"1.1",
104+
added = Seq(ResolvedArtifact("artifact-2.jar", "sha1:07c10d545325e3a6e72e06381afe469fd40eb701")),
105+
removed = Seq(ResolvedArtifact("artifact-1.jar", "sha1:2b8b815229aa8a61e483fb4ba0588b8b6c491890"))
106+
),
107+
testChangedDependencyArtifacts(
108+
"dependency-2",
109+
"1.1.2",
110+
changed = Seq(
111+
ChangedArtifact(
112+
"artifact-a.jar",
113+
"sha1:07c10d545325e3a6e72e06381afe469fd40eb701",
114+
"sha1:cfa4f316351a91bfd95cb0644c6a2c95f52db1fc"))
115+
)
116+
)
117+
)
118+
.toShortReport shouldBe expected
119+
}
120+
91121
it should "render configs and dependencies changed" in {
92122
val expected =
93123
"""Dependency lock check failed:

0 commit comments

Comments
 (0)