Skip to content

Commit

Permalink
Fix branch name
Browse files Browse the repository at this point in the history
During merge/rebase, I may have accidentally changed the
branch name used when creating the MR. On Gitlab, we need
`update/dependency-1.2.0` where as on GitHub we need:
`owner:update/dependency-1.2.0`.
  • Loading branch information
daddykotex committed Jul 2, 2019
1 parent 20fae69 commit 5c257a5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.scalasteward.core.github

import org.scalasteward.core.model.Update
import org.scalasteward.core.vcs
import org.scalasteward.core.git
import org.scalasteward.core.vcs.VCSSpecifics
import org.scalasteward.core.vcs.data.Repo

class GitHubSpecifics extends VCSSpecifics {
override def headForListingPullRequests(fork: Repo, update: Update): String =
vcs.headFor(fork.show, update)
s"${fork.show}:${git.branchFor(update).name}"

override def headForCreatingPullRequests(fork: Repo, update: Update): String =
s"${fork.owner}:${git.branchFor(update).name}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import org.scalasteward.core.git
import org.scalasteward.core.vcs.VCSSpecifics

class GitlabSpecifics extends VCSSpecifics {
override def headForListingPullRequests(fork: Repo, update: Update): String =
private def branchName(update: Update): String =
git.branchFor(update).name

override def headForListingPullRequests(fork: Repo, update: Update): String =
branchName(update)

override def headForCreatingPullRequests(fork: Repo, update: Update): String =
branchName(update)
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ final class NurtureAlg[F[_]](
def createPullRequest(data: UpdateData): F[Unit] =
for {
_ <- logger.info(s"Create PR ${data.updateBranch.name}")
requestData = NewPullRequestData.from(data, config.vcsLogin)
branchName = vcsSpecifics.headForCreatingPullRequests(data.fork, data.update)
requestData = NewPullRequestData.from(data, branchName, config.vcsLogin)
pr <- vcsApiAlg.createPullRequest(data.repo, requestData)
_ <- pullRequestRepo.createOrUpdate(
data.repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ trait VCSSpecifics {
* for already existing pull requests.
*/
def headForListingPullRequests(fork: Repo, update: Update): String

/** Determines the `head` (GitHub) / `source_branch` (GitLab) parameter for creating
* a new merge requests.
*/
def headForCreatingPullRequests(fork: Repo, update: Update): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.scalasteward.core.model.{SemVer, Update}
import org.scalasteward.core.nurture.UpdateData
import org.scalasteward.core.repoconfig.RepoConfigAlg
import org.scalasteward.core.git
import org.scalasteward.core.vcs

final case class NewPullRequestData(
title: String,
Expand Down Expand Up @@ -74,11 +73,11 @@ object NewPullRequestData {
change <- SemVer.getChange(curr, next)
} yield s"semver-${change.render}"

def from(data: UpdateData, authorLogin: String): NewPullRequestData =
def from(data: UpdateData, branchName: String, authorLogin: String): NewPullRequestData =
NewPullRequestData(
title = git.commitMsgFor(data.update),
body = bodyFor(data.update, authorLogin),
head = vcs.headFor(data.fork.owner, data.update),
head = branchName,
base = data.baseBranch
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NewPullRequestDataTest extends FunSuite with Matchers {
Branch("update/logback-classic-1.2.3")
)
NewPullRequestData
.from(data, "scala-steward")
.from(data, "scala-steward:update/logback-classic-1.2.3", "scala-steward")
.asJson
.spaces2 shouldBe
"""|{
Expand Down

0 comments on commit 5c257a5

Please sign in to comment.