Repository: scala-steward-org/scala-steward
Pull request #2890 (2023-01-06 11:48:33)

Use releaseNotesUrl even if repoUrl is empty
This is a follow-up to #2863. Before this change, the `info.releaseNotesUrl` property from the POM was ignored if `project.scm.url` and `project.url` were not set (since `DependencyMetadata#repoUrl` is then empty too). With this change the `releaseNotesUrl` is added to the PR even if the other two are not set.


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala
index 27a018bd..6325ddb8 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala
@@ -214,17 +214,10 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
       }.toMap
       releaseRelatedUrls <- dependenciesWithNextVersion.flatTraverse {
         case (currentVersion, dependency) =>
-          dependencyToMetadata.get(dependency).toList.flatTraverse { metadata =>
-            metadata.repoUrl.toList.traverse { uri =>
-              vcsExtraAlg
-                .getReleaseRelatedUrls(
-                  uri,
-                  metadata.releaseNotesUrl,
-                  currentVersion,
-                  dependency.version
-                )
-                .tupleLeft(dependency.artifactId.name)
-            }
+          dependencyToMetadata.get(dependency).toList.traverse { metadata =>
+            vcsExtraAlg
+              .getReleaseRelatedUrls(metadata, currentVersion, dependency.version)
+              .tupleLeft(dependency.artifactId.name)
           }
       }
       filesWithOldVersion <-
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSExtraAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSExtraAlg.scala
index afdc3913..b37afe86 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSExtraAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSExtraAlg.scala
@@ -18,16 +18,15 @@ package org.scalasteward.core.vcs
 
 import cats.Monad
 import cats.syntax.all._
-import org.http4s.Uri
 import org.scalasteward.core.application.Config.VCSCfg
+import org.scalasteward.core.coursier.DependencyMetadata
 import org.scalasteward.core.data.{ReleaseRelatedUrl, Version}
 import org.scalasteward.core.util.UrlChecker
 import org.scalasteward.core.vcs
 
 trait VCSExtraAlg[F[_]] {
   def getReleaseRelatedUrls(
-      repoUrl: Uri,
-      releaseNotesUrl: Option[Uri],
+      metadata: DependencyMetadata,
       currentVersion: Version,
       nextVersion: Version
   ): F[List[ReleaseRelatedUrl]]
@@ -40,20 +39,22 @@ object VCSExtraAlg {
   ): VCSExtraAlg[F] =
     new VCSExtraAlg[F] {
       override def getReleaseRelatedUrls(
-          repoUrl: Uri,
-          releaseNotesUrl: Option[Uri],
+          metadata: DependencyMetadata,
           currentVersion: Version,
           nextVersion: Version
       ): F[List[ReleaseRelatedUrl]] = {
         val releaseRelatedUrls =
-          releaseNotesUrl.toList.map(ReleaseRelatedUrl.CustomReleaseNotes.apply) ++
-            vcs.possibleReleaseRelatedUrls(
-              config.tpe,
-              config.apiHost,
-              repoUrl,
-              currentVersion,
-              nextVersion
+          metadata.releaseNotesUrl.toList.map(ReleaseRelatedUrl.CustomReleaseNotes.apply) ++
+            metadata.repoUrl.toList.flatMap(repoUrl =>
+              vcs.possibleReleaseRelatedUrls(
+                config.tpe,
+                config.apiHost,
+                repoUrl,
+                currentVersion,
+                nextVersion
+              )
             )
+
         releaseRelatedUrls
           .distinctBy(_.url)
           .filterA(releaseRelatedUrl => urlChecker.exists(releaseRelatedUrl.url))


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
index 82b1bb5e..d49daacf 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala
@@ -1,10 +1,12 @@
 package org.scalasteward.core.vcs
 
+import cats.syntax.all._
 import munit.CatsEffectSuite
 import org.http4s.HttpApp
 import org.http4s.dsl.Http4sDsl
 import org.http4s.implicits._
 import org.scalasteward.core.application.Config.VCSCfg
+import org.scalasteward.core.coursier.DependencyMetadata
 import org.scalasteward.core.data.ReleaseRelatedUrl.{CustomReleaseNotes, VersionDiff}
 import org.scalasteward.core.data.Version
 import org.scalasteward.core.mock.MockContext.context._
@@ -23,42 +25,44 @@ class VCSExtraAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
   private val v2 = Version("0.2.0")
 
   test("getReleaseRelatedUrls: repoUrl not found") {
-    val obtained =
-      vcsExtraAlg.getReleaseRelatedUrls(uri"https://github.com/foo/foo", None, v1, v2).runA(state)
+    val metadata = DependencyMetadata.empty.copy(scmUrl = uri"https://github.com/foo/foo".some)
+    val obtained = vcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     assertIO(obtained, List.empty)
   }
 
   test("getReleaseRelatedUrls: repoUrl ok") {
-    val obtained =
-      vcsExtraAlg.getReleaseRelatedUrls(uri"https://github.com/foo/bar", None, v1, v2).runA(state)
+    val metadata = DependencyMetadata.empty.copy(scmUrl = uri"https://github.com/foo/bar".some)
+    val obtained = vcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     val expected = List(VersionDiff(uri"https://github.com/foo/bar/compare/v0.1.0...v0.2.0"))
     assertIO(obtained, expected)
   }
 
   test("getReleaseRelatedUrls: repoUrl and releaseNotesUrl ok") {
-    val releaseNotesUrl = uri"https://github.com/foo/bar/README.md#changelog"
-    val obtained = vcsExtraAlg
-      .getReleaseRelatedUrls(uri"https://github.com/foo/bar", Some(releaseNotesUrl), v1, v2)
-      .runA(state)
+    val metadata = DependencyMetadata.empty.copy(
+      scmUrl = uri"https://github.com/foo/bar".some,
+      releaseNotesUrl = uri"https://github.com/foo/bar/README.md#changelog".some
+    )
+    val obtained = vcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     val expected = List(
-      CustomReleaseNotes(releaseNotesUrl),
+      CustomReleaseNotes(metadata.releaseNotesUrl.get),
       VersionDiff(uri"https://github.com/foo/bar/compare/v0.1.0...v0.2.0")
     )
     assertIO(obtained, expected)
   }
 
   test("getReleaseRelatedUrls: releaseNotesUrl is in possibleReleaseRelatedUrls") {
-    val releaseNotesUrl = uri"https://github.com/foo/bar1/blob/master/RELEASES.md"
-    val obtained = vcsExtraAlg
-      .getReleaseRelatedUrls(uri"https://github.com/foo/bar1", Some(releaseNotesUrl), v1, v2)
-      .runA(state)
-    val expected = List(CustomReleaseNotes(releaseNotesUrl))
+    val metadata = DependencyMetadata.empty.copy(
+      scmUrl = uri"https://github.com/foo/bar1".some,
+      releaseNotesUrl = uri"https://github.com/foo/bar1/blob/master/RELEASES.md".some
+    )
+    val obtained = vcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
+    val expected = List(CustomReleaseNotes(metadata.releaseNotesUrl.get))
     assertIO(obtained, expected)
   }
 
   test("getReleaseRelatedUrls: repoUrl permanent redirect") {
-    val obtained =
-      vcsExtraAlg.getReleaseRelatedUrls(uri"https://github.com/foo/buz", None, v1, v2).runA(state)
+    val metadata = DependencyMetadata.empty.copy(scmUrl = uri"https://github.com/foo/buz".some)
+    val obtained = vcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     assertIO(obtained, List.empty)
   }
 
@@ -72,25 +76,25 @@ class VCSExtraAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
   private val githubOnPremVcsExtraAlg = VCSExtraAlg.create[MockEff](config)
 
   test("getReleaseRelatedUrls: on-prem, repoUrl not found") {
-    val obtained = githubOnPremVcsExtraAlg
-      .getReleaseRelatedUrls(uri"https://github.on-prem.com/foo/foo", None, v1, v2)
-      .runA(state)
+    val metadata =
+      DependencyMetadata.empty.copy(scmUrl = uri"https://github.on-prem.com/foo/foo".some)
+    val obtained = githubOnPremVcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     assertIO(obtained, List.empty)
   }
 
   test("getReleaseRelatedUrls: on-prem, repoUrl ok") {
-    val obtained = githubOnPremVcsExtraAlg
-      .getReleaseRelatedUrls(uri"https://github.on-prem.com/foo/bar", None, v1, v2)
-      .runA(state)
+    val metadata =
+      DependencyMetadata.empty.copy(scmUrl = uri"https://github.on-prem.com/foo/bar".some)
+    val obtained = githubOnPremVcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     val expected =
       List(VersionDiff(uri"https://github.on-prem.com/foo/bar/compare/v0.1.0...v0.2.0"))
     assertIO(obtained, expected)
   }
 
   test("getReleaseRelatedUrls: on-prem, repoUrl permanent redirect") {
-    val obtained = githubOnPremVcsExtraAlg
-      .getReleaseRelatedUrls(uri"https://github.on-prem.com/foo/buz", None, v1, v2)
-      .runA(state)
+    val metadata =
+      DependencyMetadata.empty.copy(scmUrl = uri"https://github.on-prem.com/foo/buz".some)
+    val obtained = githubOnPremVcsExtraAlg.getReleaseRelatedUrls(metadata, v1, v2).runA(state)
     assertIO(obtained, List.empty)
   }
 }