-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow explicitly specifying the hostname for gh operations
Accept the "HOST/OWNER/REPO" syntax or passing a full URL for both the `--repo` flag and the GH_REPO environment variable and allow setting GH_HOST environment variable to override just the hostname for operations that assume "github.com" by default. Examples: $ gh repo clone example.org/owner/repo $ GH_HOST=example.org gh repo clone repo $ GH_HOST=example.org gh api user $ GH_HOST=example.org gh gist create myfile.txt $ gh issue list -R example.org/owner/repo $ gh issue list -R https://example.org/owner/repo.git $ GH_REPO=example.org/owner/repo gh issue list
- Loading branch information
Showing
16 changed files
with
257 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,3 +114,87 @@ func Test_repoFromURL(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestFromFullName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
wantOwner string | ||
wantName string | ||
wantHost string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "OWNER/REPO combo", | ||
input: "OWNER/REPO", | ||
wantHost: "github.com", | ||
wantOwner: "OWNER", | ||
wantName: "REPO", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "too few elements", | ||
input: "OWNER", | ||
wantErr: errors.New(`expected the "[HOST/]OWNER/REPO" format, got "OWNER"`), | ||
}, | ||
{ | ||
name: "too many elements", | ||
input: "a/b/c/d", | ||
wantErr: errors.New(`expected the "[HOST/]OWNER/REPO" format, got "a/b/c/d"`), | ||
}, | ||
{ | ||
name: "blank value", | ||
input: "a/", | ||
wantErr: errors.New(`expected the "[HOST/]OWNER/REPO" format, got "a/"`), | ||
}, | ||
{ | ||
name: "with hostname", | ||
input: "example.org/OWNER/REPO", | ||
wantHost: "example.org", | ||
wantOwner: "OWNER", | ||
wantName: "REPO", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "full URL", | ||
input: "https://example.org/OWNER/REPO.git", | ||
wantHost: "example.org", | ||
wantOwner: "OWNER", | ||
wantName: "REPO", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "SSH URL", | ||
input: "[email protected]:OWNER/REPO.git", | ||
wantHost: "example.org", | ||
wantOwner: "OWNER", | ||
wantName: "REPO", | ||
wantErr: nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r, err := FromFullName(tt.input) | ||
if tt.wantErr != nil { | ||
if err == nil { | ||
t.Fatalf("no error in result, expected %v", tt.wantErr) | ||
} else if err.Error() != tt.wantErr.Error() { | ||
t.Fatalf("expected error %q, got %q", tt.wantErr.Error(), err.Error()) | ||
} | ||
return | ||
} | ||
if err != nil { | ||
t.Fatalf("got error %v", err) | ||
} | ||
if r.RepoHost() != tt.wantHost { | ||
t.Errorf("expected host %q, got %q", tt.wantHost, r.RepoHost()) | ||
} | ||
if r.RepoOwner() != tt.wantOwner { | ||
t.Errorf("expected owner %q, got %q", tt.wantOwner, r.RepoOwner()) | ||
} | ||
if r.RepoName() != tt.wantName { | ||
t.Errorf("expected name %q, got %q", tt.wantName, r.RepoName()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.