Skip to content

Commit

Permalink
Pass update branch to createBranch and listingBranch (#2294)
Browse files Browse the repository at this point in the history
These functions do not need to compute the update branch because it
has already been done in `NurtureAlg` before they are called.
  • Loading branch information
fthomas committed Oct 17, 2021
1 parent 90cf411 commit 4939946
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
def processUpdate(data: UpdateData): F[ProcessResult] =
for {
_ <- logger.info(s"Process update ${data.update.show}")
head = vcs.listingBranch(config.tpe, data.fork, data.update)
head = vcs.listingBranch(config.tpe, data.fork, data.updateBranch)
pullRequests <- vcsApiAlg.listPullRequests(data.repo, head, data.baseBranch)
result <- pullRequests.headOption match {
case Some(pr) if pr.isClosed =>
Expand Down Expand Up @@ -185,7 +185,7 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
.get(data.update.mainArtifactId)
.traverse(vcsExtraAlg.getReleaseRelatedUrls(_, data.update))
filesWithOldVersion <- gitAlg.findFilesContaining(data.repo, data.update.currentVersion)
branchName = vcs.createBranch(config.tpe, data.fork, data.update)
branchName = vcs.createBranch(config.tpe, data.fork, data.updateBranch)
requestData = NewPullRequestData.from(
data,
branchName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.syntax.all._
import org.http4s.Uri
import org.scalasteward.core.data.ReleaseRelatedUrl.VersionDiff
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
import org.scalasteward.core.git.Branch
import org.scalasteward.core.vcs.VCSType.{Bitbucket, BitbucketServer, GitHub, GitLab}
import org.scalasteward.core.vcs.data.Repo

Expand All @@ -28,25 +29,25 @@ package object vcs {
/** Determines the `head` (GitHub) / `source_branch` (GitLab, Bitbucket) parameter for searching
* for already existing pull requests.
*/
def listingBranch(vcsType: VCSType, fork: Repo, update: Update): String =
def listingBranch(vcsType: VCSType, fork: Repo, updateBranch: Branch): String =
vcsType match {
case GitHub =>
s"${fork.toPath}:${git.branchFor(update).name}"
s"${fork.owner}/${fork.repo}:${updateBranch.name}"

case GitLab | Bitbucket | BitbucketServer =>
git.branchFor(update).name
updateBranch.name
}

/** Determines the `head` (GitHub) / `source_branch` (GitLab, Bitbucket) parameter for creating
* a new pull requests.
*/
def createBranch(vcsType: VCSType, fork: Repo, update: Update): String =
def createBranch(vcsType: VCSType, fork: Repo, updateBranch: Branch): String =
vcsType match {
case GitHub =>
s"${fork.owner}:${git.branchFor(update).name}"
s"${fork.owner}:${updateBranch.name}"

case GitLab | Bitbucket | BitbucketServer =>
git.branchFor(update).name
updateBranch.name
}

def possibleTags(version: String): List[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ import munit.FunSuite
import org.http4s.syntax.literals._
import org.scalasteward.core.TestSyntax._
import org.scalasteward.core.data.Update
import org.scalasteward.core.git
import org.scalasteward.core.util.Nel
import org.scalasteward.core.vcs.VCSType.{GitHub, GitLab}
import org.scalasteward.core.vcs.data.Repo

class VCSPackageTest extends FunSuite {
val repo: Repo = Repo("foo", "bar")
val update: Update.Single =
private val repo = Repo("foo", "bar")
private val update =
Update.Single("ch.qos.logback" % "logback-classic" % "1.2.0", Nel.of("1.2.3"))
private val updateBranch = git.branchFor(update)

test("listingBranch") {
assertEquals(listingBranch(GitHub, repo, update), "foo/bar:update/logback-classic-1.2.3")
assertEquals(listingBranch(GitLab, repo, update), "update/logback-classic-1.2.3")
assertEquals(listingBranch(GitHub, repo, updateBranch), s"foo/bar:${updateBranch.name}")
assertEquals(listingBranch(GitLab, repo, updateBranch), updateBranch.name)
}

test("createBranch") {
assertEquals(createBranch(GitHub, repo, update), "foo:update/logback-classic-1.2.3")
assertEquals(createBranch(GitLab, repo, update), "update/logback-classic-1.2.3")
assertEquals(createBranch(GitHub, repo, updateBranch), s"foo:${updateBranch.name}")
assertEquals(createBranch(GitLab, repo, updateBranch), updateBranch.name)
}

test("possibleCompareUrls") {
Expand Down

0 comments on commit 4939946

Please sign in to comment.