Skip to content

Commit b8b17c2

Browse files
emdash-iertyley
authored andcommitted
Get everything compiling with VersionWithFirstSeen
# Conflicts: # modules/core/src/main/scala/org/scalasteward/core/data/Update.scala # modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala
1 parent 89bdf94 commit b8b17c2

File tree

10 files changed

+57
-29
lines changed

10 files changed

+57
-29
lines changed

modules/benchmark/src/main/scala/org/scalasteward/benchmark/UpdatesConfigBenchmark.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.openjdk.jmh.annotations.{Benchmark, BenchmarkMode, Mode, OutputTimeUn
2121
import org.scalasteward.core.data.*
2222
import org.scalasteward.core.repoconfig.{UpdatePattern, UpdatesConfig, VersionPattern}
2323
import org.scalasteward.core.util.Nel
24+
import org.scalasteward.core.coursier.VersionsCache.VersionWithFirstSeen
2425

2526
@BenchmarkMode(Array(Mode.AverageTime))
2627
class UpdatesConfigBenchmark {
@@ -32,7 +33,7 @@ class UpdatesConfigBenchmark {
3233
val dependency = CrossDependency(Dependency(groupId, ArtifactId("artifact"), Version("1.0.0")))
3334
val newerVersions = Nel
3435
.of("2.0.0", "2.1.0", "2.1.1", "2.2.0", "3.0.0", "3.1.0", "3.2.1", "3.3.3", "4.0", "5.0")
35-
.map(Version.apply)
36+
.map(v => VersionWithFirstSeen(Version(v), None))
3637
val update = Update.ForArtifactId(dependency, newerVersions)
3738

3839
UpdatesConfig().keep(update)

modules/core/src/main/scala/org/scalasteward/core/buildtool/sbt/SbtAlg.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ final class SbtAlg[F[_]](defaultResolvers: List[Resolver], ignoreOptsFiles: Bool
129129
private def latestSbtScalafixVersion: F[Option[Version]] =
130130
versionsCache
131131
.getVersions(Scope(sbtScalafixDependency, defaultResolvers), None)
132-
.map(_.lastOption)
132+
.map(_.lastOption.map(_.version))
133133

134134
private def runBuildMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] =
135135
for {

modules/core/src/main/scala/org/scalasteward/core/data/Update.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object Update {
8484

8585
final case class ForArtifactId(
8686
crossDependency: CrossDependency,
87-
newerVersions: Nel[VersionWithFirstSeen],
87+
newerVersionsWithFirstSeen: Nel[VersionWithFirstSeen],
8888
newerGroupId: Option[GroupId] = None,
8989
newerArtifactId: Option[String] = None
9090
) extends Single {
@@ -109,6 +109,8 @@ object Update {
109109
override def currentVersion: Version =
110110
crossDependency.head.version
111111

112+
val newerVersions: Nel[Version] = newerVersionsWithFirstSeen.map(_.version)
113+
112114
def artifactId: ArtifactId =
113115
crossDependency.head.artifactId
114116
}
@@ -216,7 +218,12 @@ object Update {
216218
newerGroupId: Option[GroupId],
217219
newerArtifactId: Option[String]
218220
) =>
219-
ForArtifactId(crossDependency, newerVersions, newerGroupId, newerArtifactId)
221+
ForArtifactId(
222+
crossDependency,
223+
newerVersions.map(VersionWithFirstSeen(_, None)),
224+
newerGroupId,
225+
newerArtifactId
226+
)
220227
}
221228

222229
private val forArtifactIdDecoderV2 =

modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatePattern.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.scalasteward.core.repoconfig
1919
import cats.syntax.all.*
2020
import io.circe.Codec
2121
import io.circe.generic.semiauto.*
22-
import org.scalasteward.core.data.{GroupId, Update, Version}
22+
import org.scalasteward.core.data.{GroupId, Update}
2323
import org.scalasteward.core.coursier.VersionsCache.VersionWithFirstSeen
2424

2525
final case class UpdatePattern(
@@ -44,8 +44,10 @@ object UpdatePattern {
4444
): MatchResult = {
4545
val byGroupId = patterns.filter(_.groupId === update.groupId)
4646
val byArtifactId = byGroupId.filter(_.artifactId.forall(_ === update.artifactId.name))
47-
val filteredVersions = update.newerVersions.filter(newVersion =>
48-
(byArtifactId.exists(_.version.forall(_.matches(newVersion.value))) && versionPredicate(
47+
val filteredVersions = update.newerVersionsWithFirstSeen.filter(newVersion =>
48+
(byArtifactId.exists(
49+
_.version.forall(_.matches(newVersion.version.value))
50+
) && versionPredicate(
4951
newVersion
5052
))
5153
=== include

modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final case class UpdatesConfig(
7777
private def isAllowed(update: Update.ForArtifactId): FilterResult = {
7878
val m = UpdatePattern.findMatch(allowOrDefault, update, include = true)
7979
if (m.filteredVersions.nonEmpty)
80-
Right(update.copy(newerVersions = Nel.fromListUnsafe(m.filteredVersions)))
80+
Right(update.copy(newerVersionsWithFirstSeen = Nel.fromListUnsafe(m.filteredVersions)))
8181
else if (allowOrDefault.isEmpty)
8282
Right(update)
8383
else Left(NotAllowedByConfig(update))
@@ -86,7 +86,7 @@ final case class UpdatesConfig(
8686
private def isPinned(update: Update.ForArtifactId): FilterResult = {
8787
val m = UpdatePattern.findMatch(pinOrDefault, update, include = true)
8888
if (m.filteredVersions.nonEmpty)
89-
Right(update.copy(newerVersions = Nel.fromListUnsafe(m.filteredVersions)))
89+
Right(update.copy(newerVersionsWithFirstSeen = Nel.fromListUnsafe(m.filteredVersions)))
9090
else if (m.byArtifactId.isEmpty)
9191
Right(update)
9292
else Left(VersionPinnedByConfig(update))
@@ -95,7 +95,7 @@ final case class UpdatesConfig(
9595
private def isIgnored(update: Update.ForArtifactId): FilterResult = {
9696
val m = UpdatePattern.findMatch(ignoreOrDefault, update, include = false)
9797
if (m.filteredVersions.nonEmpty)
98-
Right(update.copy(newerVersions = Nel.fromListUnsafe(m.filteredVersions)))
98+
Right(update.copy(newerVersionsWithFirstSeen = Nel.fromListUnsafe(m.filteredVersions)))
9999
else
100100
Left(IgnoredByConfig(update))
101101
}

modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ object FilterAlg {
7979
// already on Scala Next
8080
Right(update)
8181
} else {
82-
val filteredVersions = update.newerVersions.filterNot(_ >= scalaNextMinVersion)
82+
val filteredVersions =
83+
update.newerVersionsWithFirstSeen.filterNot(v => v.version >= scalaNextMinVersion)
8384
if (filteredVersions.nonEmpty)
84-
Right(update.copy(newerVersions = Nel.fromListUnsafe(filteredVersions)))
85+
Right(update.copy(newerVersionsWithFirstSeen = Nel.fromListUnsafe(filteredVersions)))
8586
else
8687
Left(IgnoreScalaNext(update))
8788
}
@@ -113,7 +114,7 @@ object FilterAlg {
113114
val allowPreReleases = repoConfig.updatesOrDefault.preRelease(update).isRight
114115

115116
update.currentVersion.selectNext(newerVersions, allowPreReleases) match {
116-
case Some(next) => Right(update.copy(newerVersions = Nel.of(next)))
117+
case Some(next) => Right(update.copy(newerVersionsWithFirstSeen = Nel.of(next)))
117118
case None => Left(NoSuitableNextVersion(update))
118119
}
119120
}

modules/core/src/main/scala/org/scalasteward/core/update/UpdateAlg.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ final class UpdateAlg[F[_]](implicit
8282
private def findNewerVersions(
8383
dependency: Scope[Dependency],
8484
maxAge: Option[FiniteDuration]
85-
): OptionT[F, Nel[Version]] =
85+
): OptionT[F, Nel[VersionsCache.VersionWithFirstSeen]] =
8686
OptionT(versionsCache.getVersions(dependency, maxAge).map { versions =>
87-
Nel.fromList(versions.filter(_ > dependency.value.version))
87+
Nel.fromList(versions.filter(v => v.version > dependency.value.version))
8888
})
8989
}
9090

modules/core/src/test/scala/org/scalasteward/core/TestSyntax.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.scalasteward.core
33
import org.scalasteward.core.data.*
44
import org.scalasteward.core.data.Resolver.IvyRepository
55
import org.scalasteward.core.util.Nel
6+
import org.scalasteward.core.coursier.VersionsCache.VersionWithFirstSeen
67

78
object TestSyntax {
89
val sbtPluginReleases: IvyRepository = {
@@ -19,6 +20,7 @@ object TestSyntax {
1920
def g: GroupId = GroupId(self)
2021
def a: ArtifactId = ArtifactId(self)
2122
def v: Version = Version(self)
23+
def vfs: VersionWithFirstSeen = VersionWithFirstSeen(Version(self), None)
2224
}
2325

2426
implicit class StringTupleOps(private val self: (String, String)) extends AnyVal {
@@ -76,29 +78,29 @@ object TestSyntax {
7678
private val self: (Dependency, String)
7779
) extends AnyVal {
7880
def single: Update.ForArtifactId =
79-
Update.ForArtifactId(CrossDependency(self._1), Nel.of(self._2.v))
81+
Update.ForArtifactId(CrossDependency(self._1), Nel.of(self._2.vfs))
8082
}
8183

8284
implicit class DependencyAndNewerVersionsOps(
8385
private val self: (Dependency, Nel[String])
8486
) extends AnyVal {
8587
def single: Update.ForArtifactId =
86-
Update.ForArtifactId(CrossDependency(self._1), self._2.map(_.v))
88+
Update.ForArtifactId(CrossDependency(self._1), self._2.map(_.vfs))
8789
}
8890

8991
implicit class DependenciesAndNextVersionOps(
9092
private val self: (Nel[Dependency], String)
9193
) extends AnyVal {
9294
def single: Update.ForArtifactId =
93-
Update.ForArtifactId(CrossDependency(self._1), Nel.of(self._2.v))
95+
Update.ForArtifactId(CrossDependency(self._1), Nel.of(self._2.vfs))
9496
}
9597

9698
implicit class GroupIdAndArtifactIdsAndVersionAndNextVersionOps(
9799
private val self: (GroupId, Nel[ArtifactId], String, String)
98100
) extends AnyVal {
99101
def single: Update.ForArtifactId = {
100102
val crossDependency = CrossDependency(self._2.map(aId => Dependency(self._1, aId, self._3.v)))
101-
Update.ForArtifactId(crossDependency, Nel.of(self._4.v))
103+
Update.ForArtifactId(crossDependency, Nel.of(self._4.vfs))
102104
}
103105

104106
def group: Update.ForGroupId = {

modules/core/src/test/scala/org/scalasteward/core/nurture/PullRequestRepositoryTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PullRequestRepositoryTest extends FunSuite {
8181

8282
test("getObsoleteOpenPullRequests for single update") {
8383
val data = openPRFor(portableScala)
84-
val nextUpdate = portableScala.copy(newerVersions = Nel.of("1.0.1".v))
84+
val nextUpdate = portableScala.copy(newerVersionsWithFirstSeen = Nel.of("1.0.1".vfs))
8585

8686
val (emptyResult, result, closedResult) =
8787
executeOnTestRepo(expectedStoreOps = Seq("read", "write", "write")) { repo =>

modules/core/src/test/scala/org/scalasteward/core/update/FilterAlgTest.scala

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,26 @@ class FilterAlgTest extends FunSuite {
2828

2929
test("localFilter: update without bad version") {
3030
val update = ("com.jsuereth".g % "sbt-pgp".a % "1.1.0" %> Nel.of("1.1.2", "2.0.0")).single
31-
assertEquals(localFilter(update, config), Right(update.copy(newerVersions = Nel.of("1.1.2".v))))
31+
assertEquals(
32+
localFilter(update, config),
33+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("1.1.2".vfs)))
34+
)
3235
}
3336

3437
test("localFilter: update with bad version") {
3538
val update = ("com.jsuereth".g % "sbt-pgp".a % "1.1.2-1" %> Nel.of("1.1.2", "2.0.0")).single
36-
assertEquals(localFilter(update, config), Right(update.copy(newerVersions = Nel.of("2.0.0".v))))
39+
assertEquals(
40+
localFilter(update, config),
41+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("2.0.0".vfs)))
42+
)
3743
}
3844

3945
test("localFilter: update with bad version 2") {
4046
val update = ("net.sourceforge.plantuml".g % "plantuml".a % "1.2019.11" %>
4147
Nel.of("7726", "8020", "2017.09", "1.2019.12")).single
4248
assertEquals(
4349
localFilter(update, config),
44-
Right(update.copy(newerVersions = Nel.of("1.2019.12".v)))
50+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("1.2019.12".vfs)))
4551
)
4652
}
4753

@@ -58,7 +64,7 @@ class FilterAlgTest extends FunSuite {
5864
config.updatesOrDefault.copy(allowPreReleases = allowedPreReleases.some).some
5965
)
6066

61-
val expected = Right(update.copy(newerVersions = Nel.of("2.0.1-M3".v)))
67+
val expected = Right(update.copy(newerVersionsWithFirstSeen = Nel.of("2.0.1-M3".vfs)))
6268
assertEquals(localFilter(update, configWithAllowed), expected)
6369
}
6470

@@ -111,7 +117,7 @@ class FilterAlgTest extends FunSuite {
111117
).some
112118
).some
113119
)
114-
val expected = Right(update.copy(newerVersions = Nel.of("2.13.7".v)))
120+
val expected = Right(update.copy(newerVersionsWithFirstSeen = Nel.of("2.13.7".vfs)))
115121
assertEquals(localFilter(update, config), expected)
116122
}
117123

@@ -214,7 +220,10 @@ class FilterAlgTest extends FunSuite {
214220
)
215221

216222
val filtered = localFilter(update, config)
217-
assertEquals(filtered, Right(update.copy(newerVersions = Nel.of("7.3.0.jre8".v))))
223+
assertEquals(
224+
filtered,
225+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("7.3.0.jre8".vfs)))
226+
)
218227
}
219228

220229
test("ignore update via config updates.ignore using suffix") {
@@ -234,7 +243,10 @@ class FilterAlgTest extends FunSuite {
234243
)
235244

236245
val filtered = localFilter(update, config)
237-
assertEquals(filtered, Right(update.copy(newerVersions = Nel.of("7.3.0.jre8".v))))
246+
assertEquals(
247+
filtered,
248+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("7.3.0.jre8".vfs)))
249+
)
238250
}
239251

240252
test("ignore update via config updates.pin using prefix and suffix") {
@@ -263,7 +275,7 @@ class FilterAlgTest extends FunSuite {
263275
"""updates.ignore = [ { groupId = "sqlserver", version = { contains = "feature" } } ]"""
264276
)
265277
val obtained = repoConfig.flatMap(localFilter(update, _).leftMap(_.show))
266-
assertEquals(obtained, Right(update.copy(newerVersions = Nel.of("7.3.0".v))))
278+
assertEquals(obtained, Right(update.copy(newerVersionsWithFirstSeen = Nel.of("7.3.0".vfs))))
267279
}
268280

269281
test("isDependencyConfigurationIgnored: false") {
@@ -287,7 +299,10 @@ class FilterAlgTest extends FunSuite {
287299
"3.3.3",
288300
"3.4.0"
289301
)).single
290-
assertEquals(scalaLTSFilter(update), Right(update.copy(newerVersions = Nel.of("3.3.3".v))))
302+
assertEquals(
303+
scalaLTSFilter(update),
304+
Right(update.copy(newerVersionsWithFirstSeen = Nel.of("3.3.3".vfs)))
305+
)
291306
}
292307

293308
test("scalaLTSFilter: Next") {

0 commit comments

Comments
 (0)