Skip to content

Commit 83d4acb

Browse files
committed
Actually compiles...
1 parent e63ace3 commit 83d4acb

File tree

15 files changed

+174
-143
lines changed

15 files changed

+174
-143
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UpdatesConfigBenchmark {
3333
val newerVersions = Nel
3434
.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")
3535
.map(Version.apply)
36-
val update = Update.ForArtifactId(dependency, newerVersions)
36+
val update = ArtifactUpdateCandidates(ArtifactForUpdate(dependency), newerVersions)
3737

3838
UpdatesConfig().keep(update)
3939
UpdatesConfig(allow = Some(List(UpdatePattern(groupId, None, None)))).keep(update)

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

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,44 @@ import org.scalasteward.core.repoconfig.PullRequestGroup
2323
import org.scalasteward.core.util
2424
import org.scalasteward.core.util.Nel
2525

26-
27-
case class ArtifactUpdateCandidates(
26+
case class ArtifactForUpdate(
2827
crossDependency: CrossDependency,
29-
newerVersions: Nel[Version],
3028
newerGroupId: Option[GroupId] = None,
3129
newerArtifactId: Option[String] = None
3230
) {
33-
def groupId: GroupId =
34-
crossDependency.head.groupId
35-
36-
def dependencies: Nel[Dependency] =
37-
crossDependency.dependencies
38-
39-
def artifactIds: Nel[ArtifactId] =
40-
dependencies.map(_.artifactId)
41-
//
42-
// override def mainArtifactId: String =
43-
// artifactId.name
44-
//
45-
def show: String =
46-
s"$groupId:${crossDependency.showArtifactNames} : ${Version.show((currentVersion +: newerVersions.toList)*)}"
47-
48-
def currentVersion: Version =
49-
crossDependency.head.version
50-
51-
def artifactId: ArtifactId =
52-
crossDependency.head.artifactId
31+
def groupId: GroupId = crossDependency.head.groupId
32+
33+
def dependencies: Nel[Dependency] = crossDependency.dependencies
34+
35+
def artifactId: ArtifactId = crossDependency.head.artifactId
36+
37+
def artifactIds: Nel[ArtifactId] = dependencies.map(_.artifactId)
38+
//
39+
// override def mainArtifactId: String =
40+
// artifactId.name
41+
//
42+
def currentVersion: Version = crossDependency.head.version
43+
}
44+
45+
trait ArtifactUpdateVersions {
46+
val artifactForUpdate: ArtifactForUpdate
47+
48+
val refersToUpdateVersions: Nel[Version]
49+
50+
def show: String
51+
}
52+
53+
case class ArtifactUpdateCandidates(
54+
artifactForUpdate: ArtifactForUpdate,
55+
newerVersions: Nel[Version]
56+
) extends ArtifactUpdateVersions {
57+
override val refersToUpdateVersions: Nel[Version] = newerVersions
58+
59+
def asSpecificUpdate(nextVersion: Version): Update.ForArtifactId =
60+
Update.ForArtifactId(artifactForUpdate, nextVersion)
61+
62+
override def show: String =
63+
s"${artifactForUpdate.groupId}:${artifactForUpdate.crossDependency.showArtifactNames} : ${Version.show((artifactForUpdate.currentVersion +: refersToUpdateVersions.toList)*)}"
5364
}
5465

5566
sealed trait Update {
@@ -97,44 +108,41 @@ object Update {
97108
s"$groupId:$showArtifacts : ${Version.show(currentVersion, nextVersion)}"
98109

99110
def withVersionData(nextVersion: Version): Update.Single = this match {
100-
case s @ ForArtifactId(_, _, _, _) =>
111+
case s : ForArtifactId =>
101112
s.copy(nextVersion = nextVersion)
102113
case ForGroupId(forArtifactIds) =>
103114
ForGroupId(forArtifactIds.map(_.copy(nextVersion = nextVersion)))
104115
}
105116
}
106117

107118
final case class ForArtifactId(
108-
crossDependency: CrossDependency,
109-
nextVersion: Version,
110-
newerGroupId: Option[GroupId] = None,
111-
newerArtifactId: Option[String] = None
112-
) extends Single {
113-
override def forArtifactIds: Nel[ForArtifactId] =
114-
Nel.one(this)
119+
artifactForUpdate: ArtifactForUpdate,
120+
nextVersion: Version
121+
) extends Single with ArtifactUpdateVersions {
122+
override val refersToUpdateVersions: Nel[Version] = Nel.one(nextVersion)
115123

116-
override def crossDependencies: Nel[CrossDependency] =
117-
Nel.one(crossDependency)
124+
val crossDependency: CrossDependency = artifactForUpdate.crossDependency
118125

119-
override def dependencies: Nel[Dependency] =
120-
crossDependency.dependencies
126+
val headDependency: Dependency = crossDependency.head
121127

122-
override def groupId: GroupId =
123-
crossDependency.head.groupId
128+
override def forArtifactIds: Nel[ForArtifactId] = Nel.one(this)
124129

125-
override def artifactIds: Nel[ArtifactId] =
126-
dependencies.map(_.artifactId)
130+
override def crossDependencies: Nel[CrossDependency] = Nel.one(crossDependency)
131+
132+
override def dependencies: Nel[Dependency] = crossDependency.dependencies
133+
134+
override def groupId: GroupId = headDependency.groupId
127135

128-
override def mainArtifactId: String =
129-
artifactId.name
136+
override def artifactIds: Nel[ArtifactId] = dependencies.map(_.artifactId)
137+
138+
override def mainArtifactId: String = artifactId.name
130139

131140
override def showArtifacts: String = crossDependency.showArtifactNames
132141

133-
override def currentVersion: Version =
134-
crossDependency.head.version
142+
override def currentVersion: Version = headDependency.version
143+
144+
def artifactId: ArtifactId = headDependency.artifactId
135145

136-
def artifactId: ArtifactId =
137-
crossDependency.head.artifactId
138146
}
139147

140148
final case class ForGroupId(
@@ -190,8 +198,9 @@ object Update {
190198
val groups0 =
191199
updates.groupByNel(s => (s.groupId, s.artifactId.name, s.currentVersion, s.nextVersion))
192200
val groups1 = groups0.values.map { group =>
193-
val dependencies = group.flatMap(_.crossDependency.dependencies).distinct.sorted
194-
group.head.copy(crossDependency = CrossDependency(dependencies))
201+
val dependencies = group.flatMap(_.artifactForUpdate.crossDependency.dependencies).distinct.sorted
202+
val update: Update.ForArtifactId = group.head
203+
update.copy(artifactForUpdate = update.artifactForUpdate.copy(crossDependency = CrossDependency(dependencies)))
195204
}
196205
groups1.toList.distinct.sortBy(u => u: Update.Single)
197206
}
@@ -230,20 +239,20 @@ object Update {
230239

231240
implicit private val forArtifactIdEncoder: Encoder[ForArtifactId] =
232241
Encoder.forProduct1("ForArtifactId")(identity[ForArtifactId]) {
233-
Encoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
234-
s => (s.crossDependency, s.nextVersion, s.newerGroupId, s.newerArtifactId)
242+
Encoder.forProduct4("crossDependency", "newerVersions", "newerGroupId", "newerArtifactId") {
243+
s => (s.crossDependency, Seq(s.nextVersion), s.artifactForUpdate.newerGroupId, s.artifactForUpdate.newerArtifactId)
235244
}
236245
}
237246

238247
private val unwrappedForArtifactIdDecoder: Decoder[ForArtifactId] =
239-
Decoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
248+
Decoder.forProduct4("crossDependency", "newerVersions", "newerGroupId", "newerArtifactId") {
240249
(
241250
crossDependency: CrossDependency,
242-
nextVersion: Version,
251+
newerVersions: List[Version],
243252
newerGroupId: Option[GroupId],
244253
newerArtifactId: Option[String]
245254
) =>
246-
ForArtifactId(crossDependency, nextVersion, newerGroupId, newerArtifactId)
255+
ForArtifactId(ArtifactForUpdate(crossDependency, newerGroupId, newerArtifactId), newerVersions.head)
247256
}
248257

249258
private val forArtifactIdDecoderV2 =

modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ object Selector {
204204
update: Update.Single,
205205
modulePositions: List[ModulePosition]
206206
): List[Substring.Replacement] =
207-
update.forArtifactIds.toList.flatMap { forArtifactId =>
208-
val newerGroupId = forArtifactId.newerGroupId
209-
val newerArtifactId = forArtifactId.newerArtifactId
207+
update.forArtifactIds.toList.map(_.artifactForUpdate).flatMap { artifactForUpdate =>
208+
val newerGroupId = artifactForUpdate.newerGroupId
209+
val newerArtifactId = artifactForUpdate.newerArtifactId
210210
if (newerGroupId.isEmpty && newerArtifactId.isEmpty) List.empty
211211
else {
212-
val currentGroupId = forArtifactId.groupId
213-
val currentArtifactId = forArtifactId.artifactIds.head
212+
val currentGroupId = artifactForUpdate.groupId
213+
val currentArtifactId = artifactForUpdate.artifactIds.head
214214
modulePositions
215215
.filter { p =>
216216
p.groupId.value === currentGroupId.value &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ object NewPullRequestData {
363363

364364
val artifactMigrationsLabel = Option.when {
365365
update.asSingleUpdates
366-
.flatMap(_.forArtifactIds.toList)
366+
.flatMap(_.forArtifactIds.toList.map(_.artifactForUpdate))
367367
.exists(u => u.newerGroupId.nonEmpty || u.newerArtifactId.nonEmpty)
368368
}("artifact-migrations")
369369
val scalafixLabel = edits.collectFirst { case _: ScalafixEdit => "scalafix-migrations" }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ final case class RetractedArtifact(
2525
doc: String,
2626
artifacts: List[UpdatePattern] = List.empty
2727
) {
28-
def isRetracted(updateSingle: Update.Single): Boolean = // NextVersion, because the PR already raised?
28+
def isRetracted(updateSingle: Update.Single): Boolean =
2929
updateSingle.forArtifactIds.exists { updateForArtifactId =>
3030
UpdatePattern
31-
.findMatch(artifacts, updateForArtifactId.transformVersionData(_.asNewerVersions), include = true)
31+
.findMatch(artifacts, updateForArtifactId, include = true)
3232
.filteredVersions
3333
.nonEmpty
3434
}

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

Lines changed: 6 additions & 5 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.{ArtifactUpdateCandidates, GroupId, Version}
22+
import org.scalasteward.core.data.{ArtifactUpdateCandidates, ArtifactUpdateVersions, GroupId, Version}
2323

2424
final case class UpdatePattern(
2525
groupId: GroupId,
@@ -37,12 +37,13 @@ object UpdatePattern {
3737

3838
def findMatch(
3939
patterns: List[UpdatePattern],
40-
update: ArtifactUpdateCandidates,
40+
update: ArtifactUpdateVersions,
4141
include: Boolean
4242
): MatchResult = {
43-
val byGroupId = patterns.filter(_.groupId === update.groupId)
44-
val byArtifactId = byGroupId.filter(_.artifactId.forall(_ === update.artifactId.name))
45-
val filteredVersions = update.newerVersions.filter(newVersion =>
43+
val artifactForUpdate = update.artifactForUpdate
44+
val byGroupId = patterns.filter(_.groupId === artifactForUpdate.groupId)
45+
val byArtifactId = byGroupId.filter(_.artifactId.forall(_ === artifactForUpdate.artifactId.name))
46+
val filteredVersions = update.refersToUpdateVersions.filter(newVersion =>
4647
byArtifactId.exists(_.version.forall(_.matches(newVersion.value))) === include
4748
)
4849
MatchResult(byArtifactId, filteredVersions)

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class FilterAlg[F[_]](implicit
3333
update: ArtifactUpdateCandidates
3434
): F[Option[Update.ForArtifactId]] =
3535
localFilter(update, config) match {
36-
case Right(update) => F.pure(update.transformVersionData(_.toNextVersion).some)
36+
case Right(update) => F.pure(update.some)
3737
case Left(reason) =>
3838
logger.info(s"Ignore ${reason.update.show} (reason: ${reason.show})").as(None)
3939
}
@@ -44,7 +44,7 @@ object FilterAlg {
4444
type FilterResult = Either[RejectionReason, ArtifactUpdateCandidates]
4545

4646
sealed trait RejectionReason {
47-
def update: ArtifactUpdateCandidates
47+
def update: ArtifactUpdateVersions
4848
def show: String =
4949
this match {
5050
case IgnoredByConfig(_) => "ignored by config"
@@ -60,20 +60,20 @@ object FilterAlg {
6060
final case class VersionPinnedByConfig(update: ArtifactUpdateCandidates) extends RejectionReason
6161
final case class NotAllowedByConfig(update: ArtifactUpdateCandidates) extends RejectionReason
6262
final case class NoSuitableNextVersion(update: ArtifactUpdateCandidates) extends RejectionReason
63-
final case class VersionOrderingConflict(update: ArtifactUpdateCandidates) extends RejectionReason
63+
final case class VersionOrderingConflict(update: Update.ForArtifactId) extends RejectionReason
6464
final case class IgnoreScalaNext(update: ArtifactUpdateCandidates) extends RejectionReason
6565

66-
def localFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): FilterResult =
66+
def localFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): Either[RejectionReason, Update.ForArtifactId] =
6767
repoConfig.updatesOrDefault
6868
.keep(update)
6969
.flatMap(scalaLTSFilter)
7070
.flatMap(globalFilter(_, repoConfig))
7171

7272
def scalaLTSFilter(update: ArtifactUpdateCandidates): FilterResult =
73-
if (!isScala3Lang(update))
73+
if (!isScala3Lang(update.artifactForUpdate))
7474
Right(update)
7575
else {
76-
if (update.currentVersion >= scalaNextMinVersion) {
76+
if (update.artifactForUpdate.currentVersion >= scalaNextMinVersion) {
7777
// already on Scala Next
7878
Right(update)
7979
} else {
@@ -85,12 +85,12 @@ object FilterAlg {
8585
}
8686
}
8787

88-
def isScala3Lang(update: ArtifactUpdateCandidates): Boolean =
88+
def isScala3Lang(artifactForUpdate: ArtifactForUpdate): Boolean =
8989
scala3LangModules.exists { case (g, a) =>
90-
update.groupId == g && update.artifactIds.exists(_.name == a.name)
90+
artifactForUpdate.groupId == g && artifactForUpdate.artifactId.name == a.name
9191
}
9292

93-
private def globalFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): FilterResult =
93+
private def globalFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): Either[RejectionReason, Update.ForArtifactId] =
9494
selectSuitableNextVersion(update, repoConfig).flatMap(checkVersionOrdering)
9595

9696
def isDependencyConfigurationIgnored(dependency: Dependency): Boolean =
@@ -106,20 +106,20 @@ object FilterAlg {
106106
private def selectSuitableNextVersion(
107107
update: ArtifactUpdateCandidates,
108108
repoConfig: RepoConfig
109-
): FilterResult = {
109+
): Either[RejectionReason, Update.ForArtifactId] = {
110110
val newerVersions = update.newerVersions.toList
111111
val allowPreReleases = repoConfig.updatesOrDefault.preRelease(update).isRight
112-
val maybeNext = update.currentVersion.selectNext(newerVersions, allowPreReleases)
112+
val maybeNext = update.artifactForUpdate.currentVersion.selectNext(newerVersions, allowPreReleases)
113113

114114
maybeNext match {
115-
case Some(next) => Right(update.copy(newerVersions = Nel.of(next))) // TODO but we _could_ go singular at this point
115+
case Some(next) => Right(update.asSpecificUpdate(nextVersion = next))
116116
case None => Left(NoSuitableNextVersion(update))
117117
}
118118
}
119119

120-
private def checkVersionOrdering(update: ArtifactUpdateCandidates): FilterResult = {
120+
private def checkVersionOrdering(update: Update.ForArtifactId): Either[RejectionReason, Update.ForArtifactId] = {
121121
val current = coursier.core.Version(update.currentVersion.value)
122-
val next = coursier.core.Version(update.versionData.toNextVersion.nextVersion.value) // TODO is this the right change?
122+
val next = coursier.core.Version(update.nextVersion.value)
123123
if (current > next) Left(VersionOrderingConflict(update)) else Right(update)
124124
}
125125
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class PruningAlg[F[_]](implicit
8888
}
8989
}
9090
val seenUpdates = allUpdates.filterNot { u =>
91-
maybeOutdatedDeps.exists(_.value === u.crossDependency.head)
91+
maybeOutdatedDeps.exists(_.value === u.artifactForUpdate.crossDependency.head)
9292
}
9393
updateAlg.findUpdates(maybeOutdatedDeps, repoConfig, Some(5.minutes)).map(_ ++ seenUpdates)
9494
}
@@ -169,7 +169,7 @@ final class PruningAlg[F[_]](implicit
169169
repoConfig.dependencyOverridesOrDefault
170170
.collectFirstSome { groupRepoConfig =>
171171
val matchResult = UpdatePattern
172-
.findMatch(List(groupRepoConfig.dependency), dependencyOutdated.update.transformVersionData(_.asNewerVersions), include = true)
172+
.findMatch(List(groupRepoConfig.dependency), dependencyOutdated.update, include = true)
173173
Option.when(matchResult.byArtifactId.nonEmpty && matchResult.filteredVersions.nonEmpty)(
174174
(groupRepoConfig.pullRequests.frequency, artifactLastPrCreatedAt)
175175
)

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class UpdateAlg[F[_]](implicit
5555
maxAge: Option[FiniteDuration]
5656
): OptionT[F, ArtifactUpdateCandidates] =
5757
findNewerVersions(dependency, maxAge).map { newerVersions =>
58-
ArtifactUpdateCandidates(CrossDependency(dependency.value), newerVersions)
58+
ArtifactUpdateCandidates(ArtifactForUpdate(CrossDependency(dependency.value)), newerVersions)
5959
}
6060

6161
private def findUpdateWithMigration(
@@ -67,10 +67,12 @@ final class UpdateAlg[F[_]](implicit
6767
val migratedDependency = migrateDependency(dependency.value, artifactChange)
6868
findNewerVersions(dependency.as(migratedDependency), maxAge).map { newerVersions =>
6969
ArtifactUpdateCandidates(
70-
CrossDependency(dependency.value),
71-
newerVersions,
72-
Some(artifactChange.groupIdAfter),
73-
Some(artifactChange.artifactIdAfter)
70+
ArtifactForUpdate(
71+
CrossDependency(dependency.value),
72+
Some(artifactChange.groupIdAfter),
73+
Some(artifactChange.artifactIdAfter)
74+
),
75+
newerVersions
7476
)
7577
}
7678
}

0 commit comments

Comments
 (0)