diff --git a/modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala b/modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala index 2334009cfb..4d14949253 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala @@ -21,9 +21,13 @@ import cats.syntax.all._ import org.http4s.Uri import org.http4s.syntax.literals._ import org.scalasteward.core.application.Config.ForgeCfg +import org.scalasteward.core.data.Repo import org.scalasteward.core.forge.ForgeType._ +import org.scalasteward.core.git.Branch import org.scalasteward.core.util.unexpectedString +import scala.annotation.nowarn + sealed trait ForgeType extends Product with Serializable { def publicWebHost: Option[String] @@ -41,6 +45,11 @@ sealed trait ForgeType extends Product with Serializable { def supportsForking: Boolean = true def supportsLabels: Boolean = true + /** Determines the `head` (GitHub) / `source_branch` (GitLab, Bitbucket) parameter for searching + * for already existing pull requests or creating new pull requests. + */ + def pullRequestHeadFor(@nowarn fork: Repo, updateBranch: Branch): String = updateBranch.name + val asString: String = this match { case AzureRepos => "azure-repos" case Bitbucket => "bitbucket" @@ -94,6 +103,8 @@ object ForgeType { val publicApiBaseUrl = uri"https://api.github.com" val diffs: DiffUriPattern = (from, to) => _ / "compare" / s"$from...$to" val files: FileUriPattern = fileName => _ / "blob" / "master" / fileName + override def pullRequestHeadFor(fork: Repo, updateBranch: Branch): String = + s"${fork.owner}:${updateBranch.name}" } case object GitLab extends ForgeType { diff --git a/modules/core/src/main/scala/org/scalasteward/core/forge/package.scala b/modules/core/src/main/scala/org/scalasteward/core/forge/package.scala deleted file mode 100644 index 7533c78471..0000000000 --- a/modules/core/src/main/scala/org/scalasteward/core/forge/package.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2018-2023 Scala Steward contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.scalasteward.core - -import org.scalasteward.core.data.Repo -import org.scalasteward.core.forge.ForgeType._ -import org.scalasteward.core.git.Branch - -package object forge { - - /** Determines the `head` (GitHub) / `source_branch` (GitLab, Bitbucket) parameter for searching - * for already existing pull requests or creating new pull requests. - */ - def headFor(forgeType: ForgeType, fork: Repo, updateBranch: Branch): String = - forgeType match { - case GitHub => - s"${fork.owner}:${updateBranch.name}" - - case GitLab | Bitbucket | BitbucketServer | AzureRepos | Gitea => - updateBranch.name - } -} 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 d552a25ec4..2ef236245d 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 @@ -31,7 +31,7 @@ import org.scalasteward.core.git.{Branch, Commit, GitAlg} import org.scalasteward.core.repoconfig.PullRequestUpdateStrategy import org.scalasteward.core.util.logger.LoggerOps import org.scalasteward.core.util.{Nel, UrlChecker} -import org.scalasteward.core.{forge, git, util} +import org.scalasteward.core.{git, util} import org.typelevel.log4cats.Logger final class NurtureAlg[F[_]](config: ForgeCfg)(implicit @@ -92,7 +92,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit private def processUpdate(data: UpdateData): F[ProcessResult] = for { _ <- logger.info(s"Process update ${data.update.show}") - head = forge.headFor(config.tpe, data.fork, data.updateBranch) + head = config.tpe.pullRequestHeadFor(data.fork, data.updateBranch) pullRequests <- forgeApiAlg.listPullRequests(data.repo, head, data.baseBranch) result <- pullRequests.headOption match { case Some(pr) if pr.state.isClosed && data.update.isInstanceOf[Update.Single] => @@ -230,20 +230,18 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit .on(u => List(u.currentVersion.value), _.updates.map(_.currentVersion.value)) .flatTraverse(gitAlg.findFilesContaining(data.repo, _)) .map(_.distinct) - branchName = forge.headFor(config.tpe, data.fork, data.updateBranch) allLabels = labelsFor(data.update, edits, filesWithOldVersion, artifactIdToVersionScheme) labels = filterLabels(allLabels, data.repoData.config.pullRequests.includeMatchedLabels) - requestData = NewPullRequestData.from( - data = data, - branchName = branchName, - edits = edits, - artifactIdToUrl = artifactIdToUrl, - artifactIdToUpdateInfoUrls = artifactIdToUpdateInfoUrls.toMap, - filesWithOldVersion = filesWithOldVersion, - addLabels = config.addLabels, - labels = data.repoData.config.pullRequests.customLabels ++ labels - ) - } yield requestData + } yield NewPullRequestData.from( + data = data, + branchName = config.tpe.pullRequestHeadFor(data.fork, data.updateBranch), + edits = edits, + artifactIdToUrl = artifactIdToUrl, + artifactIdToUpdateInfoUrls = artifactIdToUpdateInfoUrls.toMap, + filesWithOldVersion = filesWithOldVersion, + addLabels = config.addLabels, + labels = data.repoData.config.pullRequests.customLabels ++ labels + ) private def createPullRequest(data: UpdateData, edits: List[EditAttempt]): F[ProcessResult] = for { diff --git a/modules/core/src/test/scala/org/scalasteward/core/forge/ForgePackageTest.scala b/modules/core/src/test/scala/org/scalasteward/core/forge/ForgeTypeTest.scala similarity index 65% rename from modules/core/src/test/scala/org/scalasteward/core/forge/ForgePackageTest.scala rename to modules/core/src/test/scala/org/scalasteward/core/forge/ForgeTypeTest.scala index ade11d0b49..45e2cc9fb5 100644 --- a/modules/core/src/test/scala/org/scalasteward/core/forge/ForgePackageTest.scala +++ b/modules/core/src/test/scala/org/scalasteward/core/forge/ForgeTypeTest.scala @@ -6,27 +6,24 @@ import org.scalasteward.core.data.{Repo, Update} import org.scalasteward.core.forge.ForgeType.{GitHub, GitLab} import org.scalasteward.core.git -class ForgePackageTest extends FunSuite { +class ForgeTypeTest extends FunSuite { private val repo = Repo("foo", "bar") // Single updates { - val update = ("ch.qos.logback".g % "logback-classic".a % "1.2.0" %> "1.2.3").single val updateBranch = git.branchFor(update, None) test("headFor (single)") { - assertEquals(headFor(GitHub, repo, updateBranch), s"foo:${updateBranch.name}") - assertEquals(headFor(GitLab, repo, updateBranch), updateBranch.name) + assertEquals(GitHub.pullRequestHeadFor(repo, updateBranch), s"foo:${updateBranch.name}") + assertEquals(GitLab.pullRequestHeadFor(repo, updateBranch), updateBranch.name) } - } // Grouped updates { - val update = Update.Grouped( name = "my-group", title = None, @@ -36,8 +33,8 @@ class ForgePackageTest extends FunSuite { val updateBranch = git.branchFor(update, None) test("headFor (grouped)") { - assertEquals(headFor(GitHub, repo, updateBranch), s"foo:update/my-group") - assertEquals(headFor(GitLab, repo, updateBranch), updateBranch.name) + assertEquals(GitHub.pullRequestHeadFor(repo, updateBranch), s"foo:update/my-group") + assertEquals(GitLab.pullRequestHeadFor(repo, updateBranch), updateBranch.name) } } @@ -53,8 +50,8 @@ class ForgePackageTest extends FunSuite { val updateBranch = git.branchFor(update, None) test("headFor (grouped) with $hash") { - assertEquals(headFor(GitHub, repo, updateBranch), s"foo:update/my-group-1164623676") - assertEquals(headFor(GitLab, repo, updateBranch), updateBranch.name) + assertEquals(GitHub.pullRequestHeadFor(repo, updateBranch), s"foo:update/my-group-1164623676") + assertEquals(GitLab.pullRequestHeadFor(repo, updateBranch), updateBranch.name) } }