X Tutup
Skip to content

Commit 2753f6f

Browse files
committed
Merge remote-tracking branch 'origin/trunk' into fix-milestone
2 parents e12c35c + 0cc5948 commit 2753f6f

File tree

104 files changed

+5632
-3817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+5632
-3817
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010

1111
steps:
12-
- name: Set up Go 1.14
12+
- name: Set up Go 1.15
1313
uses: actions/setup-go@v2
1414
with:
15-
go-version: 1.14
15+
go-version: 1.15
1616

1717
- name: Check out code
1818
uses: actions/checkout@v2

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- name: Set up Go 1.14
19+
- name: Set up Go 1.15
2020
uses: actions/setup-go@v2
2121
with:
22-
go-version: 1.14
22+
go-version: 1.15
2323

2424
- name: Check out code
2525
uses: actions/checkout@v2

.github/workflows/releases.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v2
14-
- name: Set up Go 1.14
14+
- name: Set up Go 1.15
1515
uses: actions/setup-go@v2
1616
with:
17-
go-version: 1.14
17+
go-version: 1.15
1818
- name: Generate changelog
1919
run: |
2020
echo ::set-env name=GORELEASER_CURRENT_TAG::${GITHUB_REF#refs/tags/}

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,43 +113,53 @@ MSI installers are available for download on the [releases page][].
113113

114114
Install and upgrade:
115115

116-
1. Download the `.deb` file from the [releases page][]
117-
2. `sudo apt install ./gh_*_linux_amd64.deb` install the downloaded file
116+
1. Download the `.deb` file from the [releases page][];
117+
2. Install the downloaded file: `sudo apt install ./gh_*_linux_amd64.deb`
118118

119119
### Fedora Linux
120120

121121
Install and upgrade:
122122

123-
1. Download the `.rpm` file from the [releases page][]
124-
2. `sudo dnf install gh_*_linux_amd64.rpm` install the downloaded file
123+
1. Download the `.rpm` file from the [releases page][];
124+
2. Install the downloaded file: `sudo dnf install gh_*_linux_amd64.rpm`
125125

126126
### Centos Linux
127127

128128
Install and upgrade:
129129

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

133133
### openSUSE/SUSE Linux
134134

135135
Install and upgrade:
136136

137-
1. Download the `.rpm` file from the [releases page][]
138-
2. `sudo zypper in gh_*_linux_amd64.rpm` install the downloaded file
137+
1. Download the `.rpm` file from the [releases page][];
138+
2. Install the downloaded file: `sudo zypper in gh_*_linux_amd64.rpm`
139139

140140
### Arch Linux
141141

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

144144
```bash
145145
pacman -S github-cli
146146
```
147147

148+
### Android
149+
150+
Android users can install via Termux:
151+
152+
```bash
153+
pkg install gh
154+
```
155+
148156
### Other platforms
149157

150-
Install a prebuilt binary from the [releases page][]
158+
Download packaged binaries from the [releases page][].
159+
160+
### Build from source
151161

152-
### [Build from source](/docs/source.md)
162+
See here on how to [build GitHub CLI from source](/docs/source.md).
153163

154164
[docs]: https://cli.github.com/manual
155165
[scoop]: https://scoop.sh

api/client.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,22 @@ func (err HTTPError) Error() string {
196196
return fmt.Sprintf("HTTP %d (%s)", err.StatusCode, err.RequestURL)
197197
}
198198

199-
func (c Client) HasMinimumScopes(hostname string) (bool, error) {
199+
type MissingScopesError struct {
200+
error
201+
}
202+
203+
func (c Client) HasMinimumScopes(hostname string) error {
200204
apiEndpoint := ghinstance.RESTPrefix(hostname)
201205

202206
req, err := http.NewRequest("GET", apiEndpoint, nil)
203207
if err != nil {
204-
return false, err
208+
return err
205209
}
206210

207211
req.Header.Set("Content-Type", "application/json; charset=utf-8")
208212
res, err := c.http.Do(req)
209213
if err != nil {
210-
return false, err
214+
return err
211215
}
212216

213217
defer func() {
@@ -218,7 +222,7 @@ func (c Client) HasMinimumScopes(hostname string) (bool, error) {
218222
}()
219223

220224
if res.StatusCode != 200 {
221-
return false, handleHTTPError(res)
225+
return handleHTTPError(res)
222226
}
223227

224228
hasScopes := strings.Split(res.Header.Get("X-Oauth-Scopes"), ",")
@@ -243,11 +247,10 @@ func (c Client) HasMinimumScopes(hostname string) (bool, error) {
243247
}
244248

245249
if len(errorMsgs) > 0 {
246-
return false, errors.New(strings.Join(errorMsgs, ";"))
250+
return &MissingScopesError{error: errors.New(strings.Join(errorMsgs, ";"))}
247251
}
248252

249-
return true, nil
250-
253+
return nil
251254
}
252255

253256
// GraphQL performs a GraphQL request and parses the response

api/queries_pr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"net/http"
99
"strings"
1010

11-
"github.com/shurcooL/githubv4"
12-
11+
"github.com/cli/cli/internal/ghinstance"
1312
"github.com/cli/cli/internal/ghrepo"
13+
"github.com/shurcooL/githubv4"
1414
)
1515

1616
type PullRequestReviewState int
@@ -210,8 +210,8 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
210210
}
211211

212212
func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (io.ReadCloser, error) {
213-
url := fmt.Sprintf("https://api.github.com/repos/%s/pulls/%d",
214-
ghrepo.FullName(baseRepo), prNumber)
213+
url := fmt.Sprintf("%srepos/%s/pulls/%d",
214+
ghinstance.RESTPrefix(baseRepo.RepoHost()), ghrepo.FullName(baseRepo), prNumber)
215215
req, err := http.NewRequest("GET", url, nil)
216216
if err != nil {
217217
return nil, err

cmd/gen-docs/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/cli/cli/command"
8+
"github.com/cli/cli/pkg/cmd/root"
9+
"github.com/cli/cli/pkg/cmdutil"
10+
"github.com/cli/cli/pkg/iostreams"
911
"github.com/spf13/cobra/doc"
1012
"github.com/spf13/pflag"
1113
)
@@ -35,13 +37,16 @@ func main() {
3537
fatal("no dir set")
3638
}
3739

40+
io, _, _, _ := iostreams.Test()
41+
rootCmd := root.NewCmdRoot(&cmdutil.Factory{IOStreams: io}, "", "")
42+
3843
err := os.MkdirAll(*dir, 0755)
3944
if err != nil {
4045
fatal(err)
4146
}
4247

4348
if *website {
44-
err = doc.GenMarkdownTreeCustom(command.RootCmd, *dir, filePrepender, linkHandler)
49+
err = doc.GenMarkdownTreeCustom(rootCmd, *dir, filePrepender, linkHandler)
4550
if err != nil {
4651
fatal(err)
4752
}
@@ -54,7 +59,7 @@ func main() {
5459
Source: "", //source and manual are just put at the top of the manpage, before name
5560
Manual: "", //if source is an empty string, it's set to "Auto generated by spf13/cobra"
5661
}
57-
err = doc.GenManTree(command.RootCmd, header, *dir)
62+
err = doc.GenManTree(rootCmd, header, *dir)
5863
if err != nil {
5964
fatal(err)
6065
}

cmd/gh/main.go

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212

1313
"github.com/cli/cli/command"
1414
"github.com/cli/cli/internal/config"
15+
"github.com/cli/cli/internal/ghinstance"
16+
"github.com/cli/cli/internal/run"
17+
"github.com/cli/cli/pkg/cmd/alias/expand"
18+
"github.com/cli/cli/pkg/cmd/factory"
19+
"github.com/cli/cli/pkg/cmd/root"
1520
"github.com/cli/cli/pkg/cmdutil"
1621
"github.com/cli/cli/update"
1722
"github.com/cli/cli/utils"
@@ -31,25 +36,48 @@ func main() {
3136

3237
hasDebug := os.Getenv("DEBUG") != ""
3338

34-
stderr := utils.NewColorable(os.Stderr)
39+
if hostFromEnv := os.Getenv("GH_HOST"); hostFromEnv != "" {
40+
ghinstance.OverrideDefault(hostFromEnv)
41+
}
42+
43+
cmdFactory := factory.New(command.Version)
44+
stderr := cmdFactory.IOStreams.ErrOut
45+
rootCmd := root.NewCmdRoot(cmdFactory, command.Version, command.BuildDate)
3546

3647
expandedArgs := []string{}
3748
if len(os.Args) > 0 {
3849
expandedArgs = os.Args[1:]
3950
}
4051

41-
cmd, _, err := command.RootCmd.Traverse(expandedArgs)
42-
if err != nil || cmd == command.RootCmd {
52+
cmd, _, err := rootCmd.Traverse(expandedArgs)
53+
if err != nil || cmd == rootCmd {
4354
originalArgs := expandedArgs
4455
isShell := false
45-
expandedArgs, isShell, err = command.ExpandAlias(os.Args)
56+
57+
cfg, err := cmdFactory.Config()
58+
if err != nil {
59+
fmt.Fprintf(stderr, "failed to read configuration: %s\n", err)
60+
os.Exit(2)
61+
}
62+
63+
expandedArgs, isShell, err = expand.ExpandAlias(cfg, os.Args, nil)
4664
if err != nil {
4765
fmt.Fprintf(stderr, "failed to process aliases: %s\n", err)
4866
os.Exit(2)
4967
}
5068

69+
if hasDebug {
70+
fmt.Fprintf(stderr, "%v -> %v\n", originalArgs, expandedArgs)
71+
}
72+
5173
if isShell {
52-
err = command.ExecuteShellAlias(expandedArgs)
74+
externalCmd := exec.Command(expandedArgs[0], expandedArgs[1:]...)
75+
externalCmd.Stderr = os.Stderr
76+
externalCmd.Stdout = os.Stdout
77+
externalCmd.Stdin = os.Stdin
78+
preparedCmd := run.PrepareCmd(externalCmd)
79+
80+
err = preparedCmd.Run()
5381
if err != nil {
5482
if ee, ok := err.(*exec.ExitError); ok {
5583
os.Exit(ee.ExitCode())
@@ -61,19 +89,15 @@ func main() {
6189

6290
os.Exit(0)
6391
}
64-
65-
if hasDebug {
66-
fmt.Fprintf(stderr, "%v -> %v\n", originalArgs, expandedArgs)
67-
}
6892
}
6993

70-
command.RootCmd.SetArgs(expandedArgs)
94+
rootCmd.SetArgs(expandedArgs)
7195

72-
if cmd, err := command.RootCmd.ExecuteC(); err != nil {
73-
printError(os.Stderr, err, cmd, hasDebug)
96+
if cmd, err := rootCmd.ExecuteC(); err != nil {
97+
printError(stderr, err, cmd, hasDebug)
7498
os.Exit(1)
7599
}
76-
if command.HasFailed() {
100+
if root.HasFailed() {
77101
os.Exit(1)
78102
}
79103

@@ -85,7 +109,6 @@ func main() {
85109
ansi.Color(newRelease.Version, "cyan"),
86110
ansi.Color(newRelease.URL, "yellow"))
87111

88-
stderr := utils.NewColorable(os.Stderr)
89112
fmt.Fprintf(stderr, "\n\n%s\n\n", msg)
90113
}
91114
}

0 commit comments

Comments
 (0)
X Tutup