X Tutup
Skip to content

Commit e19ea12

Browse files
committed
Merge remote-tracking branch 'origin' into blank-issue
2 parents 8bfc935 + 217998a commit e19ea12

Some content is hidden

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

71 files changed

+3852
-807
lines changed

.github/PULL_REQUEST_TEMPLATE/bug_fix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ about: Fix a bug in GitHub CLI
66

77
<!--
88
Please make sure you read our contributing guidelines at
9-
https://github.com/cli/cli/blob/master/.github/CONTRIBUTING.md
9+
https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md
1010
before opening opening a pull request. Thanks!
1111
-->
1212

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
steps:
1212
- name: Set up Go 1.14
13-
uses: actions/setup-go@v2-beta
13+
uses: actions/setup-go@v2
1414
with:
1515
go-version: 1.14
1616

.github/workflows/lint.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ on:
55
- "**.go"
66
- go.mod
77
- go.sum
8+
pull_request:
9+
paths:
10+
- "**.go"
11+
- go.mod
12+
- go.sum
813

914
jobs:
1015
lint:
1116
runs-on: ubuntu-latest
1217

1318
steps:
1419
- name: Set up Go 1.14
15-
uses: actions/setup-go@v2-beta
20+
uses: actions/setup-go@v2
1621
with:
1722
go-version: 1.14
1823

.github/workflows/releases.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Checkout
1313
uses: actions/checkout@v2
1414
- name: Set up Go 1.14
15-
uses: actions/setup-go@v2-beta
15+
uses: actions/setup-go@v2
1616
with:
1717
go-version: 1.14
1818
- name: Generate changelog
@@ -44,6 +44,11 @@ jobs:
4444
token: ${{secrets.SITE_GITHUB_TOKEN}}
4545
- name: Publish documentation site
4646
if: "!contains(github.ref, '-')" # skip prereleases
47+
env:
48+
GIT_COMMITTER_NAME: cli automation
49+
GIT_AUTHOR_NAME: cli automation
50+
GIT_COMMITTER_EMAIL: noreply@github.com
51+
GIT_AUTHOR_EMAIL: noreply@github.com
4752
run: make site-publish
4853
- name: Move project cards
4954
if: "!contains(github.ref, '-')" # skip prereleases

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/bin
2+
/share/man/man1
23
/gh-cli
34
.envrc
45
/dist

.goreleaser.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ release:
66
before:
77
hooks:
88
- go mod tidy
9+
- make manpages
910

1011
builds:
1112
- <<: &build_defaults
@@ -17,10 +18,12 @@ builds:
1718
id: macos
1819
goos: [darwin]
1920
goarch: [amd64]
21+
2022
- <<: *build_defaults
2123
id: linux
2224
goos: [linux]
2325
goarch: [386, amd64, arm64]
26+
2427
- <<: *build_defaults
2528
id: windows
2629
goos: [windows]
@@ -35,11 +38,16 @@ archives:
3538
replacements:
3639
darwin: macOS
3740
format: tar.gz
41+
files:
42+
- LICENSE
43+
- ./share/man/man1/gh*.1
3844
- id: windows
3945
builds: [windows]
4046
<<: *archive_defaults
4147
wrap_in_directory: false
4248
format: zip
49+
files:
50+
- LICENSE
4351

4452
brews:
4553
- name: gh
@@ -57,8 +65,9 @@ brews:
5765
depends_on "go"
5866
end
5967
install: |
60-
system "make" if build.head?
68+
system "make", "bin/gh", "manpages" if build.head?
6169
bin.install "bin/gh"
70+
man1.install Dir["./share/man/man1/gh*.1"]
6271
(bash_completion/"gh.sh").write `#{bin}/gh completion -s bash`
6372
(zsh_completion/"_gh").write `#{bin}/gh completion -s zsh`
6473
(fish_completion/"gh.fish").write `#{bin}/gh completion -s fish`
@@ -76,6 +85,8 @@ nfpms:
7685
formats:
7786
- deb
7887
- rpm
88+
files:
89+
"./share/man/man1/gh*.1": "/usr/share/man/man1"
7990

8091
scoop:
8192
bucket:

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ endif
1111
LDFLAGS := -X github.com/cli/cli/command.Version=$(GH_VERSION) $(LDFLAGS)
1212
LDFLAGS := -X github.com/cli/cli/command.BuildDate=$(BUILD_DATE) $(LDFLAGS)
1313
ifdef GH_OAUTH_CLIENT_SECRET
14-
LDFLAGS := -X github.com/cli/cli/context.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(LDFLAGS)
15-
LDFLAGS := -X github.com/cli/cli/context.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(LDFLAGS)
14+
LDFLAGS := -X github.com/cli/cli/internal/config.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(LDFLAGS)
15+
LDFLAGS := -X github.com/cli/cli/internal/config.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(LDFLAGS)
1616
endif
1717

1818
bin/gh: $(BUILD_FILES)
@@ -28,7 +28,7 @@ site:
2828
site-docs: site
2929
git -C site pull
3030
git -C site rm 'manual/gh*.md' 2>/dev/null || true
31-
go run ./cmd/gen-docs site/manual
31+
go run ./cmd/gen-docs --website --doc-path site/manual
3232
for f in site/manual/gh*.md; do sed -i.bak -e '/^### SEE ALSO/,$$d' "$$f"; done
3333
rm -f site/manual/*.bak
3434
git -C site add 'manual/gh*.md'
@@ -44,3 +44,8 @@ endif
4444
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
4545
git -C site push
4646
.PHONY: site-publish
47+
48+
49+
.PHONY: manpages
50+
manpages:
51+
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
`gh` is GitHub on the command line, and it's now available in beta. It brings pull requests, issues, and other GitHub concepts to
44
the terminal next to where you are already working with `git` and your code.
55

6-
![screenshot](https://user-images.githubusercontent.com/98482/73286699-9f922180-41bd-11ea-87c9-60a2d31fd0ac.png)
6+
![screenshot of gh pr status](https://user-images.githubusercontent.com/98482/84171218-327e7a80-aa40-11ea-8cd1-5177fc2d0e72.png)
77

88
## Availability
99

@@ -136,4 +136,4 @@ Install a prebuilt binary from the [releases page][]
136136
[Chocolatey]: https://chocolatey.org
137137
[releases page]: https://github.com/cli/cli/releases/latest
138138
[hub]: https://github.com/github/hub
139-
[contributing page]: https://github.com/cli/cli/blob/master/.github/CONTRIBUTING.md
139+
[contributing page]: https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md

api/client.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ import (
1616
// ClientOption represents an argument to NewClient
1717
type ClientOption = func(http.RoundTripper) http.RoundTripper
1818

19-
// NewClient initializes a Client
20-
func NewClient(opts ...ClientOption) *Client {
19+
// NewHTTPClient initializes an http.Client
20+
func NewHTTPClient(opts ...ClientOption) *http.Client {
2121
tr := http.DefaultTransport
2222
for _, opt := range opts {
2323
tr = opt(tr)
2424
}
25-
http := &http.Client{Transport: tr}
26-
client := &Client{http: http}
25+
return &http.Client{Transport: tr}
26+
}
27+
28+
// NewClient initializes a Client
29+
func NewClient(opts ...ClientOption) *Client {
30+
client := &Client{http: NewHTTPClient(opts...)}
2731
return client
2832
}
2933

@@ -145,6 +149,45 @@ func (gr GraphQLErrorResponse) Error() string {
145149
return fmt.Sprintf("graphql error: '%s'", strings.Join(errorMessages, ", "))
146150
}
147151

152+
// Returns whether or not scopes are present, appID, and error
153+
func (c Client) HasScopes(wantedScopes ...string) (bool, string, error) {
154+
url := "https://api.github.com/user"
155+
req, err := http.NewRequest("GET", url, nil)
156+
if err != nil {
157+
return false, "", err
158+
}
159+
160+
req.Header.Set("Content-Type", "application/json; charset=utf-8")
161+
162+
res, err := c.http.Do(req)
163+
if err != nil {
164+
return false, "", err
165+
}
166+
defer res.Body.Close()
167+
168+
if res.StatusCode != 200 {
169+
return false, "", handleHTTPError(res)
170+
}
171+
172+
appID := res.Header.Get("X-Oauth-Client-Id")
173+
hasScopes := strings.Split(res.Header.Get("X-Oauth-Scopes"), ",")
174+
175+
found := 0
176+
for _, s := range hasScopes {
177+
for _, w := range wantedScopes {
178+
if w == strings.TrimSpace(s) {
179+
found++
180+
}
181+
}
182+
}
183+
184+
if found == len(wantedScopes) {
185+
return true, appID, nil
186+
}
187+
188+
return false, appID, nil
189+
}
190+
148191
// GraphQL performs a GraphQL request and parses the response
149192
func (c Client) GraphQL(query string, variables map[string]interface{}, data interface{}) error {
150193
url := "https://api.github.com/graphql"

api/queries_gist.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package api
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
)
7+
8+
// Gist represents a GitHub's gist.
9+
type Gist struct {
10+
Description string `json:"description,omitempty"`
11+
Public bool `json:"public,omitempty"`
12+
Files map[GistFilename]GistFile `json:"files,omitempty"`
13+
HTMLURL string `json:"html_url,omitempty"`
14+
}
15+
16+
type GistFilename string
17+
18+
type GistFile struct {
19+
Content string `json:"content,omitempty"`
20+
}
21+
22+
// Create a gist for authenticated user.
23+
//
24+
// GitHub API docs: https://developer.github.com/v3/gists/#create-a-gist
25+
func GistCreate(client *Client, description string, public bool, files map[string]string) (*Gist, error) {
26+
gistFiles := map[GistFilename]GistFile{}
27+
28+
for filename, content := range files {
29+
gistFiles[GistFilename(filename)] = GistFile{content}
30+
}
31+
32+
path := "gists"
33+
body := &Gist{
34+
Description: description,
35+
Public: public,
36+
Files: gistFiles,
37+
}
38+
result := Gist{}
39+
40+
requestByte, err := json.Marshal(body)
41+
if err != nil {
42+
return nil, err
43+
}
44+
requestBody := bytes.NewReader(requestByte)
45+
46+
err = client.REST("POST", path, requestBody, &result)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
return &result, nil
52+
}

0 commit comments

Comments
 (0)
X Tutup