Skip to content

Commit 00fd5f7

Browse files
committed
feat: added git github URL parsing to internal pkg
1 parent a64117f commit 00fd5f7

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

internal/github/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
var patterns = []string{
3131
`^(?P<scheme>https?)://(?P<resource>[^/]+)/(?P<owner>[^/]+)/(?P<repo>[^/]+)(/(?:tree|blob)/(?P<branch>[^/]+)(?P<path>/.*)?)?$`,
3232
`^(?P<scheme>https?)://(?P<resource>raw\.githubusercontent\.com)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/(?P<branch>[^/]+)(?P<path>/.*)$`,
33+
`^(?P<scheme>git)@(?P<resource>github\.com):(?P<owner>[^/]+)/(?P<repo>[^/]+)\.git$`,
3334
}
3435

3536
// New factory to create a new GitHub instance.

internal/github/parser_public_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,34 @@ func (suite *GitHubPublicTestSuite) TestParseOk() {
117117
href: "https://raw.githubusercontent.com/retr0h/git-url-parse/main/files/file0.json",
118118
},
119119
},
120+
{
121+
input: "https://www.github.com/retr0h/git-url-parse",
122+
want: &url{
123+
protocol: "https",
124+
resource: "www.github.com",
125+
owner: "retr0h",
126+
repo: "git-url-parse",
127+
path: "",
128+
branch: "",
129+
provider: "github",
130+
href: "https://www.github.com/retr0h/git-url-parse",
131+
},
132+
},
133+
{
134+
input: "[email protected]:retr0h/git-url-parse.git",
135+
want: &url{
136+
protocol: "git",
137+
resource: "github.com",
138+
owner: "retr0h",
139+
repo: "git-url-parse",
140+
path: "",
141+
branch: "",
142+
provider: "github",
143+
href: "[email protected]:retr0h/git-url-parse.git",
144+
},
145+
},
120146
}
121147

122-
// "[email protected]:retr0h/git-url-parse.git"
123-
// "[email protected]:foobar/retr0h/git-url-parse.git"
124-
// "https://www.github.com/retr0h/git-url-parse"
125-
126148
for _, tc := range tests {
127149
var got internal.RepositoryURLManager
128150
got, err := suite.rm.Parse(tc.input)
@@ -154,6 +176,13 @@ func (suite *GitHubPublicTestSuite) TestParseFails() {
154176
input: "bogus://url/",
155177
want: fmt.Sprintf("could match url: %s to any pattern", "bogus://url/"),
156178
},
179+
{
180+
input: "[email protected]:foobar/retr0h/git-url-parse.git",
181+
want: fmt.Sprintf(
182+
"could match url: %s to any pattern",
183+
"[email protected]:foobar/retr0h/git-url-parse.git",
184+
),
185+
},
157186
}
158187

159188
for _, tc := range tests {

0 commit comments

Comments
 (0)