From efefe5a8493c8b5f864f42a30e549e400dbabcd1 Mon Sep 17 00:00:00 2001 From: Michael Dickens Date: Thu, 2 Apr 2020 08:49:43 -0400 Subject: [PATCH 01/10] add MacPorts usage info --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 59e378eda..52ad9c2da 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,20 @@ tool. Check out our [more detailed explanation](/docs/gh-vs-hub.md) to learn mor ### macOS +`gh` is available via [brew][] and [MacPorts][]. + +#### brew + Install: `brew install github/gh/gh` Upgrade: `brew update && brew upgrade gh` +#### MacPorts + +Install `sudo port install gh` + +Upgrade: `sudo port selfupdate && sudo port upgrade gh` + ### Windows `gh` is available via [scoop][], [Chocolatey][], and as downloadable MSI. From 7e1ed5f9a34bbb624aec4d6c1a0c260a51f3119f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Sun, 5 Apr 2020 20:54:29 +0200 Subject: [PATCH 02/10] Fetch upstream remote after adding it --- command/repo.go | 2 +- command/repo_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/command/repo.go b/command/repo.go index afc6ddec7..e7ac12b83 100644 --- a/command/repo.go +++ b/command/repo.go @@ -143,7 +143,7 @@ func addUpstreamRemote(parentRepo ghrepo.Interface, cloneURL string) error { upstreamURL := fmt.Sprintf("https://github.com/%s.git", ghrepo.FullName(parentRepo)) cloneDir := path.Base(strings.TrimSuffix(cloneURL, ".git")) - cloneCmd := git.GitCommand("-C", cloneDir, "remote", "add", "upstream", upstreamURL) + cloneCmd := git.GitCommand("-C", cloneDir, "remote", "add", "-f", "upstream", upstreamURL) cloneCmd.Stdout = os.Stdout cloneCmd.Stderr = os.Stderr return run.PrepareCmd(cloneCmd).Run() diff --git a/command/repo_test.go b/command/repo_test.go index f0d271cf8..baeed3722 100644 --- a/command/repo_test.go +++ b/command/repo_test.go @@ -185,7 +185,7 @@ func TestRepoFork_outside_yes(t *testing.T) { eq(t, output.Stderr(), "") eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/repo.git") - eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add upstream https://github.com/OWNER/REPO.git") + eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add -f upstream https://github.com/OWNER/REPO.git") test.ExpectLines(t, output.String(), "Created fork someone/REPO", @@ -218,7 +218,7 @@ func TestRepoFork_outside_survey_yes(t *testing.T) { eq(t, output.Stderr(), "") eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/repo.git") - eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add upstream https://github.com/OWNER/REPO.git") + eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add -f upstream https://github.com/OWNER/REPO.git") test.ExpectLines(t, output.String(), "Created fork someone/REPO", @@ -414,7 +414,7 @@ func TestRepoClone_hasParent(t *testing.T) { } eq(t, cs.Count, 2) - eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C REPO remote add upstream https://github.com/hubot/ORIG.git") + eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C REPO remote add -f upstream https://github.com/hubot/ORIG.git") } func TestRepoCreate(t *testing.T) { From 806574f9c168eed769c4e21710449738a32dd816 Mon Sep 17 00:00:00 2001 From: Tiernan L Date: Mon, 6 Apr 2020 09:56:45 -1000 Subject: [PATCH 03/10] spell out PR changes "PR" ---> "pull request" for consistency and clarity --- command/pr_checkout.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/pr_checkout.go b/command/pr_checkout.go index 5db8fbd07..d237aefbb 100644 --- a/command/pr_checkout.go +++ b/command/pr_checkout.go @@ -123,7 +123,7 @@ var prCheckoutCmd = &cobra.Command{ Short: "Check out a pull request in Git", Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { - return errors.New("requires a PR number as an argument") + return errors.New("requires a pull request number as an argument") } return nil }, From 1aba83758948acdf3019caef9ff5599f4901105f Mon Sep 17 00:00:00 2001 From: Tiernan L Date: Mon, 6 Apr 2020 11:27:17 -1000 Subject: [PATCH 04/10] update text to long-form Change from "repo" to "repository". Run "gh repo clone -h` to see the usage text I am referring to. We use the word "repository" here: Usage: gh repo fork [] [flags] Usage: gh repo view [] [flags] --- command/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/repo.go b/command/repo.go index 4f8c51e0b..8efda0595 100644 --- a/command/repo.go +++ b/command/repo.go @@ -51,7 +51,7 @@ A repository can be supplied as an argument in any of the following formats: } var repoCloneCmd = &cobra.Command{ - Use: "clone []", + Use: "clone []", Args: cobra.MinimumNArgs(1), Short: "Clone a repository locally", Long: `Clone a GitHub repository locally. From 79f749a02b184d167d4db6050c0f9c1735ae1899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Apr 2020 16:46:36 +0200 Subject: [PATCH 05/10] Avoid checking for updates during `gh completion` This is due to the fact that `gh completion` can be programatically used during shell startup and we definitely don't want to 1. slow down people's startup time 2. show any upgrade notice until the user has invoked `gh` manually --- cmd/gh/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index a9e0837f3..17f2042f2 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -70,7 +70,11 @@ func printError(out io.Writer, err error, cmd *cobra.Command, debug bool) { } func shouldCheckForUpdate() bool { - return updaterEnabled != "" && utils.IsTerminal(os.Stderr) + return updaterEnabled != "" && !isCompletionCommand() && utils.IsTerminal(os.Stderr) +} + +func isCompletionCommand() bool { + return len(os.Args) > 1 && os.Args[1] == "completion" } func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) { From 2915abc2ba8e0110825812a4cf0fafe016f7dcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Apr 2020 16:58:50 +0200 Subject: [PATCH 06/10] Improve user-friendliness of `completion` command When ran directly in the terminal, the command now errors out with: $ gh completion error: the value for `--shell` is required see `gh completion --help` for more information This is to avoid the previously default bash code output confusing the user if they ran the command out of curiousity. A backwards compatibility layer is present here: if stdout is not a terminal, then output bash code like before. This is to support users who have already added a line like this to their bash profile: eval "$(gh completion)" --- command/completion.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/command/completion.go b/command/completion.go index 94c9ccf5d..319d103a2 100644 --- a/command/completion.go +++ b/command/completion.go @@ -1,15 +1,18 @@ package command import ( + "errors" "fmt" + "os" "github.com/cli/cli/internal/cobrafish" + "github.com/cli/cli/utils" "github.com/spf13/cobra" ) func init() { RootCmd.AddCommand(completionCmd) - completionCmd.Flags().StringP("shell", "s", "bash", "Shell type: {bash|zsh|fish|powershell}") + completionCmd.Flags().StringP("shell", "s", "", "Shell type: {bash|zsh|fish|powershell}") } var completionCmd = &cobra.Command{ @@ -17,9 +20,12 @@ var completionCmd = &cobra.Command{ Short: "Generate shell completion scripts", Long: `Generate shell completion scripts for GitHub CLI commands. +The output of this command will be computer code and is meant to be saved to a +file or immediately evaluated by an interactive shell. + For example, for bash you could add this to your '~/.bash_profile': - eval "$(gh completion)" + eval "$(gh completion -s bash)" When installing GitHub CLI through a package manager, however, it's possible that no additional shell configuration is necessary to gain completion support. For @@ -31,6 +37,19 @@ Homebrew, see return err } + if shellType == "" { + out := cmd.OutOrStdout() + isTTY := false + if outFile, isFile := out.(*os.File); isFile { + isTTY = utils.IsTerminal(outFile) + } + + if isTTY { + return errors.New("error: the value for `--shell` is required\nsee `gh help completion` for more information") + } + shellType = "bash" + } + switch shellType { case "bash": return RootCmd.GenBashCompletion(cmd.OutOrStdout()) From d1754b2bb065df2bcaaf953f28b6c905491304c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 8 Apr 2020 12:04:39 +0200 Subject: [PATCH 07/10] Improve `issue/pr/repo view` documentation - Short-form docs for `pr/repo view` no longer say "in browser" - Long-form docs for all these commands now list more information about what will be displayed in the terminal, plus stressing out the alternate behavior with the `--web` flag. - `--web` flag docs: add English articles --- command/issue.go | 7 +++++-- command/pr.go | 12 +++++++----- command/repo.go | 10 ++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/command/issue.go b/command/issue.go index 9e57556e1..fd2e03eef 100644 --- a/command/issue.go +++ b/command/issue.go @@ -38,7 +38,7 @@ func init() { issueListCmd.Flags().StringP("author", "A", "", "Filter by author") issueCmd.AddCommand(issueViewCmd) - issueViewCmd.Flags().BoolP("web", "w", false, "Open issue in browser") + issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser") } var issueCmd = &cobra.Command{ @@ -74,7 +74,10 @@ var issueViewCmd = &cobra.Command{ return nil }, Short: "View an issue", - RunE: issueView, + Long: `Display the title, body, and other information about an issue. + +With '--web', open the issue in a web browser instead.`, + RunE: issueView, } func issueList(cmd *cobra.Command, args []string) error { diff --git a/command/pr.go b/command/pr.go index e494d88b5..c87010365 100644 --- a/command/pr.go +++ b/command/pr.go @@ -31,7 +31,7 @@ func init() { prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label") prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee") - prViewCmd.Flags().BoolP("web", "w", false, "Open pull request in browser") + prViewCmd.Flags().BoolP("web", "w", false, "Open a pull request in the browser") } var prCmd = &cobra.Command{ @@ -56,11 +56,13 @@ var prStatusCmd = &cobra.Command{ } var prViewCmd = &cobra.Command{ Use: "view [{ | | }]", - Short: "View a pull request in the browser", - Long: `View a pull request specified by the argument. + Short: "View a pull request", + Long: `Display the title, body, and other information about a pull request. -Without an argument, the pull request that belongs to the current -branch is displayed.`, +Without an argument, the pull request that belongs to the current branch +is displayed. + +With '--web', open the pull request in a web browser instead.`, RunE: prView, } diff --git a/command/repo.go b/command/repo.go index 5e16f9645..43a28a2fa 100644 --- a/command/repo.go +++ b/command/repo.go @@ -37,7 +37,7 @@ func init() { repoForkCmd.Flags().Lookup("remote").NoOptDefVal = "true" repoCmd.AddCommand(repoViewCmd) - repoViewCmd.Flags().BoolP("web", "w", false, "Open repository in browser") + repoViewCmd.Flags().BoolP("web", "w", false, "Open a repository in the browser") } var repoCmd = &cobra.Command{ @@ -80,10 +80,12 @@ With no argument, creates a fork of the current repository. Otherwise, forks the var repoViewCmd = &cobra.Command{ Use: "view []", - Short: "View a repository in the browser", - Long: `View a GitHub repository. + Short: "View a repository", + Long: `Display the description and the README of a GitHub repository. -With no argument, the repository for the current directory is displayed.`, +With no argument, the repository for the current directory is displayed. + +With '--web', open the repository in a web browser instead.`, RunE: repoView, } From 60e7bb624330703a200cfd61f25e83d48c39c63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 8 Apr 2020 12:26:15 +0200 Subject: [PATCH 08/10] Tweak macOS installation docs --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52ad9c2da..1fdf1bad6 100644 --- a/README.md +++ b/README.md @@ -40,17 +40,17 @@ tool. Check out our [more detailed explanation](/docs/gh-vs-hub.md) to learn mor ### macOS -`gh` is available via [brew][] and [MacPorts][]. +`gh` is available via Homebrew and MacPorts. -#### brew +#### Homebrew Install: `brew install github/gh/gh` -Upgrade: `brew update && brew upgrade gh` +Upgrade: `brew upgrade gh` #### MacPorts -Install `sudo port install gh` +Install: `sudo port install gh` Upgrade: `sudo port selfupdate && sudo port upgrade gh` From 531bfbc295693fa5ee765945ffb7d7e3913928f7 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Wed, 8 Apr 2020 15:08:08 +0900 Subject: [PATCH 09/10] Update unit tests for PR metadata --- command/pr_test.go | 37 +++++++++---------- .../prViewPreviewWithMetadataByBranch.json | 30 +++++++++++++-- ...=> prViewPreviewWithMetadataByNumber.json} | 17 +++++---- 3 files changed, 53 insertions(+), 31 deletions(-) rename test/fixtures/{prViewPreviewWithLotsOfMetadata.json => prViewPreviewWithMetadataByNumber.json} (91%) diff --git a/command/pr_test.go b/command/pr_test.go index 705792e82..00cabcbb9 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -416,11 +416,25 @@ func TestPRView_Preview(t *testing.T) { expectedOutputs: []string{ `Blueberries are from a fork`, `Open • nobody wants to merge 12 commits into master from blueberries`, - `Participants: marseilles\n`, `blueberries taste good`, `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`, }, }, + "Open PR with metadata by number": { + ownerRepo: "master", + args: "pr view 12", + fixture: "../test/fixtures/prViewPreviewWithMetadataByNumber.json", + expectedOutputs: []string{ + `Blueberries are from a fork`, + `Open • nobody wants to merge 12 commits into master from blueberries`, + `Assignees: marseilles, monaco\n`, + `Labels: one, two, three, four, five\n`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`, + `Milestone: uluru\n`, + `blueberries taste good`, + `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12\n`, + }, + }, "Open PR with metadata by branch": { ownerRepo: "master", args: "pr view blueberries", @@ -429,30 +443,13 @@ func TestPRView_Preview(t *testing.T) { `Blueberries are a good fruit`, `Open • nobody wants to merge 8 commits into master from blueberries`, `Assignees: marseilles, monaco\n`, - `Labels: one, two, three\n`, - `Projects: The GitHub CLI \(to do list\)\n`, + `Labels: one, two, three, four, five\n`, + `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`, `Milestone: uluru\n`, - `Participants: marseilles, monaco, montpellier\n`, `blueberries taste good`, `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10\n`, }, }, - "Open PR with lots of metadata": { - ownerRepo: "master", - args: "pr view 12", - fixture: "../test/fixtures/prViewPreviewWithLotsOfMetadata.json", - expectedOutputs: []string{ - `Blueberries are from a fork`, - `Open • nobody wants to merge 12 commits into master from blueberries`, - `Assignees: marseilles, monaco, montpellier, …\n`, - `Labels: one, two, three, …\n`, - `Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), …\n`, - `Milestone: uluru\n`, - `Participants: marseilles, monaco, montpellier, …\n`, - `blueberries taste good`, - `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`, - }, - }, "Open PR for the current branch": { ownerRepo: "blueberries", args: "pr view", diff --git a/test/fixtures/prViewPreviewWithMetadataByBranch.json b/test/fixtures/prViewPreviewWithMetadataByBranch.json index 5f58fc0fe..483b4d63c 100644 --- a/test/fixtures/prViewPreviewWithMetadataByBranch.json +++ b/test/fixtures/prViewPreviewWithMetadataByBranch.json @@ -76,22 +76,44 @@ }, { "name": "three" + }, + { + "name": "four" + }, + { + "name": "five" } ], - "totalcount": 3 + "totalcount": 5 }, "projectcards": { "nodes": [ { "project": { - "name": "The GitHub CLI" + "name": "Project 1" }, "column": { - "name": "to do list" + "name": "column A" + } + }, + { + "project": { + "name": "Project 2" + }, + "column": { + "name": "column B" + } + }, + { + "project": { + "name": "Project 3" + }, + "column": { + "name": "column C" } } ], - "totalcount": 1 + "totalcount": 3 }, "milestone": { "title": "uluru" diff --git a/test/fixtures/prViewPreviewWithLotsOfMetadata.json b/test/fixtures/prViewPreviewWithMetadataByNumber.json similarity index 91% rename from test/fixtures/prViewPreviewWithLotsOfMetadata.json rename to test/fixtures/prViewPreviewWithMetadataByNumber.json index b6cd1d7ca..24927cb19 100644 --- a/test/fixtures/prViewPreviewWithLotsOfMetadata.json +++ b/test/fixtures/prViewPreviewWithMetadataByNumber.json @@ -17,12 +17,9 @@ }, { "login": "monaco" - }, - { - "login": "montpellier" } ], - "totalcount": 4 + "totalcount": 2 }, "labels": { "nodes": [ @@ -34,9 +31,15 @@ }, { "name": "three" + }, + { + "name": "four" + }, + { + "name": "five" } ], - "totalcount": 4 + "totalcount": 5 }, "projectcards": { "nodes": [ @@ -65,7 +68,7 @@ } } ], - "totalcount": 4 + "totalcount": 3 }, "milestone": { "title": "uluru" @@ -82,7 +85,7 @@ "login": "montpellier" } ], - "totalcount": 4 + "totalcount": 3 }, "commits": { "totalCount": 12 From 6d0e5bf2b8d6acce51add7bbdd4e047ea2db15d9 Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Fri, 10 Apr 2020 01:01:41 +0900 Subject: [PATCH 10/10] Remove Participants related codes for `pr view`` --- api/queries_pr.go | 18 --------------- command/pr.go | 17 -------------- test/fixtures/prViewPreview.json | 8 ------- .../prViewPreviewWithMetadataByBranch.json | 22 ------------------- .../prViewPreviewWithMetadataByNumber.json | 14 ------------ 5 files changed, 79 deletions(-) diff --git a/api/queries_pr.go b/api/queries_pr.go index ad29f163f..0b2fd378a 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -107,12 +107,6 @@ type PullRequest struct { Milestone struct { Title string } - Participants struct { - Nodes []struct { - Login string - } - TotalCount int - } } type NotFoundError struct { @@ -423,12 +417,6 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu milestone{ title } - participants(first: 100) { - nodes { - login - } - totalCount - } } } }` @@ -528,12 +516,6 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea milestone{ title } - participants(first: 100) { - nodes { - login - } - totalCount - } } } } diff --git a/command/pr.go b/command/pr.go index 21c3853cd..797ce9606 100644 --- a/command/pr.go +++ b/command/pr.go @@ -425,23 +425,6 @@ func prProjectList(pr api.PullRequest) string { return list } -func prParticipantList(pr api.PullRequest) string { - if len(pr.Participants.Nodes) == 0 { - return "" - } - - participantNames := make([]string, 0, len(pr.Participants.Nodes)) - for _, participant := range pr.Participants.Nodes { - participantNames = append(participantNames, participant.Login) - } - - list := strings.Join(participantNames, ", ") - if pr.Participants.TotalCount > len(pr.Participants.Nodes) { - list += ", …" - } - return list -} - var prURLRE = regexp.MustCompile(`^https://github\.com/([^/]+)/([^/]+)/pull/(\d+)`) func prFromURL(arg string) (string, ghrepo.Interface) { diff --git a/test/fixtures/prViewPreview.json b/test/fixtures/prViewPreview.json index 408d0f1fa..f660eaa6c 100644 --- a/test/fixtures/prViewPreview.json +++ b/test/fixtures/prViewPreview.json @@ -25,14 +25,6 @@ "milestone": { "title": "" }, - "participants": { - "nodes": [ - { - "login": "marseilles" - } - ], - "totalcount": 1 - }, "commits": { "totalCount": 12 }, diff --git a/test/fixtures/prViewPreviewWithMetadataByBranch.json b/test/fixtures/prViewPreviewWithMetadataByBranch.json index 483b4d63c..aaf9c6dfa 100644 --- a/test/fixtures/prViewPreviewWithMetadataByBranch.json +++ b/test/fixtures/prViewPreviewWithMetadataByBranch.json @@ -27,14 +27,6 @@ "totalcount": 0 }, "milestone": {}, - "participants": { - "nodes": [ - { - "login": "nobody" - } - ], - "totalcount": 1 - }, "commits": { "totalCount": 12 }, @@ -118,20 +110,6 @@ "milestone": { "title": "uluru" }, - "participants": { - "nodes": [ - { - "login": "marseilles" - }, - { - "login": "monaco" - }, - { - "login": "montpellier" - } - ], - "totalcount": 3 - }, "headRepositoryOwner": { "login": "OWNER" }, diff --git a/test/fixtures/prViewPreviewWithMetadataByNumber.json b/test/fixtures/prViewPreviewWithMetadataByNumber.json index 24927cb19..de0da816a 100644 --- a/test/fixtures/prViewPreviewWithMetadataByNumber.json +++ b/test/fixtures/prViewPreviewWithMetadataByNumber.json @@ -73,20 +73,6 @@ "milestone": { "title": "uluru" }, - "participants": { - "nodes": [ - { - "login": "marseilles" - }, - { - "login": "monaco" - }, - { - "login": "montpellier" - } - ], - "totalcount": 3 - }, "commits": { "totalCount": 12 },