X Tutup
Skip to content

Commit feadf68

Browse files
committed
Merge remote-tracking branch 'origin' into ghe-auth-tweaks
2 parents 2bb5e05 + 9109b68 commit feadf68

File tree

10 files changed

+124
-20
lines changed

10 files changed

+124
-20
lines changed

.github/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
[legal]: https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license
44
[license]: ../LICENSE
55
[code-of-conduct]: CODE-OF-CONDUCT.md
6+
[bug issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3Abug
7+
[feature request issues]: https://github.com/cli/cli/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement
68

79
Hi! Thanks for your interest in contributing to the GitHub CLI!
810

911
We accept pull requests for bug fixes and features where we've discussed the approach in an issue and given the go-ahead for a community member to work on it. We'd also love to hear about ideas for new features as issues.
1012

1113
Please do:
1214

15+
* check existing issues to verify that the [bug][bug issues] or [feature request][feature request issues] has not already been submitted
1316
* open an issue if things aren't working as expected
1417
* open an issue to propose a significant change
1518
* open a pull request to fix a bug

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ the terminal next to where you are already working with `git` and your code.
99

1010
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.
1111

12-
## We need your feedback
12+
## We want your feedback
1313

14-
GitHub CLI is currently in its early development stages, and we're hoping to get feedback from people using it.
15-
16-
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
17-
18-
And if you spot bugs or have features that you'd really like to see in `gh`, please check out the [contributing page][]
14+
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][].
1915

2016
## Usage
2117

@@ -27,14 +23,14 @@ And if you spot bugs or have features that you'd really like to see in `gh`, ple
2723

2824
## Documentation
2925

30-
Read the [official docs](https://cli.github.com/manual/) for more information.
26+
Read the [official docs][] for more information.
3127

3228
## Comparison with hub
3329

3430
For many years, [hub][] was the unofficial GitHub CLI tool. `gh` is a new project that helps us explore
3531
what an official GitHub CLI tool can look like with a fundamentally different design. While both
3632
tools bring GitHub to the terminal, `hub` behaves as a proxy to `git`, and `gh` is a standalone
37-
tool. Check out our [more detailed explanation](/docs/gh-vs-hub.md) to learn more.
33+
tool. Check out our [more detailed explanation][gh-vs-hub] to learn more.
3834

3935

4036
<!-- this anchor is linked to from elsewhere, so avoid renaming it -->
@@ -128,7 +124,7 @@ Install and upgrade:
128124
Install and upgrade:
129125

130126
1. Download the `.rpm` file from the [releases page][];
131-
2. Install the downloaded file: `sudo yum localinstall gh_*_linux_amd64.rpm`
127+
2. Install the downloaded file: `sudo yum localinstall gh_*_linux_amd64.rpm`
132128

133129
### openSUSE/SUSE Linux
134130

@@ -139,7 +135,7 @@ Install and upgrade:
139135

140136
### Arch Linux
141137

142-
Arch Linux users can install from the [community repo](https://www.archlinux.org/packages/community/x86_64/github-cli/):
138+
Arch Linux users can install from the [community repo][arch linux repo]:
143139

144140
```bash
145141
pacman -S github-cli
@@ -159,11 +155,14 @@ Download packaged binaries from the [releases page][].
159155

160156
### Build from source
161157

162-
See here on how to [build GitHub CLI from source](/docs/source.md).
158+
See here on how to [build GitHub CLI from source][build from source].
163159

164-
[docs]: https://cli.github.com/manual
160+
[official docs]: https://cli.github.com/manual
165161
[scoop]: https://scoop.sh
166162
[Chocolatey]: https://chocolatey.org
167163
[releases page]: https://github.com/cli/cli/releases/latest
168164
[hub]: https://github.com/github/hub
169165
[contributing page]: https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md
166+
[gh-vs-hub]: /docs/gh-vs-hub.md
167+
[arch linux repo]: https://www.archlinux.org/packages/community/x86_64/github-cli
168+
[build from source]: /docs/source.md

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/spf13/pflag v1.0.5
2323
github.com/stretchr/testify v1.5.1
2424
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
25-
golang.org/x/text v0.3.2
25+
golang.org/x/text v0.3.3
2626
gopkg.in/yaml.v2 v2.2.8 // indirect
2727
gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86
2828
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HX
227227
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
228228
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
229229
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
230-
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
231-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
230+
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
231+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
232232
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
233233
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
234234
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

pkg/cmd/factory/default.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ func New(appVersion string) *cmdutil.Factory {
4646
return nil, err
4747
}
4848

49-
// TODO: avoid setting Accept header for `api` command
50-
return httpClient(io, cfg, appVersion, true), nil
49+
return NewHTTPClient(io, cfg, appVersion, true), nil
5150
},
5251
BaseRepo: func() (ghrepo.Interface, error) {
5352
remotes, err := remotesFunc()

pkg/cmd/factory/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// generic authenticated HTTP client for commands
16-
func httpClient(io *iostreams.IOStreams, cfg config.Config, appVersion string, setAccept bool) *http.Client {
16+
func NewHTTPClient(io *iostreams.IOStreams, cfg config.Config, appVersion string, setAccept bool) *http.Client {
1717
var opts []api.ClientOption
1818
if verbose := os.Getenv("DEBUG"); verbose != "" {
1919
logTraffic := strings.Contains(verbose, "api")

pkg/cmd/repo/credits/credits.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func creditsRun(opts *CreditsOptions) error {
135135

136136
type Contributor struct {
137137
Login string
138+
Type string
138139
}
139140

140141
type Result []Contributor
@@ -161,6 +162,10 @@ func creditsRun(opts *CreditsOptions) error {
161162

162163
logins := []string{}
163164
for x, c := range result {
165+
if c.Type != "User" {
166+
continue
167+
}
168+
164169
if isTTY && !static {
165170
logins = append(logins, getColor(x)(c.Login))
166171
} else {

pkg/cmd/root/root.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package root
22

33
import (
44
"fmt"
5+
"net/http"
56
"regexp"
67
"strings"
78

@@ -13,6 +14,7 @@ import (
1314
apiCmd "github.com/cli/cli/pkg/cmd/api"
1415
authCmd "github.com/cli/cli/pkg/cmd/auth"
1516
configCmd "github.com/cli/cli/pkg/cmd/config"
17+
"github.com/cli/cli/pkg/cmd/factory"
1618
gistCmd "github.com/cli/cli/pkg/cmd/gist"
1719
issueCmd "github.com/cli/cli/pkg/cmd/issue"
1820
prCmd "github.com/cli/cli/pkg/cmd/pr"
@@ -104,13 +106,24 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
104106
// CHILD COMMANDS
105107

106108
cmd.AddCommand(aliasCmd.NewCmdAlias(f))
107-
cmd.AddCommand(apiCmd.NewCmdApi(f, nil))
108109
cmd.AddCommand(authCmd.NewCmdAuth(f))
109110
cmd.AddCommand(configCmd.NewCmdConfig(f))
110111
cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil))
111112
cmd.AddCommand(gistCmd.NewCmdGist(f))
112113
cmd.AddCommand(NewCmdCompletion(f.IOStreams))
113114

115+
// the `api` command should not inherit any extra HTTP headers
116+
bareHTTPCmdFactory := *f
117+
bareHTTPCmdFactory.HttpClient = func() (*http.Client, error) {
118+
cfg, err := bareHTTPCmdFactory.Config()
119+
if err != nil {
120+
return nil, err
121+
}
122+
return factory.NewHTTPClient(bareHTTPCmdFactory.IOStreams, cfg, version, false), nil
123+
}
124+
125+
cmd.AddCommand(apiCmd.NewCmdApi(&bareHTTPCmdFactory, nil))
126+
114127
// below here at the commands that require the "intelligent" BaseRepo resolver
115128
repoResolvingCmdFactory := *f
116129
repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f)

pkg/text/truncate.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,24 @@ func Truncate(max int, s string) string {
5353
return res
5454
}
5555

56+
var runeDisplayWidthOverrides = map[rune]int{
57+
'“': 1,
58+
'”': 1,
59+
'‘': 1,
60+
'’': 1,
61+
'–': 1, // en dash
62+
'—': 1, // em dash
63+
'→': 1,
64+
'…': 1,
65+
'•': 1, // bullet
66+
'·': 1, // middle dot
67+
}
68+
5669
func runeDisplayWidth(r rune) int {
70+
if w, ok := runeDisplayWidthOverrides[r]; ok {
71+
return w
72+
}
73+
5774
switch width.LookupRune(r).Kind() {
5875
case width.EastAsianWide, width.EastAsianAmbiguous, width.EastAsianFullwidth:
5976
return 2

pkg/text/truncate_test.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package text
22

3-
import "testing"
3+
import (
4+
"testing"
5+
)
46

57
func TestTruncate(t *testing.T) {
68
type args struct {
@@ -69,3 +71,69 @@ func TestTruncate(t *testing.T) {
6971
})
7072
}
7173
}
74+
75+
func TestDisplayWidth(t *testing.T) {
76+
tests := []struct {
77+
name string
78+
text string
79+
want int
80+
}{
81+
{
82+
name: "check mark",
83+
text: `✓`,
84+
want: 1,
85+
},
86+
{
87+
name: "bullet icon",
88+
text: `•`,
89+
want: 1,
90+
},
91+
{
92+
name: "middle dot",
93+
text: `·`,
94+
want: 1,
95+
},
96+
{
97+
name: "ellipsis",
98+
text: `…`,
99+
want: 1,
100+
},
101+
{
102+
name: "right arrow",
103+
text: `→`,
104+
want: 1,
105+
},
106+
{
107+
name: "smart double quotes",
108+
text: `“”`,
109+
want: 2,
110+
},
111+
{
112+
name: "smart single quotes",
113+
text: `‘’`,
114+
want: 2,
115+
},
116+
{
117+
name: "em dash",
118+
text: `—`,
119+
want: 1,
120+
},
121+
{
122+
name: "en dash",
123+
text: `–`,
124+
want: 1,
125+
},
126+
{
127+
name: "emoji",
128+
text: `👍`,
129+
want: 2,
130+
},
131+
}
132+
for _, tt := range tests {
133+
t.Run(tt.name, func(t *testing.T) {
134+
if got := DisplayWidth(tt.text); got != tt.want {
135+
t.Errorf("DisplayWidth() = %v, want %v", got, tt.want)
136+
}
137+
})
138+
}
139+
}

0 commit comments

Comments
 (0)
X Tutup