-
Notifications
You must be signed in to change notification settings - Fork 502
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
Bitbucket support #647
Bitbucket support #647
Conversation
This refactoring is breaking for users: * args change from --github-api-host to --vcs-api-host * args change from --github-login to --vcs-login
This is a work in progress. There are a lot of things to discuss: * the custom encoder/decoder to convert between GitHub json responses and Gitlab json responses * the Monad/MonadThrowabled requirements added because some operations in Gitlab are multi-step where as their original Github conterpart are a single step * the specific vcs thingy
Can you target fthomas/topic/gitlab branch? instead of fthomas/master (that way we won't see commits that were merged already in this branch) |
@daddykotex done |
Many thanks for working on this! The code looks good to me on a cursory glance and I'll try to have a closer look soon. I think the best way forward here is to merge #645 into master and then to merge this PR so we don't mix the GitLab and Bitbucket support in one big PR. I'll try to merge #645 today. |
About the conflict, it happens becase I remove the VCSSpecifics interface. You can remove it from VCSSelection where the new This patch should do it: diff --git a/build.sbt b/build.sbt
index ac1ef62..9aa3288 100644
--- a/build.sbt
+++ b/build.sbt
@@ -206,7 +206,7 @@ addCommandAlias(
Seq("--repos-file", s"$projectDir/repos.md"),
Seq("--git-author-name", "Scala Steward"),
Seq("--git-author-email", s"me@$projectName.org"),
- Seq("--github-login", projectName),
+ Seq("--vcs-login", projectName),
Seq("--git-ask-pass", s"$home/.github/askpass/$projectName.sh"),
Seq("--whitelist", s"$home/.cache/coursier"),
Seq("--whitelist", s"$home/.coursier"),
diff --git a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
index 0ab9ef0..602dddf 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala
@@ -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
@@ -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]
diff --git a/modules/core/src/main/scala/org/scalasteward/core/bitbucket/BitbucketSpecifics.scala b/modules/core/src/main/scala/org/scalasteward/core/bitbucket/BitbucketSpecifics.scala
deleted file mode 100644
index c283bd1..0000000
--- a/modules/core/src/main/scala/org/scalasteward/core/bitbucket/BitbucketSpecifics.scala
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2018-2019 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.bitbucket
-
-import org.scalasteward.core.git
-import org.scalasteward.core.model.Update
-import org.scalasteward.core.vcs.data.Repo
-import org.scalasteward.core.vcs.VCSSpecifics
-
-class BitbucketSpecifics extends VCSSpecifics {
-
- override def headForListingPullRequests(fork: Repo, update: Update): String =
- git.branchFor(update).name
-
-}
diff --git a/modules/core/src/main/scala/org/scalasteward/core/github/GitHubSpecifics.scala b/modules/core/src/main/scala/org/scalasteward/core/github/GitHubSpecifics.scala
deleted file mode 100644
index 8284d97..0000000
--- a/modules/core/src/main/scala/org/scalasteward/core/github/GitHubSpecifics.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2018-2019 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.github
-
-import org.scalasteward.core.model.Update
-import org.scalasteward.core.vcs
-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)
-}
diff --git a/modules/core/src/main/scala/org/scalasteward/core/gitlab/GitlabSpecifics.scala b/modules/core/src/main/scala/org/scalasteward/core/gitlab/GitlabSpecifics.scala
deleted file mode 100644
index 2b74da0..0000000
--- a/modules/core/src/main/scala/org/scalasteward/core/gitlab/GitlabSpecifics.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2018-2019 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.gitlab
-
-import org.scalasteward.core.model.Update
-import org.scalasteward.core.vcs.data.Repo
-import org.scalasteward.core.git
-import org.scalasteward.core.vcs.VCSSpecifics
-
-class GitlabSpecifics extends VCSSpecifics {
- override def headForListingPullRequests(fork: Repo, update: Update): String =
- git.branchFor(update).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 2edf39c..e6de36c 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
@@ -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
@@ -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],
@@ -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 =>
@@ -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)
pr <- vcsApiAlg.createPullRequest(data.repo, requestData)
_ <- pullRequestRepo.createOrUpdate(
data.repo,
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSelection.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSelection.scala
index bbf44a6..7476ecc 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSelection.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSelection.scala
@@ -21,39 +21,32 @@ import org.scalasteward.core.application.Config
import org.scalasteward.core.application.SupportedVCS.Bitbucket
import org.scalasteward.core.application.SupportedVCS.GitHub
import org.scalasteward.core.application.SupportedVCS.Gitlab
-import org.scalasteward.core.bitbucket.BitbucketSpecifics
import org.scalasteward.core.bitbucket.http4s.Http4sBitbucketApiAlg
-import org.scalasteward.core.github.GitHubSpecifics
import org.scalasteward.core.github.http4s.Http4sGitHubApiAlg
-import org.scalasteward.core.gitlab.GitlabSpecifics
import org.scalasteward.core.gitlab.http4s.Http4sGitLabApiAlg
import org.scalasteward.core.util.HttpJsonClient
import org.scalasteward.core.vcs.data.AuthenticatedUser
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))
}
- private def bitbucket(config: Config): (Http4sBitbucketApiAlg[F], BitbucketSpecifics) = {
+ private def bitbucket(config: Config): Http4sBitbucketApiAlg[F] = {
import org.scalasteward.core.bitbucket.http4s.authentication.addCredentials
- val alg = new Http4sBitbucketApiAlg(config.vcsApiHost, user, _ => addCredentials(user))
- val specifics = new BitbucketSpecifics()
- (alg, specifics)
+ new Http4sBitbucketApiAlg(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)
case Bitbucket => bitbucket(config)
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSpecifics.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSpecifics.scala
deleted file mode 100644
index f163b24..0000000
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/VCSSpecifics.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2018-2019 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.vcs
-
-import org.scalasteward.core.model.Update
-import org.scalasteward.core.vcs.data.Repo
-
-trait VCSSpecifics {
-
- /** Determines the `head` (GitHub) / `source_branch` (GitLab) parameter for searching
- * for already existing pull requests.
- */
- def headForListingPullRequests(fork: Repo, update: Update): String
-}
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
index 5cbcaec..2e61ebb 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/data/NewPullRequestData.scala
@@ -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,
@@ -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
)
}
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/package.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/package.scala
index 3ed621e..3df7daf 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/package.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/package.scala
@@ -16,11 +16,37 @@
package org.scalasteward.core
+import org.scalasteward.core.application.SupportedVCS
+import org.scalasteward.core.application.SupportedVCS.Bitbucket
+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, Bitbucket) 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 | Bitbucket =>
+ git.branchFor(update).name
+ }
+
+ /** Determines the `head` (GitHub) / `source_branch` (GitLab, Bitbucket) 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 | Bitbucket =>
+ git.branchFor(update).name
+ }
}
diff --git a/modules/core/src/test/scala/org/scalasteward/core/github/GitHubSpecificsTest.scala b/modules/core/src/test/scala/org/scalasteward/core/github/GitHubSpecificsTest.scala
deleted file mode 100644
index 30fa2cf..0000000
--- a/modules/core/src/test/scala/org/scalasteward/core/github/GitHubSpecificsTest.scala
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.scalasteward.core.github
-
-import org.scalasteward.core.model.Update
-import org.scalasteward.core.vcs.data.Repo
-import org.scalatest.{FunSuite, Matchers}
-import org.scalasteward.core.util.Nel
-
-class GitHubSpecificsTest extends FunSuite with Matchers {
- val specifics = new GitHubSpecifics
-
- test("headForListingPullRequests") {
- specifics.headForListingPullRequests(
- Repo("scala-steward", "bar"),
- Update.Single("ch.qos.logback", "logback-classic", "1.2.0", Nel.of("1.2.3"))
- ) shouldBe "scala-steward/bar:update/logback-classic-1.2.3"
- }
-}
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSPackageTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSPackageTest.scala
new file mode 100644
index 0000000..1388c27
--- /dev/null
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/VCSPackageTest.scala
@@ -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"
+ }
+}
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
index 644ab6a..ac42c01 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/data/NewPullRequestDataTest.scala
@@ -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
"""|{
diff --git a/scripts/run.sh b/scripts/run.sh
index b55fb4a..235391c 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -17,7 +17,7 @@ java -jar ${JAR} \
--repos-file "$STEWARD_DIR/repos.md" \
--git-author-name "Scala Steward" \
--git-author-email "me@$LOGIN.org" \
- --github-login ${LOGIN} \
+ --vcs-login ${LOGIN} \
--git-ask-pass "$HOME/.github/askpass/$LOGIN.sh" \
--ignore-opts-files \
--sign-commits \
|
Codecov Report
@@ Coverage Diff @@
## master #647 +/- ##
==========================================
+ Coverage 57.39% 59.92% +2.52%
==========================================
Files 71 81 +10
Lines 953 1048 +95
Branches 32 21 -11
==========================================
+ Hits 547 628 +81
- Misses 406 420 +14
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #647 +/- ##
==========================================
+ Coverage 57.39% 60.32% +2.92%
==========================================
Files 71 78 +7
Lines 953 1041 +88
Branches 32 22 -10
==========================================
+ Hits 547 628 +81
- Misses 406 413 +7
Continue to review full report at Codecov.
|
Thx @daddykotex for providing the patch. |
This pull request targets #562 and builds on top of @tjheslin1 work on #562 and @daddykotex work on #313 .
https://github.com/fg-devs co-authored the bitbucket implementation during a company hackday.
@fthomas please if you have time please let us know how we can improve the code. I enjoyed digging into this codebase a lot. Thanks for creating scala-steward in the first place and maintaining it.