Skip to content

Commit e7d116b

Browse files
authored
Rename VCSExtraAlg to UpdateInfoUrlFinder (#2891)
This is a purely stylistic change. No behaviour has been changed. It - renames `VCSExtraAlg` to `UpdateInfoUrlFinder` - renames `ReleaseRelatedUrl` to `UpdateInfoUrl` - moves `UpdateInfoUrlFinder` and `UpdateInfoUrl` to the nurture package since it is mainly used there - moves the function from the `vcs` package object that created `ReleaseRelatedUrl`s into the `UpdateUrlFinder` companion since these functions are more related to the `UpdateUrlFinder` than to the different VCS integrations. For example, it would be perfectly fine to have a VCS intgeration without updating the `UpdateInfoUrlFinder` or to update it for VCSs for which we don't have integrations. I hope the new names and the reorganization makes it clearer what `UpdateInfoUrlFinder` is about.
1 parent 89c66e3 commit e7d116b

File tree

11 files changed

+501
-542
lines changed

11 files changed

+501
-542
lines changed

modules/core/src/main/scala/org/scalasteward/core/application/Context.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package org.scalasteward.core.application
1818

1919
import better.files.File
20+
import cats.MonadThrow
2021
import cats.effect._
2122
import cats.effect.implicits._
22-
import cats.MonadThrow
2323
import cats.syntax.all._
2424
import eu.timepit.refined.auto._
2525
import org.http4s.Uri
2626
import org.http4s.client.Client
2727
import org.http4s.headers.`User-Agent`
28+
import org.scalasteward.core.application.Config.StewardUsage
2829
import org.scalasteward.core.buildtool.BuildToolDispatcher
2930
import org.scalasteward.core.buildtool.maven.MavenAlg
3031
import org.scalasteward.core.buildtool.mill.MillAlg
@@ -34,25 +35,23 @@ import org.scalasteward.core.coursier.{CoursierAlg, VersionsCache}
3435
import org.scalasteward.core.edit.EditAlg
3536
import org.scalasteward.core.edit.hooks.HookExecutor
3637
import org.scalasteward.core.edit.scalafix._
38+
import org.scalasteward.core.edit.update.ScannerAlg
3739
import org.scalasteward.core.git.{GenGitAlg, GitAlg}
3840
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
39-
import org.scalasteward.core.nurture.{NurtureAlg, PullRequestRepository}
41+
import org.scalasteward.core.nurture.{NurtureAlg, PullRequestRepository, UpdateInfoUrlFinder}
4042
import org.scalasteward.core.persistence.{CachingKeyValueStore, JsonKeyValueStore}
4143
import org.scalasteward.core.repocache._
42-
import org.scalasteward.core.repoconfig.{RepoConfigAlg, RepoConfigLoader}
44+
import org.scalasteward.core.repoconfig.{RepoConfigAlg, RepoConfigLoader, ValidateRepoConfigAlg}
4345
import org.scalasteward.core.scalafmt.ScalafmtAlg
4446
import org.scalasteward.core.update.artifact.{ArtifactMigrationsFinder, ArtifactMigrationsLoader}
4547
import org.scalasteward.core.update.{FilterAlg, PruningAlg, UpdateAlg}
4648
import org.scalasteward.core.util._
4749
import org.scalasteward.core.util.uri._
4850
import org.scalasteward.core.vcs.data.Repo
4951
import org.scalasteward.core.vcs.github.{GitHubAppApiAlg, GitHubAuthAlg}
50-
import org.scalasteward.core.vcs.{VCSApiAlg, VCSExtraAlg, VCSRepoAlg, VCSSelection}
52+
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg, VCSSelection}
5153
import org.typelevel.log4cats.Logger
5254
import org.typelevel.log4cats.slf4j.Slf4jLogger
53-
import org.scalasteward.core.application.Config.StewardUsage
54-
import org.scalasteward.core.edit.update.ScannerAlg
55-
import org.scalasteward.core.repoconfig.ValidateRepoConfigAlg
5655

5756
final class Context[F[_]](implicit
5857
val buildToolDispatcher: BuildToolDispatcher[F],
@@ -79,8 +78,8 @@ final class Context[F[_]](implicit
7978
val scalafmtAlg: ScalafmtAlg[F],
8079
val stewardAlg: StewardAlg[F],
8180
val updateAlg: UpdateAlg[F],
81+
val updateInfoUrlFinder: UpdateInfoUrlFinder[F],
8282
val urlChecker: UrlChecker[F],
83-
val vcsExtraAlg: VCSExtraAlg[F],
8483
val vcsRepoAlg: VCSRepoAlg[F],
8584
val workspaceAlg: WorkspaceAlg[F]
8685
)
@@ -207,7 +206,8 @@ object Context {
207206
new RepoCacheRepository[F](repoCacheStore)
208207
implicit val vcsApiAlg: VCSApiAlg[F] = new VCSSelection[F](config, vcsUser).vcsApiAlg
209208
implicit val vcsRepoAlg: VCSRepoAlg[F] = new VCSRepoAlg[F](config)
210-
implicit val vcsExtraAlg: VCSExtraAlg[F] = VCSExtraAlg.create[F](config.vcsCfg)
209+
implicit val updateInfoUrlFinder: UpdateInfoUrlFinder[F] =
210+
new UpdateInfoUrlFinder[F](config.vcsCfg)
211211
implicit val pullRequestRepository: PullRequestRepository[F] =
212212
new PullRequestRepository[F](pullRequestsStore)
213213
implicit val scalafixCli: ScalafixCli[F] = new ScalafixCli[F]

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.scalasteward.core.nurture
1818

19-
import cats.{Applicative, Id}
2019
import cats.effect.Concurrent
2120
import cats.implicits._
21+
import cats.{Applicative, Id}
2222
import org.scalasteward.core.application.Config.VCSCfg
2323
import org.scalasteward.core.coursier.CoursierAlg
2424
import org.scalasteward.core.data.ProcessResult.{Created, Ignored, Updated}
@@ -29,7 +29,7 @@ import org.scalasteward.core.repoconfig.PullRequestUpdateStrategy
2929
import org.scalasteward.core.util.logger.LoggerOps
3030
import org.scalasteward.core.util.{Nel, UrlChecker}
3131
import org.scalasteward.core.vcs.data._
32-
import org.scalasteward.core.vcs.{VCSApiAlg, VCSExtraAlg, VCSRepoAlg}
32+
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg}
3333
import org.scalasteward.core.{git, util, vcs}
3434
import org.typelevel.log4cats.Logger
3535

@@ -39,10 +39,10 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
3939
gitAlg: GitAlg[F],
4040
logger: Logger[F],
4141
pullRequestRepository: PullRequestRepository[F],
42+
updateInfoUrlFinder: UpdateInfoUrlFinder[F],
43+
urlChecker: UrlChecker[F],
4244
vcsApiAlg: VCSApiAlg[F],
43-
vcsExtraAlg: VCSExtraAlg[F],
4445
vcsRepoAlg: VCSRepoAlg[F],
45-
urlChecker: UrlChecker[F],
4646
F: Concurrent[F]
4747
) {
4848
def nurture(data: RepoData, fork: RepoOut, updates: Nel[Update.ForArtifactId]): F[Unit] =
@@ -212,11 +212,11 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
212212
artifactIdToUrl = dependencyToMetadata.toList.mapFilter { case (dependency, metadata) =>
213213
metadata.repoUrl.tupleLeft(dependency.artifactId.name)
214214
}.toMap
215-
releaseRelatedUrls <- dependenciesWithNextVersion.flatTraverse {
215+
artifactIdToUpdateInfoUrls <- dependenciesWithNextVersion.flatTraverse {
216216
case (currentVersion, dependency) =>
217217
dependencyToMetadata.get(dependency).toList.traverse { metadata =>
218-
vcsExtraAlg
219-
.getReleaseRelatedUrls(metadata, currentVersion, dependency.version)
218+
updateInfoUrlFinder
219+
.findUpdateInfoUrls(metadata, currentVersion, dependency.version)
220220
.tupleLeft(dependency.artifactId.name)
221221
}
222222
}
@@ -231,7 +231,7 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
231231
branchName,
232232
edits,
233233
artifactIdToUrl,
234-
releaseRelatedUrls.toMap,
234+
artifactIdToUpdateInfoUrls.toMap,
235235
filesWithOldVersion,
236236
data.repoData.config.pullRequests.includeMatchedLabels
237237
)

modules/core/src/main/scala/org/scalasteward/core/data/ReleaseRelatedUrl.scala renamed to modules/core/src/main/scala/org/scalasteward/core/nurture/UpdateInfoUrl.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.scalasteward.core.data
17+
package org.scalasteward.core.nurture
1818

1919
import org.http4s.Uri
2020

21-
sealed trait ReleaseRelatedUrl {
21+
/** A URL of a resource that provides additional information for an update. */
22+
sealed trait UpdateInfoUrl {
2223
def url: Uri
2324
}
2425

25-
object ReleaseRelatedUrl {
26-
final case class CustomChangelog(url: Uri) extends ReleaseRelatedUrl
27-
final case class CustomReleaseNotes(url: Uri) extends ReleaseRelatedUrl
28-
final case class GitHubReleaseNotes(url: Uri) extends ReleaseRelatedUrl
29-
final case class VersionDiff(url: Uri) extends ReleaseRelatedUrl
26+
object UpdateInfoUrl {
27+
final case class CustomChangelog(url: Uri) extends UpdateInfoUrl
28+
final case class CustomReleaseNotes(url: Uri) extends UpdateInfoUrl
29+
final case class GitHubReleaseNotes(url: Uri) extends UpdateInfoUrl
30+
final case class VersionDiff(url: Uri) extends UpdateInfoUrl
3031
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright 2018-2023 Scala Steward contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.scalasteward.core.nurture
18+
19+
import cats.Monad
20+
import cats.syntax.all._
21+
import org.http4s.Uri
22+
import org.scalasteward.core.application.Config.VCSCfg
23+
import org.scalasteward.core.coursier.DependencyMetadata
24+
import org.scalasteward.core.data.Version
25+
import org.scalasteward.core.nurture.UpdateInfoUrl._
26+
import org.scalasteward.core.nurture.UpdateInfoUrlFinder.possibleUpdateInfoUrls
27+
import org.scalasteward.core.util.UrlChecker
28+
import org.scalasteward.core.vcs.VCSType
29+
import org.scalasteward.core.vcs.VCSType._
30+
31+
final class UpdateInfoUrlFinder[F[_]](config: VCSCfg)(implicit
32+
urlChecker: UrlChecker[F],
33+
F: Monad[F]
34+
) {
35+
def findUpdateInfoUrls(
36+
metadata: DependencyMetadata,
37+
currentVersion: Version,
38+
nextVersion: Version
39+
): F[List[UpdateInfoUrl]] = {
40+
val updateInfoUrls =
41+
metadata.releaseNotesUrl.toList.map(CustomReleaseNotes.apply) ++
42+
metadata.repoUrl.toList.flatMap { repoUrl =>
43+
possibleUpdateInfoUrls(config.tpe, config.apiHost, repoUrl, currentVersion, nextVersion)
44+
}
45+
46+
updateInfoUrls.distinctBy(_.url).filterA(updateInfoUrl => urlChecker.exists(updateInfoUrl.url))
47+
}
48+
}
49+
50+
object UpdateInfoUrlFinder {
51+
private def possibleTags(version: Version): List[String] =
52+
List(s"v$version", version.value, s"release-$version")
53+
54+
private[nurture] val possibleChangelogFilenames: List[String] = {
55+
val baseNames = List(
56+
"CHANGELOG",
57+
"Changelog",
58+
"changelog",
59+
"CHANGES"
60+
)
61+
possibleFilenames(baseNames)
62+
}
63+
64+
private[nurture] val possibleReleaseNotesFilenames: List[String] = {
65+
val baseNames = List(
66+
"ReleaseNotes",
67+
"RELEASES",
68+
"Releases",
69+
"releases"
70+
)
71+
possibleFilenames(baseNames)
72+
}
73+
74+
private def extractRepoVCSType(vcsType: VCSType, vcsUri: Uri, repoUrl: Uri): Option[VCSType] =
75+
repoUrl.host.flatMap { repoHost =>
76+
if (vcsUri.host.contains(repoHost)) Some(vcsType)
77+
else VCSType.fromPublicWebHost(repoHost.value)
78+
}
79+
80+
private[nurture] def possibleVersionDiffs(
81+
vcsType: VCSType,
82+
vcsUri: Uri,
83+
repoUrl: Uri,
84+
currentVersion: Version,
85+
nextVersion: Version
86+
): List[VersionDiff] =
87+
extractRepoVCSType(vcsType, vcsUri, repoUrl).map {
88+
case GitHub | GitLab =>
89+
possibleTags(currentVersion).zip(possibleTags(nextVersion)).map { case (from1, to1) =>
90+
VersionDiff(repoUrl / "compare" / s"$from1...$to1")
91+
}
92+
case Bitbucket | BitbucketServer =>
93+
possibleTags(currentVersion).zip(possibleTags(nextVersion)).map { case (from1, to1) =>
94+
VersionDiff((repoUrl / "compare" / s"$to1..$from1").withFragment("diff"))
95+
}
96+
case AzureRepos =>
97+
possibleTags(currentVersion).zip(possibleTags(nextVersion)).map { case (from1, to1) =>
98+
VersionDiff(
99+
(repoUrl / "branchCompare")
100+
.withQueryParams(Map("baseVersion" -> from1, "targetVersion" -> to1))
101+
)
102+
}
103+
}.orEmpty
104+
105+
private[nurture] def possibleUpdateInfoUrls(
106+
vcsType: VCSType,
107+
vcsUrl: Uri,
108+
repoUrl: Uri,
109+
currentVersion: Version,
110+
nextVersion: Version
111+
): List[UpdateInfoUrl] = {
112+
val repoVCSType = extractRepoVCSType(vcsType, vcsUrl, repoUrl)
113+
114+
val githubReleaseNotes = repoVCSType
115+
.collect { case GitHub =>
116+
possibleTags(nextVersion).map(tag => GitHubReleaseNotes(repoUrl / "releases" / "tag" / tag))
117+
}
118+
.getOrElse(List.empty)
119+
120+
def files(fileNames: List[String]): List[Uri] = {
121+
val maybeSegments = repoVCSType.collect {
122+
case GitHub | GitLab => List("blob", "master")
123+
case Bitbucket => List("master")
124+
case BitbucketServer => List("browse")
125+
}
126+
127+
val repoFiles = maybeSegments.toList.flatMap { segments =>
128+
val base = segments.foldLeft(repoUrl)(_ / _)
129+
fileNames.map(name => base / name)
130+
}
131+
132+
val azureRepoFiles = repoVCSType
133+
.collect { case AzureRepos => fileNames.map(name => repoUrl.withQueryParam("path", name)) }
134+
.toList
135+
.flatten
136+
137+
repoFiles ++ azureRepoFiles
138+
}
139+
140+
val customChangelog = files(possibleChangelogFilenames).map(CustomChangelog)
141+
val customReleaseNotes = files(possibleReleaseNotesFilenames).map(CustomReleaseNotes)
142+
143+
githubReleaseNotes ++ customReleaseNotes ++ customChangelog ++
144+
possibleVersionDiffs(vcsType, vcsUrl, repoUrl, currentVersion, nextVersion)
145+
}
146+
147+
private def possibleFilenames(baseNames: List[String]): List[String] = {
148+
val extensions = List("md", "markdown", "rst")
149+
(baseNames, extensions).mapN { case (base, ext) => s"$base.$ext" }
150+
}
151+
}

modules/core/src/main/scala/org/scalasteward/core/vcs/VCSExtraAlg.scala

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)