Skip to content

Commit

Permalink
Merge pull request #552 from fthomas/topic/fix-head-for-search
Browse files Browse the repository at this point in the history
Include repo in head param when searching for PRs
  • Loading branch information
fthomas authored Jun 8, 2019
2 parents a48842f + badd1b5 commit 1dec60e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ final class NurtureAlg[F[_]](
logAlg.infoTotalTime(repo.show) {
logAlg.attemptLog_(s"Nurture ${repo.show}") {
for {
baseBranch <- cloneAndSync(repo)
_ <- updateDependencies(repo, baseBranch)
res <- cloneAndSync(repo)
(fork, baseBranch) = res
_ <- updateDependencies(repo, fork, baseBranch)
_ <- gitAlg.removeClone(repo)
} yield ()
}
}

def cloneAndSync(repo: Repo): F[Branch] =
def cloneAndSync(repo: Repo): F[(Repo, Branch)] =
for {
_ <- logger.info(s"Clone and synchronize ${repo.show}")
repoOut <- gitHubApiAlg.createForkOrGetRepo(config, repo)
_ <- vcsRepoAlg.clone(repo, repoOut)
parent <- vcsRepoAlg.syncFork(repo, repoOut)
} yield parent.default_branch
} yield (repoOut.repo, parent.default_branch)

def updateDependencies(repo: Repo, baseBranch: Branch): F[Unit] =
def updateDependencies(repo: Repo, fork: Repo, baseBranch: Branch): F[Unit] =
for {
_ <- logger.info(s"Find updates for ${repo.show}")
repoConfig <- repoConfigAlg.getRepoConfig(repo)
Expand All @@ -74,15 +75,16 @@ final class NurtureAlg[F[_]](
_ <- logger.info(util.logger.showUpdates(grouped))
baseSha1 <- gitAlg.latestSha1(repo, baseBranch)
_ <- grouped.traverse_ { update =>
val data = UpdateData(repo, repoConfig, update, baseBranch, baseSha1, git.branchFor(update))
val data =
UpdateData(repo, fork, repoConfig, update, baseBranch, baseSha1, git.branchFor(update))
processUpdate(data)
}
} yield ()

def processUpdate(data: UpdateData): F[Unit] =
for {
_ <- logger.info(s"Process update ${data.update.show}")
head = vcs.headFor(vcs.getLogin(config, data.repo), data.update)
head = vcs.headFor(data.fork.show, data.update)
pullRequests <- gitHubApiAlg.listPullRequests(data.repo, head, data.baseBranch)
_ <- pullRequests.headOption match {
case Some(pr) if pr.isClosed =>
Expand Down Expand Up @@ -121,8 +123,7 @@ final class NurtureAlg[F[_]](
def createPullRequest(data: UpdateData): F[Unit] =
for {
_ <- logger.info(s"Create PR ${data.updateBranch.name}")
headLogin = vcs.getLogin(config, data.repo)
requestData = NewPullRequestData.from(data, headLogin, config.gitHubLogin)
requestData = NewPullRequestData.from(data, config.gitHubLogin)
pr <- gitHubApiAlg.createPullRequest(data.repo, requestData)
_ <- pullRequestRepo.createOrUpdate(
data.repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.scalasteward.core.repoconfig.RepoConfig

final case class UpdateData(
repo: Repo,
fork: Repo,
repoConfig: RepoConfig,
update: Update,
baseBranch: Branch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ object NewPullRequestData {
change <- SemVer.getChange(curr, next)
} yield s"semver-${change.render}"

def from(data: UpdateData, headLogin: String, authorLogin: String): NewPullRequestData =
def from(data: UpdateData, authorLogin: String): NewPullRequestData =
NewPullRequestData(
title = git.commitMsgFor(data.update),
body = bodyFor(data.update, authorLogin),
head = vcs.headFor(headLogin, data.update),
head = vcs.headFor(data.fork.owner, data.update),
base = data.baseBranch
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@

package org.scalasteward.core

import org.scalasteward.core.application.Config
import org.scalasteward.core.model.Update
import org.scalasteward.core.vcs.data.Repo

package object vcs {

def getLogin(config: Config, repo: Repo): String =
if (config.doNotFork) repo.owner else config.gitHubLogin

def headFor(login: String, update: Update): String =
s"$login:${git.branchFor(update).name}"
def headFor(origin: String, update: Update): String =
s"$origin:${git.branchFor(update).name}"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ class NewPullRequestDataTest extends FunSuite with Matchers {
test("asJson") {
val data = UpdateData(
Repo("foo", "bar"),
Repo("scala-steward", "bar"),
RepoConfig(),
Update.Single("ch.qos.logback", "logback-classic", "1.2.0", Nel.of("1.2.3")),
Branch("master"),
Sha1(Sha1.HexString("d6b6791d2ea11df1d156fe70979ab8c3a5ba3433")),
Branch("update/logback-classic-1.2.3")
)
NewPullRequestData.from(data, "foo", "scala-steward").asJson.spaces2 shouldBe
NewPullRequestData.from(data, "scala-steward").asJson.spaces2 shouldBe
"""|{
| "title" : "Update logback-classic to 1.2.3",
| "body" : "Updates ch.qos.logback:logback-classic from 1.2.0 to 1.2.3.\n\nI'll automatically update this PR to resolve conflicts as long as you don't change it yourself.\n\nIf you'd like to skip this version, you can just close this PR. If you have any feedback, just mention @scala-steward in the comments below.\n\nHave a nice day!\n\n<details>\n<summary>Ignore future updates</summary>\n\nAdd this to your `.scala-steward.conf` file to ignore future updates of this dependency:\n```\nupdates.ignore = [{ groupId = \"ch.qos.logback\", artifactId = \"logback-classic\" }]\n```\n</details>\n\nlabels: semver-patch",
| "head" : "foo:update/logback-classic-1.2.3",
| "head" : "scala-steward:update/logback-classic-1.2.3",
| "base" : "master"
|}
|""".stripMargin.trim
Expand Down

0 comments on commit 1dec60e

Please sign in to comment.