Skip to content
New issue

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

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

Already on GitHub? # to your account

scmInfo is None with HTTPS GitHub remote URL #171

Open
olafurpg opened this issue Sep 23, 2019 · 0 comments
Open

scmInfo is None with HTTPS GitHub remote URL #171

olafurpg opened this issue Sep 23, 2019 · 0 comments

Comments

@olafurpg
Copy link
Member

If cloning a repo on GitHub with HTTPS the remote URL is formatted like https://github.com/olafurpg/sbt-ci-release, which is not picked up by the automatic scmInfo detection in

scmInfo := {
val user = """(?:[^@\/]+@)?"""
val domain = """([^\/]+)"""
val gitPath = """(.*)\.git\/?"""
val unauthenticated = raw"""(?:git|https?|ftps?)\:\/\/$domain\/$gitPath""".r
val ssh = raw"""ssh\:\/\/$user$domain\/$gitPath""".r
val headlessSSH = raw"""$user$domain:$gitPath""".r
def buildScmInfo(domain: String, repo: String) = Option(
ScmInfo(
url(s"https://$domain/$repo"),
s"scm:git:https://$domain/$repo.git",
Some(s"scm:git:git@$domain:$repo.git")
)
)
gitReader.value.withGit(_.remoteOrigin) match {
case unauthenticated(domain, repo) => buildScmInfo(domain,repo)
case ssh(domain, repo) => buildScmInfo(domain,repo)
case headlessSSH(domain, repo) => buildScmInfo(domain,repo)
case _ => None
}
}

A workaround is to add the following to buildSettings:

+    scmInfo ~= {
+      case Some(info) => Some(info)
+      case None =>
+        import scala.sys.process._
+        val identifier = """([^\/]+)"""
+        val GitHubHttps = s"https://github.com/$identifier/$identifier".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:git@github.com:$user/$repo.git")
+                )
+              )
+            case _ =>
+              None
+          }
+        } catch {
+          case NonFatal(_) => None
+        }
+    }

This issue was discovered while publishing a Sonatype release via GitHub Actions with the following error message

 [error] Failed to close the repository
[error] Activity close started:2019-09-22T22:33:25.400Z, stopped:2019-09-22T22:33:33.729Z
[error]     Failed: pom-staging, failureMessage:Invalid POM: /com/geirsson/sbt-ci-release_2.12_1.0/1.4.27/sbt-ci-release-1.4.27.pom: SCM URL missing
[error] java.lang.Exception: Failed to close the repository
[error] Use 'last' for the full log.

It appears that GitHub Actions clone the repository with the HTTPS remote instead of SSH remote.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant