diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e610380e9..8a1dc4849 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%3Aenhancement Hi! Thanks for your interest in contributing to the GitHub CLI! @@ -10,6 +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][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 diff --git a/README.md b/README.md index 4fd0311e0..01f18ab74 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 +## We want your 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'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 @@ -27,14 +23,14 @@ And if you spot bugs or have features that you'd really like to see in `gh`, ple ## 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][gh-vs-hub] to learn more. @@ -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 @@ -139,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][arch linux repo]: ```bash pacman -S github-cli @@ -159,11 +155,14 @@ 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][build 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 +[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 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= 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 9daf6d36b..d36bffdb2 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/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 { diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 947ba73a8..de14c681b 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" @@ -104,13 +106,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) 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) + } + }) + } +}