Changed name from SHA to Commit

This commit is contained in:
bchadwic 2021-07-14 01:19:55 -07:00
parent 0e18db2b11
commit 158a15160d
2 changed files with 22 additions and 16 deletions

View file

@ -27,7 +27,7 @@ type BrowseOptions struct {
SelectorArg string
Branch string
SHA string
Commit string
ProjectsFlag bool
SettingsFlag bool
WikiFlag bool
@ -81,8 +81,9 @@ func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Co
}
if err := cmdutil.MutuallyExclusive(
"specify only one of `--branch`, `--projects`, `--wiki`, or `--settings`",
"specify only one of `--branch`, `--commit`, `--projects`, `--wiki`, or `--settings`",
opts.Branch != "",
opts.Commit != "",
opts.WikiFlag,
opts.SettingsFlag,
opts.ProjectsFlag,
@ -103,7 +104,7 @@ func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Co
cmd.Flags().BoolVarP(&opts.SettingsFlag, "settings", "s", false, "Open repository settings")
cmd.Flags().BoolVarP(&opts.NoBrowserFlag, "no-browser", "n", false, "Print destination URL instead of opening the browser")
cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Select another branch by passing in the branch name")
cmd.Flags().StringVarP(&opts.SHA, "sha", "a", "", "Select a commit by passing in the SHA hash")
cmd.Flags().StringVarP(&opts.Commit, "commit", "c", "", "Select a commit by passing in the SHA hash")
return cmd
}
@ -129,8 +130,8 @@ func runBrowse(opts *BrowseOptions) error {
url += "/wiki"
} else if opts.Branch != "" {
url += "/tree/" + opts.Branch + "/"
} else if opts.SHA != "" {
url += "/tree/" + opts.SHA + "/"
} else if opts.Commit != "" {
url += "/tree/" + opts.Commit + "/"
}
} else {
if isNumber(opts.SelectorArg) {
@ -142,8 +143,8 @@ func runBrowse(opts *BrowseOptions) error {
}
if opts.Branch != "" {
url += "/tree/" + opts.Branch + "/"
} else if opts.SHA != "" {
url += "/tree/" + opts.SHA + "/"
} else if opts.Commit != "" {
url += "/tree/" + opts.Commit + "/"
} else {
apiClient := api.NewClientFromHTTP(httpClient)
branchName, err := api.RepoDefaultBranch(apiClient, baseRepo)

View file

@ -59,16 +59,21 @@ func TestNewCmdBrowse(t *testing.T) {
wantsErr: false,
},
{
name: "SHA flag",
cli: "--sha e32e640",
name: "Commit flag",
cli: "--commit e32e640",
wants: BrowseOptions{
SHA: "e32e640",
Commit: "e32e640",
},
wantsErr: false,
},
{
name: "SHA flag no arg",
cli: "-a",
name: "Commit flag no arg",
cli: "-c",
wantsErr: true,
},
{
name: "Multi flags",
cli: "-c 1a2b3c -b trunk",
wantsErr: true,
},
{
@ -268,18 +273,18 @@ func Test_runBrowse(t *testing.T) {
expectedURL: "https://github.com/mislav/will_paginate/tree/3-0-stable/init.rb#L6",
},
{
name: "opening browser with SHA hash no args",
name: "opening browser with Commit hash no args",
opts: BrowseOptions{
SHA: "162a1b2",
Commit: "162a1b2",
},
baseRepo: ghrepo.New("torvalds", "linux"),
wantsErr: false,
expectedURL: "https://github.com/torvalds/linux/tree/162a1b2/",
},
{
name: "opening browser with SHA hash file arg",
name: "opening browser with commit hash file arg",
opts: BrowseOptions{
SHA: "162a1b2",
Commit: "162a1b2",
SelectorArg: "api/cache.go:32",
},
baseRepo: ghrepo.New("cli", "cli"),