Skip to content

Commit fd36a4c

Browse files
committed
[Code review] Refactoring - add config to vcsExtraAlg
1 parent 8e404f8 commit fd36a4c

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ final class NurtureAlg[F[_]](implicit
163163
existingArtifactUrlsMap
164164
.get(data.update.mainArtifactId)
165165
.traverse(
166-
vcsExtraAlg.getReleaseRelatedUrls(config.vcsType, config.vcsApiHost, _, data.update)
166+
vcsExtraAlg.getReleaseRelatedUrls(_, data.update)
167167
)
168168
branchName = vcs.createBranch(config.vcsType, data.fork, data.update)
169169
migrations = migrationAlg.findMigrations(data.update)

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ package org.scalasteward.core.vcs
1919
import cats.Monad
2020
import cats.syntax.all._
2121
import org.http4s.Uri
22-
import org.scalasteward.core.application.SupportedVCS
22+
import org.scalasteward.core.application.Config
2323
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
2424
import org.scalasteward.core.util.HttpExistenceClient
2525
import org.scalasteward.core.vcs
2626

2727
trait VCSExtraAlg[F[_]] {
2828
def getReleaseRelatedUrls(
29-
vcsType: SupportedVCS,
30-
vcsUri: Uri,
3129
repoUrl: Uri,
3230
update: Update
3331
): F[List[ReleaseRelatedUrl]]
@@ -36,17 +34,16 @@ trait VCSExtraAlg[F[_]] {
3634
object VCSExtraAlg {
3735
def create[F[_]](implicit
3836
existenceClient: HttpExistenceClient[F],
37+
config: Config,
3938
F: Monad[F]
4039
): VCSExtraAlg[F] =
4140
new VCSExtraAlg[F] {
4241
override def getReleaseRelatedUrls(
43-
vcsType: SupportedVCS,
44-
vcsUri: Uri,
4542
repoUrl: Uri,
4643
update: Update
4744
): F[List[ReleaseRelatedUrl]] =
4845
vcs
49-
.possibleReleaseRelatedUrls(vcsType, vcsUri, repoUrl, update)
46+
.possibleReleaseRelatedUrls(config.vcsType, config.vcsApiHost, repoUrl, update)
5047
.filterA(releaseRelatedUrl => existenceClient.exists(releaseRelatedUrl.url))
5148
}
5249
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ package object vcs {
126126
val repoVCSType = extractRepoVCSType(vcsType, vcsUri, repoUrl)
127127

128128
val github = repoVCSType
129-
.collect {
130-
case GitHub =>
131-
possibleTags(update.nextVersion).map(tag =>
132-
ReleaseRelatedUrl.GitHubReleaseNotes(repoUrl / "releases" / "tag" / tag)
133-
)
129+
.collect { case GitHub =>
130+
possibleTags(update.nextVersion).map(tag =>
131+
ReleaseRelatedUrl.GitHubReleaseNotes(repoUrl / "releases" / "tag" / tag)
132+
)
134133
}
135134
.getOrElse(List.empty)
136135

modules/core/src/test/scala/org/scalasteward/core/vcs/VCSExtraAlgTest.scala

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import org.http4s.dsl.io._
77
import org.http4s.implicits._
88
import org.scalasteward.core.TestInstances.ioLogger
99
import org.scalasteward.core.TestSyntax._
10-
import org.scalasteward.core.application.SupportedVCS
10+
import org.scalasteward.core.application.{Config, SupportedVCS}
1111
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
12-
import org.scalasteward.core.mock.MockContext.config
12+
import org.scalasteward.core.mock.MockContext
1313
import org.scalasteward.core.util.{HttpExistenceClient, Nel}
1414
import org.scalatest.funsuite.AnyFunSuite
1515
import org.scalatest.matchers.should.Matchers
@@ -22,29 +22,27 @@ class VCSExtraAlgTest extends AnyFunSuite with Matchers {
2222
case _ => NotFound()
2323
}
2424

25+
implicit val cfg = MockContext.config
2526
implicit val client = Client.fromHttpApp[IO](routes.orNotFound)
2627
implicit val httpExistenceClient =
2728
HttpExistenceClient.create[IO].allocated.map(_._1).unsafeRunSync()
2829

29-
val vcsExtraAlg = VCSExtraAlg.create[IO]
3030
val updateFoo = Update.Single("com.example" % "foo" % "0.1.0", Nel.of("0.2.0"))
3131
val updateBar = Update.Single("com.example" % "bar" % "0.1.0", Nel.of("0.2.0"))
3232
val updateBuz = Update.Single("com.example" % "buz" % "0.1.0", Nel.of("0.2.0"))
3333

34-
test("getBranchCompareUrl") {
34+
test("getBranchCompareUrl: std vsc") {
35+
val vcsExtraAlg = VCSExtraAlg.create[IO]
36+
3537
vcsExtraAlg
3638
.getReleaseRelatedUrls(
37-
SupportedVCS.Gitlab,
38-
uri"https://gitlab.com/",
3939
uri"https://github.com/foo/foo",
4040
updateFoo
4141
)
4242
.unsafeRunSync() shouldBe List.empty
4343

4444
vcsExtraAlg
4545
.getReleaseRelatedUrls(
46-
SupportedVCS.Gitlab,
47-
uri"https://gitlab.com/",
4846
uri"https://github.com/foo/bar",
4947
updateBar
5048
)
@@ -54,21 +52,39 @@ class VCSExtraAlgTest extends AnyFunSuite with Matchers {
5452

5553
vcsExtraAlg
5654
.getReleaseRelatedUrls(
57-
SupportedVCS.GitHub,
58-
uri"https://github.on-prem.com/",
55+
uri"https://github.com/foo/buz",
56+
updateBuz
57+
)
58+
.unsafeRunSync() shouldBe List.empty
59+
}
60+
61+
test("getBranchCompareUrl: github on prem") {
62+
implicit val cfg: Config = MockContext.config.copy(
63+
vcsType = SupportedVCS.GitHub,
64+
vcsApiHost = uri"https://github.on-prem.com/"
65+
)
66+
val githubOnPremVcsExtraAlg = VCSExtraAlg.create[IO]
67+
68+
githubOnPremVcsExtraAlg
69+
.getReleaseRelatedUrls(
70+
uri"https://github.on-prem.com/foo/foo",
71+
updateFoo
72+
)
73+
.unsafeRunSync() shouldBe List.empty
74+
75+
githubOnPremVcsExtraAlg
76+
.getReleaseRelatedUrls(
5977
uri"https://github.on-prem.com/foo/bar",
6078
updateBar
6179
)
6280
.unsafeRunSync() shouldBe List(
6381
ReleaseRelatedUrl.VersionDiff(uri"https://github.on-prem.com/foo/bar/compare/v0.1.0...v0.2.0")
6482
)
6583

66-
vcsExtraAlg
84+
githubOnPremVcsExtraAlg
6785
.getReleaseRelatedUrls(
68-
SupportedVCS.Gitlab,
69-
uri"https://gitlab.com/",
70-
uri"https://github.com/foo/buz",
71-
updateBuz
86+
uri"https://github.on-prem.com/foo/buz",
87+
updateFoo
7288
)
7389
.unsafeRunSync() shouldBe List.empty
7490
}

modules/core/src/test/scala/org/scalasteward/core/vcs/VCSPackageTest.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ class VCSPackageTest extends AnyFunSuite with Matchers {
145145
possibleReleaseNotesFilenames.map(name =>
146146
s"https://gitlab.on-prem.net/foo/bar/blob/master/$name"
147147
) ++
148-
possibleChangelogFilenames.map(name =>
149-
s"https://gitlab.on-prem.net/foo/bar/blob/master/$name"
150-
) ++
151-
List(
152-
"https://gitlab.on-prem.net/foo/bar/compare/v1.2.0...v1.2.3",
153-
"https://gitlab.on-prem.net/foo/bar/compare/1.2.0...1.2.3",
154-
"https://gitlab.on-prem.net/foo/bar/compare/release-1.2.0...release-1.2.3"
155-
)
148+
possibleChangelogFilenames.map(name =>
149+
s"https://gitlab.on-prem.net/foo/bar/blob/master/$name"
150+
) ++
151+
List(
152+
"https://gitlab.on-prem.net/foo/bar/compare/v1.2.0...v1.2.3",
153+
"https://gitlab.on-prem.net/foo/bar/compare/1.2.0...1.2.3",
154+
"https://gitlab.on-prem.net/foo/bar/compare/release-1.2.0...release-1.2.3"
155+
)
156156
}
157157

158158
test("possibleChangelogUrls: bitbucket.org") {

0 commit comments

Comments
 (0)