From a3eb099c14cdfcc0705ddfc464d464358f93bd79 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 31 Aug 2020 08:35:32 +0200 Subject: [PATCH 1/9] Remove feedback survey from README --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4fd0311e0..06d3279db 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,9 @@ the terminal next to where you are already working with `git` and your code. While in beta, GitHub CLI is available for repos hosted on GitHub.com only. It currently does not support repositories hosted on GitHub Enterprise Server or other hosting providers. We are planning on adding support for GitHub Enterprise Server after GitHub CLI is out of beta (likely towards the end of 2020), and we want to ensure that the API endpoints we use are more widely available for GHES versions that most GitHub customers are on. -## We need your feedback +## Feedback -GitHub CLI is currently in its early development stages, and we're hoping to get feedback from people using it. - -If you've installed and used `gh`, we'd love for you to take a short survey here (no more than five minutes): https://forms.gle/umxd3h31c7aMQFKG7 - -And if you spot bugs or have features that you'd really like to see in `gh`, please check out the [contributing page][] +We love to hear feedback about `gh`. If you spot bugs or have features that you'd really like to see in `gh`, please check out the [contributing page][]. ## Usage @@ -128,7 +124,7 @@ Install and upgrade: Install and upgrade: 1. Download the `.rpm` file from the [releases page][]; -2. Install the downloaded file: `sudo yum localinstall gh_*_linux_amd64.rpm` +2. Install the downloaded file: `sudo yum localinstall gh_*_linux_amd64.rpm` ### openSUSE/SUSE Linux From a8add832b54a6b6529c982e7801fc2f267ec304c Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 31 Aug 2020 16:27:27 +0200 Subject: [PATCH 2/9] Address PR feedback and link cleanup --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 06d3279db..3a1099679 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ the terminal next to where you are already working with `git` and your code. While in beta, GitHub CLI is available for repos hosted on GitHub.com only. It currently does not support repositories hosted on GitHub Enterprise Server or other hosting providers. We are planning on adding support for GitHub Enterprise Server after GitHub CLI is out of beta (likely towards the end of 2020), and we want to ensure that the API endpoints we use are more widely available for GHES versions that most GitHub customers are on. -## Feedback +## We want your feedback -We love to hear feedback about `gh`. If you spot bugs or have features that you'd really like to see in `gh`, please check out the [contributing page][]. +We'd love to hear your feedback about `gh`. If you spot bugs or have features that you'd really like to see in `gh`, please open an [issue][] and check out the [contributing page][]. ## Usage @@ -23,14 +23,14 @@ We love to hear feedback about `gh`. If you spot bugs or have features that you' ## Documentation -Read the [official docs](https://cli.github.com/manual/) for more information. +Read the [official docs][] for more information. ## Comparison with hub For many years, [hub][] was the unofficial GitHub CLI tool. `gh` is a new project that helps us explore what an official GitHub CLI tool can look like with a fundamentally different design. While both tools bring GitHub to the terminal, `hub` behaves as a proxy to `git`, and `gh` is a standalone -tool. Check out our [more detailed explanation](/docs/gh-vs-hub.md) to learn more. +tool. Check out our [more detailed explanation][] to learn more. @@ -135,7 +135,7 @@ Install and upgrade: ### Arch Linux -Arch Linux users can install from the [community repo](https://www.archlinux.org/packages/community/x86_64/github-cli/): +Arch Linux users can install from the [community repo][]: ```bash pacman -S github-cli @@ -155,11 +155,15 @@ Download packaged binaries from the [releases page][]. ### Build from source -See here on how to [build GitHub CLI from source](/docs/source.md). +See here on how to [build GitHub CLI from source][]. -[docs]: https://cli.github.com/manual +[official docs]: https://cli.github.com/manual [scoop]: https://scoop.sh [Chocolatey]: https://chocolatey.org [releases page]: https://github.com/cli/cli/releases/latest [hub]: https://github.com/github/hub [contributing page]: https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md +[issue]: https://github.com/cli/cli/issues/new/choose +[more detailed explanation]: /docs/gh-vs-hub.md +[community repo]: https://www.archlinux.org/packages/community/x86_64/github-cli/ +[build GitHub CLI from source]: /docs/source.md From 022d29ce796331b96650411236a0083b4d71616b Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 1 Sep 2020 09:40:27 +0200 Subject: [PATCH 3/9] Further cleanup up README links and update contributing doc --- .github/CONTRIBUTING.md | 1 + README.md | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e610380e9..573da443b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -10,6 +10,7 @@ We accept pull requests for bug fixes and features where we've discussed the app Please do: +* check existing issues to verify that the bug or feature request has not already been submitted * open an issue if things aren't working as expected * open an issue to propose a significant change * open a pull request to fix a bug diff --git a/README.md b/README.md index 3a1099679..01f18ab74 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ While in beta, GitHub CLI is available for repos hosted on GitHub.com only. It c ## We want your feedback -We'd love to hear your feedback about `gh`. If you spot bugs or have features that you'd really like to see in `gh`, please open an [issue][] and check out the [contributing page][]. +We'd love to hear your feedback about `gh`. If you spot bugs or have features that you'd really like to see in `gh`, please check out the [contributing page][]. ## Usage @@ -30,7 +30,7 @@ Read the [official docs][] for more information. For many years, [hub][] was the unofficial GitHub CLI tool. `gh` is a new project that helps us explore what an official GitHub CLI tool can look like with a fundamentally different design. While both tools bring GitHub to the terminal, `hub` behaves as a proxy to `git`, and `gh` is a standalone -tool. Check out our [more detailed explanation][] to learn more. +tool. Check out our [more detailed explanation][gh-vs-hub] to learn more. @@ -135,7 +135,7 @@ Install and upgrade: ### Arch Linux -Arch Linux users can install from the [community repo][]: +Arch Linux users can install from the [community repo][arch linux repo]: ```bash pacman -S github-cli @@ -155,7 +155,7 @@ Download packaged binaries from the [releases page][]. ### Build from source -See here on how to [build GitHub CLI from source][]. +See here on how to [build GitHub CLI from source][build from source]. [official docs]: https://cli.github.com/manual [scoop]: https://scoop.sh @@ -163,7 +163,6 @@ See here on how to [build GitHub CLI from source][]. [releases page]: https://github.com/cli/cli/releases/latest [hub]: https://github.com/github/hub [contributing page]: https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md -[issue]: https://github.com/cli/cli/issues/new/choose -[more detailed explanation]: /docs/gh-vs-hub.md -[community repo]: https://www.archlinux.org/packages/community/x86_64/github-cli/ -[build GitHub CLI from source]: /docs/source.md +[gh-vs-hub]: /docs/gh-vs-hub.md +[arch linux repo]: https://www.archlinux.org/packages/community/x86_64/github-cli +[build from source]: /docs/source.md From 35e739dfbd5abc6d328990b827ea5706d91b0d69 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 1 Sep 2020 10:25:16 +0200 Subject: [PATCH 4/9] Link to bugs and feature requests --- .github/CONTRIBUTING.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 573da443b..a22a9ffa3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -3,6 +3,8 @@ [legal]: https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license [license]: ../LICENSE [code-of-conduct]: CODE-OF-CONDUCT.md +[bug issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3Abug +[feature request issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3A+label%3Aenhancement Hi! Thanks for your interest in contributing to the GitHub CLI! @@ -10,7 +12,7 @@ We accept pull requests for bug fixes and features where we've discussed the app Please do: -* check existing issues to verify that the bug or feature request has not already been submitted +* check existing issues to verify that the [bug][bug issues] or [feature request][feature request issues] has not already been submitted * open an issue if things aren't working as expected * open an issue to propose a significant change * open a pull request to fix a bug From b4956006beeb8fc553d09099c18dc256225aa056 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 1 Sep 2020 15:52:58 +0200 Subject: [PATCH 5/9] Fix up feature request issues url --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a22a9ffa3..8a1dc4849 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -4,7 +4,7 @@ [license]: ../LICENSE [code-of-conduct]: CODE-OF-CONDUCT.md [bug issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3Abug -[feature request issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3A+label%3Aenhancement +[feature request issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement Hi! Thanks for your interest in contributing to the GitHub CLI! From 1f86e7cd04955b3b635934620ff77c958db4244d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 2 Sep 2020 20:59:11 +0200 Subject: [PATCH 6/9] Fix display width of common punctuation characters These characters get classified as "East Asian Mixed" by Go's `text/width` package, and thus assumed that their printed version occupies a width of 2 characters, whereas they each only occupy one. I'm not sure why they are classified as East Asian, but I did not have the energy to dive into Go's Unicode tables, so here is a workaround based on an exclusion list. --- pkg/text/truncate.go | 17 ++++++++++ pkg/text/truncate_test.go | 70 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/pkg/text/truncate.go b/pkg/text/truncate.go index f0d8abe62..78cd05da2 100644 --- a/pkg/text/truncate.go +++ b/pkg/text/truncate.go @@ -53,7 +53,24 @@ func Truncate(max int, s string) string { return res } +var runeDisplayWidthOverrides = map[rune]int{ + '“': 1, + '”': 1, + '‘': 1, + '’': 1, + '–': 1, // en dash + '—': 1, // em dash + '→': 1, + '…': 1, + '•': 1, // bullet + '·': 1, // middle dot +} + func runeDisplayWidth(r rune) int { + if w, ok := runeDisplayWidthOverrides[r]; ok { + return w + } + switch width.LookupRune(r).Kind() { case width.EastAsianWide, width.EastAsianAmbiguous, width.EastAsianFullwidth: return 2 diff --git a/pkg/text/truncate_test.go b/pkg/text/truncate_test.go index dbc0ec060..85a399e80 100644 --- a/pkg/text/truncate_test.go +++ b/pkg/text/truncate_test.go @@ -1,6 +1,8 @@ package text -import "testing" +import ( + "testing" +) func TestTruncate(t *testing.T) { type args struct { @@ -69,3 +71,69 @@ func TestTruncate(t *testing.T) { }) } } + +func TestDisplayWidth(t *testing.T) { + tests := []struct { + name string + text string + want int + }{ + { + name: "check mark", + text: `✓`, + want: 1, + }, + { + name: "bullet icon", + text: `•`, + want: 1, + }, + { + name: "middle dot", + text: `·`, + want: 1, + }, + { + name: "ellipsis", + text: `…`, + want: 1, + }, + { + name: "right arrow", + text: `→`, + want: 1, + }, + { + name: "smart double quotes", + text: `“”`, + want: 2, + }, + { + name: "smart single quotes", + text: `‘’`, + want: 2, + }, + { + name: "em dash", + text: `—`, + want: 1, + }, + { + name: "en dash", + text: `–`, + want: 1, + }, + { + name: "emoji", + text: `👍`, + want: 2, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DisplayWidth(tt.text); got != tt.want { + t.Errorf("DisplayWidth() = %v, want %v", got, tt.want) + } + }) + } +} From b93c8965612745ca57b302b55452eccb322a3886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 2 Sep 2020 21:01:39 +0200 Subject: [PATCH 7/9] Upgrade `text/width` package --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7f3b3a628..5f429ac99 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.5.1 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - golang.org/x/text v0.3.2 + golang.org/x/text v0.3.3 gopkg.in/yaml.v2 v2.2.8 // indirect gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 ) diff --git a/go.sum b/go.sum index 00b851929..0fb6e78da 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,8 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HX golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 995828abf813b66d3a1f36e48dcdc26aef471112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 4 Sep 2020 17:42:57 +0200 Subject: [PATCH 8/9] Avoid setting a default `Accept` header in `hub api` Due to our HTTP client default behavior, an `Accept` header is added to all API requests. This is fine for all commands except `gh api`, where the user should ideally have fine-grained control over most aspects of HTTP requests and where there should be little to no defaults in general. --- pkg/cmd/factory/default.go | 3 +-- pkg/cmd/factory/http.go | 2 +- pkg/cmd/root/root.go | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index 6b46f74d0..f667acb6b 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -46,8 +46,7 @@ func New(appVersion string) *cmdutil.Factory { return nil, err } - // TODO: avoid setting Accept header for `api` command - return httpClient(io, cfg, appVersion, true), nil + return NewHTTPClient(io, cfg, appVersion, true), nil }, BaseRepo: func() (ghrepo.Interface, error) { remotes, err := remotesFunc() diff --git a/pkg/cmd/factory/http.go b/pkg/cmd/factory/http.go index 1cccfda9c..f87bfa423 100644 --- a/pkg/cmd/factory/http.go +++ b/pkg/cmd/factory/http.go @@ -13,7 +13,7 @@ import ( ) // generic authenticated HTTP client for commands -func httpClient(io *iostreams.IOStreams, cfg config.Config, appVersion string, setAccept bool) *http.Client { +func NewHTTPClient(io *iostreams.IOStreams, cfg config.Config, appVersion string, setAccept bool) *http.Client { var opts []api.ClientOption if verbose := os.Getenv("DEBUG"); verbose != "" { logTraffic := strings.Contains(verbose, "api") diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 252636e52..986976121 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -2,6 +2,7 @@ package root import ( "fmt" + "net/http" "regexp" "strings" @@ -13,6 +14,7 @@ import ( apiCmd "github.com/cli/cli/pkg/cmd/api" authCmd "github.com/cli/cli/pkg/cmd/auth" configCmd "github.com/cli/cli/pkg/cmd/config" + "github.com/cli/cli/pkg/cmd/factory" gistCmd "github.com/cli/cli/pkg/cmd/gist" issueCmd "github.com/cli/cli/pkg/cmd/issue" prCmd "github.com/cli/cli/pkg/cmd/pr" @@ -102,13 +104,24 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command { // CHILD COMMANDS cmd.AddCommand(aliasCmd.NewCmdAlias(f)) - cmd.AddCommand(apiCmd.NewCmdApi(f, nil)) cmd.AddCommand(authCmd.NewCmdAuth(f)) cmd.AddCommand(configCmd.NewCmdConfig(f)) cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil)) cmd.AddCommand(gistCmd.NewCmdGist(f)) cmd.AddCommand(NewCmdCompletion(f.IOStreams)) + // the `api` command should not inherit any extra HTTP headers + bareHTTPCmdFactory := *f + bareHTTPCmdFactory.HttpClient = func() (*http.Client, error) { + cfg, err := bareHTTPCmdFactory.Config() + if err != nil { + return nil, err + } + return factory.NewHTTPClient(bareHTTPCmdFactory.IOStreams, cfg, version, false), nil + } + + cmd.AddCommand(apiCmd.NewCmdApi(&bareHTTPCmdFactory, nil)) + // below here at the commands that require the "intelligent" BaseRepo resolver repoResolvingCmdFactory := *f repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f) From d83c99f87f44eccd44442f6230fd71631f0f5e97 Mon Sep 17 00:00:00 2001 From: Brian 'bdougie' Douglas Date: Fri, 28 Aug 2020 08:36:52 -0700 Subject: [PATCH 9/9] filter by contributor type --- pkg/cmd/repo/credits/credits.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/cmd/repo/credits/credits.go b/pkg/cmd/repo/credits/credits.go index 40aff56d1..c69ce1f3e 100644 --- a/pkg/cmd/repo/credits/credits.go +++ b/pkg/cmd/repo/credits/credits.go @@ -135,6 +135,7 @@ func creditsRun(opts *CreditsOptions) error { type Contributor struct { Login string + Type string } type Result []Contributor @@ -161,6 +162,10 @@ func creditsRun(opts *CreditsOptions) error { logins := []string{} for x, c := range result { + if c.Type != "User" { + continue + } + if isTTY && !static { logins = append(logins, getColor(x)(c.Login)) } else {