Skip to content

Commit 60622cb

Browse files
committed
First extract GH repo from upstream, then origin
1 parent 366caab commit 60622cb

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

github/src/main/scala/org/typelevel/sbt/TypelevelGitHubPlugin.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,23 @@ object TypelevelGitHubPlugin extends AutoPlugin {
5858
private[sbt] def gitHubUserRepo = Def.setting {
5959
import scala.sys.process._
6060

61-
val identifier = """([^\/]+?)"""
62-
val GitHubHttps = s"https://github.com/$identifier/$identifier(?:\\.git)?".r
63-
val GitHubGit = s"git://github.com:$identifier/$identifier(?:\\.git)?".r
64-
val GitHubSsh = s"[email protected]:$identifier/$identifier(?:\\.git)?".r
65-
Try {
66-
val remote = List("git", "ls-remote", "--get-url", "origin").!!.trim()
67-
remote match {
68-
case GitHubHttps(user, repo) => Some((user, repo))
69-
case GitHubGit(user, repo) => Some((user, repo))
70-
case GitHubSsh(user, repo) => Some((user, repo))
71-
case _ => None
72-
}
73-
}.toOption.flatten
61+
def fromRemote(remote: String) = {
62+
val identifier = """([^\/]+?)"""
63+
val GitHubHttps = s"https://github.com/$identifier/$identifier(?:\\.git)?".r
64+
val GitHubGit = s"git://github.com:$identifier/$identifier(?:\\.git)?".r
65+
val GitHubSsh = s"[email protected]:$identifier/$identifier(?:\\.git)?".r
66+
Try {
67+
List("git", "ls-remote", "--get-url", remote).!!.trim() match {
68+
case GitHubHttps(user, repo) => Some((user, repo))
69+
case GitHubGit(user, repo) => Some((user, repo))
70+
case GitHubSsh(user, repo) => Some((user, repo))
71+
case _ => None
72+
}
73+
}.toOption.flatten
74+
}
75+
76+
// upstream if this is a fork, otherwise fallback to origin
77+
fromRemote("upstream").orElse(fromRemote("origin"))
7478
}
7579

7680
}

0 commit comments

Comments
 (0)