Skip to content

Commit

Permalink
Support SSH and Git protocol remote URLs
Browse files Browse the repository at this point in the history
When extracting the SCM info from the git remote URL:

* Support HTTPS, SSH and git protocols
* Support URLs with the optional `.git` suffix
  • Loading branch information
cb372 committed Apr 21, 2020
1 parent 3c6fe53 commit 18a6bd9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,30 @@ object CiReleasePlugin extends AutoPlugin {
}
}

private def gitHubScmInfo(user: String, repo: String) =
ScmInfo(
url(s"https://github.com/$user/$repo"),
s"scm:git:https://github.com/$user/$repo.git",
Some(s"scm:git:[email protected]:$user/$repo.git")
)

override lazy val buildSettings: Seq[Def.Setting[_]] = List(
dynverSonatypeSnapshots := true,
scmInfo ~= {
case Some(info) => Some(info)
case None =>
import scala.sys.process._
val identifier = """([^\/]+)"""
val GitHubHttps = s"https://github.com/$identifier/$identifier".r
val identifier = """([^\/]+?)"""
val GitHubHttps = s"https://github.com/$identifier/$identifier(?:\\.git)?".r
val GitHubGit = s"git://github.com:$identifier/$identifier(?:\\.git)?".r
val GitHubSsh = s"[email protected]:$identifier/$identifier(?:\\.git)?".r
try {
val remote = List("git", "ls-remote", "--get-url", "origin").!!.trim()
remote match {
case GitHubHttps(user, repo) =>
Some(
ScmInfo(
url(s"https://github.com/$user/$repo"),
s"scm:git:https://github.com/$user/$repo.git",
Some(s"scm:git:[email protected]:$user/$repo.git")
)
)
case _ =>
None
case GitHubHttps(user, repo) => Some(gitHubScmInfo(user, repo))
case GitHubGit(user, repo) => Some(gitHubScmInfo(user, repo))
case GitHubSsh(user, repo) => Some(gitHubScmInfo(user, repo))
case _ => None
}
} catch {
case NonFatal(_) => None
Expand Down

0 comments on commit 18a6bd9

Please sign in to comment.