Skip to content

Commit a1dffde

Browse files
committed
Replace withNewerVersions with supersedes
This commit removes withNewerVersions and replaces the one usage of it with a new function supersedes, which checks whether an update matches another while having a newer nextVersion. withNewerVersions was a little awkward to update to work with us having changed some Versions to VersionWithFirstSeens, because it accepts a list of Versions (rather than just producing one). It was originally added in response to [this PR comment](#1667 (comment)), but we reckon replacing it with a slightly different check of the group and artifact IDs makes for clearer, more explicit code. We think (though it’s somewhat hard to tell) that this doesn’t remove any existing functionality: part of the argument for adding withNewerVersions in the first place was to support Update.Group, but it appears to only be called for Update.Singles.
1 parent 0d83ea8 commit a1dffde

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ object Update {
7777
s"$groupId:$artifacts : $versions"
7878
}
7979

80-
def withNewerVersions(versions: Nel[Version]): Update.Single = this match {
81-
case s @ ForArtifactId(_, _, _, _) =>
82-
s.copy(newerVersions = versions)
83-
case ForGroupId(forArtifactIds) =>
84-
ForGroupId(forArtifactIds.map(_.copy(newerVersions = versions)))
85-
}
80+
def supersedes(that: Update.Single): Boolean =
81+
this.groupAndMainArtifactId == that.groupAndMainArtifactId
82+
&& this.nextVersion > that.nextVersion
8683
}
8784

8885
final case class ForArtifactId(

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ final class PullRequestRepository[F[_]](kvStore: KeyValueStore[F, Repo, Map[Uri,
7171
kvStore.getOrElse(repo, Map.empty).map {
7272
_.collect {
7373
case (url, Entry(baseSha1, u: Update.Single, state, _, number, updateBranch))
74-
if state === PullRequestState.Open &&
75-
u.withNewerVersions(update.newerVersions) === update &&
76-
u.nextVersion < update.nextVersion =>
74+
if state === PullRequestState.Open && update.supersedes(u) =>
7775
for {
7876
number <- number
7977
branch = updateBranch.getOrElse(git.branchFor(u, repo.branch))

0 commit comments

Comments
 (0)