@@ -182,7 +182,7 @@ func TestFetchGitHubRepoFromRemote(t *testing.T) {
182182 "origin" : {"https://gitlab.com/owner/repo.git" },
183183 },
184184 wantErr : true ,
185- wantErrSubstr : "could not find an 'origin' remote" ,
185+ wantErrSubstr : "is not a GitHub remote" ,
186186 },
187187 {
188188 name : "upstream is GitHub, but no origin" ,
@@ -208,7 +208,7 @@ func TestFetchGitHubRepoFromRemote(t *testing.T) {
208208 "upstream" : {"https://github.com/gh-owner/gh-repo.git" },
209209 },
210210 wantErr : true ,
211- wantErrSubstr : "could not find an 'origin' remote" ,
211+ wantErrSubstr : "is not a GitHub remote" ,
212212 },
213213 {
214214 name : "origin has multiple URLs, first is GitHub" ,
@@ -278,7 +278,7 @@ func TestParseURL(t *testing.T) {
278278 } {
279279 t .Run (test .name , func (t * testing.T ) {
280280 t .Parallel ()
281- repo , err := ParseURL (test .remoteURL )
281+ repo , err := ParseRemote (test .remoteURL )
282282
283283 if test .wantErr {
284284 if err == nil {
@@ -298,6 +298,65 @@ func TestParseURL(t *testing.T) {
298298 }
299299}
300300
301+ func TestParseSSHRemote (t * testing.T ) {
302+ t .Parallel ()
303+ for _ , test := range []struct {
304+ name string
305+ remote string
306+ wantRepo * Repository
307+ wantErr bool
308+ wantErrSubstr string
309+ }{
310+ {
311+ name : "Valid SSH URL with .git" ,
312+ remote :
"[email protected] :owner/repo.git" ,
313+ wantRepo : & Repository {Owner : "owner" , Name : "repo" },
314+ },
315+ {
316+ name : "Valid SSH URL without .git" ,
317+ remote :
"[email protected] :owner/repo" ,
318+ wantRepo : & Repository {Owner : "owner" , Name : "repo" },
319+ },
320+ {
321+ name : "Invalid remote, no git@ prefix" ,
322+ remote : "https://github.com/owner/repo.git" ,
323+ wantErr : true ,
324+ wantErrSubstr : "not a GitHub remote" ,
325+ },
326+ {
327+ name : "Invalid remote, no colon" ,
328+ remote :
"[email protected] /repo.git" ,
329+ wantErr : true ,
330+ wantErrSubstr : "not a GitHub remote" ,
331+ },
332+ {
333+ name : "Invalid remote, no slash" ,
334+ remote :
"[email protected] :owner-repo.git" ,
335+ wantErr : true ,
336+ wantErrSubstr : "not a GitHub remote" ,
337+ },
338+ } {
339+ t .Run (test .name , func (t * testing.T ) {
340+ t .Parallel ()
341+ repo , err := parseSSHRemote (test .remote )
342+ if test .wantErr {
343+ if err == nil {
344+ t .Errorf ("ParseSSHRemote() err = nil, want error containing %q" , test .wantErrSubstr )
345+ } else if ! strings .Contains (err .Error (), test .wantErrSubstr ) {
346+ t .Errorf ("ParseSSHRemote() err = %v, want error containing %q" , err , test .wantErrSubstr )
347+ }
348+ } else {
349+ if err != nil {
350+ t .Errorf ("ParseSSHRemote() err = %v, want nil" , err )
351+ }
352+ if diff := cmp .Diff (test .wantRepo , repo ); diff != "" {
353+ t .Errorf ("ParseSSHRemote() repo mismatch (-want +got): %s" , diff )
354+ }
355+ }
356+ })
357+ }
358+ }
359+
301360func TestCreatePullRequest (t * testing.T ) {
302361 t .Parallel ()
303362 for _ , test := range []struct {
0 commit comments