Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix branch name #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.scalasteward.core.update.json.JsonUpdateRepository
import org.scalasteward.core.update.{FilterAlg, UpdateRepository, UpdateService}
import org.scalasteward.core.util.{DateTimeAlg, HttpJsonClient, LogAlg}
import org.scalasteward.core.vcs.data.AuthenticatedUser
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg, VCSSelection, VCSSpecifics}
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg, VCSSelection}

import scala.concurrent.ExecutionContext

Expand All @@ -58,8 +58,7 @@ object Context {
implicit val gitAlg: GitAlg[F] = GitAlg.create[F]
implicit val httpJsonClient: HttpJsonClient[F] = new HttpJsonClient[F]
val vcsSelection = new VCSSelection[F]
implicit val (vcsApiAlg: VCSApiAlg[F], vcsSpecifics: VCSSpecifics) =
vcsSelection.build(config)
implicit val vcsApiAlg: VCSApiAlg[F] = vcsSelection.getAlg(config)
implicit val vcsRepoAlg: VCSRepoAlg[F] = VCSRepoAlg.create[F](config, gitAlg)
implicit val pullRequestRepo: PullRequestRepository[F] = new JsonPullRequestRepo[F]
implicit val sbtAlg: SbtAlg[F] = SbtAlg.create[F]
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import org.scalasteward.core.repoconfig.RepoConfigAlg
import org.scalasteward.core.sbt.SbtAlg
import org.scalasteward.core.update.FilterAlg
import org.scalasteward.core.util.{BracketThrowable, LogAlg}
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg, VCSSpecifics}
import org.scalasteward.core.{git, util}
import org.scalasteward.core.vcs.{VCSApiAlg, VCSRepoAlg}
import org.scalasteward.core.{git, util, vcs}

final class NurtureAlg[F[_]](
implicit
Expand All @@ -37,7 +37,6 @@ final class NurtureAlg[F[_]](
repoConfigAlg: RepoConfigAlg[F],
filterAlg: FilterAlg[F],
gitAlg: GitAlg[F],
vcsSpecifics: VCSSpecifics,
vcsApiAlg: VCSApiAlg[F],
vcsRepoAlg: VCSRepoAlg[F],
logAlg: LogAlg[F],
Expand Down Expand Up @@ -84,7 +83,7 @@ final class NurtureAlg[F[_]](
def processUpdate(data: UpdateData): F[Unit] =
for {
_ <- logger.info(s"Process update ${data.update.show}")
head = vcsSpecifics.headForListingPullRequests(data.fork, data.update)
head = vcs.listingBranch(config.vcsType, data.fork, data.update)
pullRequests <- vcsApiAlg.listPullRequests(data.repo, head, data.baseBranch)
_ <- pullRequests.headOption match {
case Some(pr) if pr.isClosed =>
Expand Down Expand Up @@ -123,7 +122,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 = vcs.createBranch(config.vcsType, data.fork, data.update)
requestData = NewPullRequestData.from(data, branchName, config.vcsLogin)
daddykotex marked this conversation as resolved.
Show resolved Hide resolved
pr <- vcsApiAlg.createPullRequest(data.repo, requestData)
_ <- pullRequestRepo.createOrUpdate(
data.repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,25 @@ package org.scalasteward.core.vcs

import org.scalasteward.core.application.Config
import org.scalasteward.core.util.HttpJsonClient
import org.scalasteward.core.github.GitHubSpecifics
import org.scalasteward.core.github.http4s.Http4sGitHubApiAlg
import org.scalasteward.core.gitlab.http4s.Http4sGitLabApiAlg
import org.scalasteward.core.gitlab.GitlabSpecifics
import org.scalasteward.core.vcs.data.AuthenticatedUser
import cats.effect.Sync
import org.scalasteward.core.application.SupportedVCS.GitHub
import org.scalasteward.core.application.SupportedVCS.Gitlab

class VCSSelection[F[_]: Sync](implicit client: HttpJsonClient[F], user: AuthenticatedUser) {
private def github(config: Config): (Http4sGitHubApiAlg[F], GitHubSpecifics) = {
private def github(config: Config): Http4sGitHubApiAlg[F] = {
import org.scalasteward.core.github.http4s.authentication.addCredentials

val alg = new Http4sGitHubApiAlg[F](config.vcsApiHost, _ => addCredentials(user))
val specifics = new GitHubSpecifics()
(alg, specifics)
new Http4sGitHubApiAlg[F](config.vcsApiHost, _ => addCredentials(user))
}
private def gitlab(config: Config): (Http4sGitLabApiAlg[F], GitlabSpecifics) = {
private def gitlab(config: Config): Http4sGitLabApiAlg[F] = {
import org.scalasteward.core.gitlab.http4s.authentication.addCredentials

val alg = new Http4sGitLabApiAlg[F](config.vcsApiHost, user, _ => addCredentials(user))
val specifics = new GitlabSpecifics()
(alg, specifics)
new Http4sGitLabApiAlg[F](config.vcsApiHost, user, _ => addCredentials(user))
}
def build(config: Config): (VCSApiAlg[F], VCSSpecifics) = config.vcsType match {
def getAlg(config: Config): VCSApiAlg[F] = config.vcsType match {
case GitHub => github(config)
case Gitlab => gitlab(config)
}
Expand Down

This file was deleted.

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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,36 @@

package org.scalasteward.core

import org.scalasteward.core.application.SupportedVCS
import org.scalasteward.core.application.SupportedVCS.GitHub
import org.scalasteward.core.application.SupportedVCS.Gitlab
import org.scalasteward.core.vcs.data.Repo
import org.scalasteward.core.model.Update

package object vcs {

def headFor(origin: String, update: Update): String =
s"$origin:${git.branchFor(update).name}"
/** Determines the `head` (GitHub) / `source_branch` (GitLab) parameter for searching
* for already existing pull requests.
*/
def listingBranch(vcsType: SupportedVCS, fork: Repo, update: Update): String =
vcsType match {
case GitHub =>
s"${fork.show}:${git.branchFor(update).name}"

case Gitlab =>
git.branchFor(update).name
}

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

case Gitlab =>
git.branchFor(update).name
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.scalasteward.core.vcs

import org.scalasteward.core.application.SupportedVCS.GitHub
import org.scalasteward.core.application.SupportedVCS.Gitlab
import org.scalasteward.core.util.Nel
import org.scalasteward.core.vcs.data.Repo
import org.scalasteward.core.model.Update

import org.scalatest.{FunSuite, Matchers}

class BranchOutTest extends FunSuite with Matchers {
val repo = Repo("foo", "bar")
val update = Update.Single("ch.qos.logback", "logback-classic", "1.2.0", Nel.of("1.2.3"))

test("listingBranch") {
listingBranch(GitHub, repo, update) shouldBe "foo/bar:update/logback-classic-1.2.3"
listingBranch(Gitlab, repo, update) shouldBe "update/logback-classic-1.2.3"
}

test("createBranch") {
createBranch(GitHub, repo, update) shouldBe "foo:update/logback-classic-1.2.3"
createBranch(Gitlab, repo, update) shouldBe "update/logback-classic-1.2.3"
}
}
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