Skip to content

Commit 39743fb

Browse files
authored
Merge pull request #1588 from JD557/support-ssh-scm-urls
Add support for explicit SSH connections in SCM URLs
2 parents 9b4484a + c37bcd4 commit 39743fb

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

modules/data/src/main/scala/scaladex/data/cleanup/ScmInfoParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object ScmInfoParser extends Parsers:
2020
else v
2121

2222
private def ScmUrl[A: P] = P(
23-
"scm:".? ~ "git:".? ~ ("git@" | "https://" | "git://" | "//") ~
23+
"scm:".? ~ "git:".? ~ ("git@" | "https://" | "git://" | ("ssh://" ~ "git@".?) | "//") ~
2424
"github.com" ~ (":" | "/") ~ Segment
2525
.rep(1)
2626
.! ~ "/" ~ Segment.rep(1).!.map(removeDotGit)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package scaladex.data
2+
package cleanup
3+
4+
import org.scalatest.funspec.AnyFunSpec
5+
import org.scalatest.matchers.should.Matchers
6+
7+
class ScmInfoParserTests extends AnyFunSpec with Matchers:
8+
describe("ScmInfoParse") {
9+
it("correctly parse valid SCM strings") {
10+
// Implicit protocol
11+
ScmInfoParser
12+
.parse("scm:git:[email protected]:foobarbuz/example.git")
13+
.map(_.toString) shouldBe Some("foobarbuz/example")
14+
// HTTPS
15+
ScmInfoParser
16+
.parse("scm:https://github.com/foobarbuz/example.git")
17+
.map(_.toString) shouldBe Some("foobarbuz/example")
18+
ScmInfoParser
19+
.parse("scm:https://github.com/foobarbuz/example")
20+
.map(_.toString) shouldBe Some("foobarbuz/example")
21+
// Git
22+
ScmInfoParser
23+
.parse("scm:git:git://github.com:foobarbuz/example.git")
24+
.map(_.toString) shouldBe Some("foobarbuz/example")
25+
ScmInfoParser
26+
.parse("scm:git://github.com:foobarbuz/example.git")
27+
.map(_.toString) shouldBe Some("foobarbuz/example")
28+
// SSH
29+
ScmInfoParser
30+
.parse("scm:git:ssh://[email protected]:foobarbuz/example.git")
31+
.map(_.toString) shouldBe Some("foobarbuz/example")
32+
ScmInfoParser
33+
.parse("scm:git:ssh://github.com:foobarbuz/example.git")
34+
.map(_.toString) shouldBe Some("foobarbuz/example")
35+
// Unknown protocol
36+
ScmInfoParser
37+
.parse("scm:git:unknown://[email protected]:foobarbuz/example.git")
38+
.map(_.toString) shouldBe None
39+
ScmInfoParser
40+
.parse("scm:git:unknown://github.com:foobarbuz/example.git")
41+
.map(_.toString) shouldBe None
42+
}
43+
}
44+
end ScmInfoParserTests

0 commit comments

Comments
 (0)