X Tutup
Skip to content

Commit 06cf2c9

Browse files
committed
Merge remote-tracking branch 'origin' into cmd-stub-new
2 parents 14b8047 + 4d28c79 commit 06cf2c9

Some content is hidden

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

79 files changed

+2933
-1206
lines changed

.github/CONTRIBUTING.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ Prerequisites:
2626
- Go 1.13+ for building the binary
2727
- Go 1.15+ for running the test suite
2828

29-
Build with: `make` or `go build -o bin/gh ./cmd/gh`
29+
Build with:
30+
* Unix-like systems: `make`
31+
* Windows: `go run script/build.go`
3032

31-
Run the new binary as: `./bin/gh`
33+
Run the new binary as:
34+
* Unix-like systems: `bin/gh`
35+
* Windows: `bin\gh`
3236

33-
Run tests with: `make test` or `go test ./...`
37+
Run tests with: `go test ./...`
3438

3539
## Submitting a pull request
3640

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/site
77
.github/**/node_modules
88
/CHANGELOG.md
9+
/script/build
910

1011
# VS Code
1112
.vscode

Makefile

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,56 @@
1-
BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
2-
{{end}}' ./...)
3-
4-
GH_VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
5-
DATE_FMT = +%Y-%m-%d
6-
ifdef SOURCE_DATE_EPOCH
7-
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
8-
else
9-
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
10-
endif
11-
121
CGO_CPPFLAGS ?= ${CPPFLAGS}
132
export CGO_CPPFLAGS
143
CGO_CFLAGS ?= ${CFLAGS}
154
export CGO_CFLAGS
165
CGO_LDFLAGS ?= $(filter -g -L% -l% -O%,${LDFLAGS})
176
export CGO_LDFLAGS
187

19-
GO_LDFLAGS := -X github.com/cli/cli/internal/build.Version=$(GH_VERSION) $(GO_LDFLAGS)
20-
GO_LDFLAGS := -X github.com/cli/cli/internal/build.Date=$(BUILD_DATE) $(GO_LDFLAGS)
21-
ifdef GH_OAUTH_CLIENT_SECRET
22-
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(GO_LDFLAGS)
23-
GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS)
24-
endif
8+
## The following tasks delegate to `script/build.go` so they can be run cross-platform.
259

26-
bin/gh: $(BUILD_FILES)
27-
go build -trimpath -ldflags "${GO_LDFLAGS}" -o "$@" ./cmd/gh
10+
.PHONY: bin/gh
11+
bin/gh: script/build
12+
@script/build bin/gh
13+
14+
script/build: script/build.go
15+
go build -o script/build script/build.go
2816

29-
clean:
30-
rm -rf ./bin ./share
3117
.PHONY: clean
18+
clean: script/build
19+
@script/build clean
20+
21+
.PHONY: manpages
22+
manpages: script/build
23+
@script/build manpages
3224

25+
# just a convenience task around `go test`
26+
.PHONY: test
3327
test:
3428
go test ./...
35-
.PHONY: test
29+
30+
## Site-related tasks are exclusively intended for use by the GitHub CLI team and for our release automation.
3631

3732
site:
3833
git clone https://github.com/github/cli.github.com.git "$@"
3934

35+
.PHONY: site-docs
4036
site-docs: site
4137
git -C site pull
4238
git -C site rm 'manual/gh*.md' 2>/dev/null || true
4339
go run ./cmd/gen-docs --website --doc-path site/manual
4440
rm -f site/manual/*.bak
4541
git -C site add 'manual/gh*.md'
4642
git -C site commit -m 'update help docs' || true
47-
.PHONY: site-docs
4843

44+
.PHONY: site-bump
4945
site-bump: site-docs
5046
ifndef GITHUB_REF
5147
$(error GITHUB_REF is not set)
5248
endif
5349
sed -i.bak -E 's/(assign version = )".+"/\1"$(GITHUB_REF:refs/tags/v%=%)"/' site/index.html
5450
rm -f site/index.html.bak
5551
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
56-
.PHONY: site-bump
5752

58-
.PHONY: manpages
59-
manpages:
60-
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/
53+
## Install/uninstall tasks are here for use on *nix platform. On Windows, there is no equivalent.
6154

6255
DESTDIR :=
6356
prefix := /usr/local

api/client_test.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ import (
55
"errors"
66
"io/ioutil"
77
"net/http"
8-
"reflect"
98
"testing"
109

1110
"github.com/cli/cli/pkg/httpmock"
11+
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func eq(t *testing.T, got interface{}, expected interface{}) {
15-
t.Helper()
16-
if !reflect.DeepEqual(got, expected) {
17-
t.Errorf("expected: %v, got: %v", expected, got)
18-
}
19-
}
20-
2114
func TestGraphQL(t *testing.T) {
2215
http := &httpmock.Registry{}
2316
client := NewClient(
@@ -38,13 +31,13 @@ func TestGraphQL(t *testing.T) {
3831
)
3932

4033
err := client.GraphQL("github.com", "QUERY", vars, &response)
41-
eq(t, err, nil)
42-
eq(t, response.Viewer.Login, "hubot")
34+
assert.NoError(t, err)
35+
assert.Equal(t, "hubot", response.Viewer.Login)
4336

4437
req := http.Requests[0]
4538
reqBody, _ := ioutil.ReadAll(req.Body)
46-
eq(t, string(reqBody), `{"query":"QUERY","variables":{"name":"Mona"}}`)
47-
eq(t, req.Header.Get("Authorization"), "token OTOKEN")
39+
assert.Equal(t, `{"query":"QUERY","variables":{"name":"Mona"}}`, string(reqBody))
40+
assert.Equal(t, "token OTOKEN", req.Header.Get("Authorization"))
4841
}
4942

5043
func TestGraphQLError(t *testing.T) {
@@ -84,7 +77,7 @@ func TestRESTGetDelete(t *testing.T) {
8477

8578
r := bytes.NewReader([]byte(`{}`))
8679
err := client.REST("github.com", "DELETE", "applications/CLIENTID/grant", r, nil)
87-
eq(t, err, nil)
80+
assert.NoError(t, err)
8881
}
8982

9083
func TestRESTError(t *testing.T) {

api/pull_request_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package api
33
import (
44
"encoding/json"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
68
)
79

810
func TestPullRequest_ChecksStatus(t *testing.T) {
@@ -31,11 +33,11 @@ func TestPullRequest_ChecksStatus(t *testing.T) {
3133
} }] } }
3234
`
3335
err := json.Unmarshal([]byte(payload), &pr)
34-
eq(t, err, nil)
36+
assert.NoError(t, err)
3537

3638
checks := pr.ChecksStatus()
37-
eq(t, checks.Total, 8)
38-
eq(t, checks.Pending, 3)
39-
eq(t, checks.Failing, 3)
40-
eq(t, checks.Passing, 2)
39+
assert.Equal(t, 8, checks.Total)
40+
assert.Equal(t, 3, checks.Pending)
41+
assert.Equal(t, 3, checks.Failing)
42+
assert.Equal(t, 2, checks.Passing)
4143
}

api/queries_comments.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,51 @@ func CommentCreate(client *Client, repoHost string, params CommentCreateInput) (
132132

133133
return mutation.AddComment.CommentEdge.Node.URL, nil
134134
}
135+
136+
func commentsFragment() string {
137+
return `comments(last: 1) {
138+
nodes {
139+
author {
140+
login
141+
}
142+
authorAssociation
143+
body
144+
createdAt
145+
includesCreatedEdit
146+
` + reactionGroupsFragment() + `
147+
}
148+
totalCount
149+
}`
150+
}
151+
152+
func (c Comment) AuthorLogin() string {
153+
return c.Author.Login
154+
}
155+
156+
func (c Comment) Association() string {
157+
return c.AuthorAssociation
158+
}
159+
160+
func (c Comment) Content() string {
161+
return c.Body
162+
}
163+
164+
func (c Comment) Created() time.Time {
165+
return c.CreatedAt
166+
}
167+
168+
func (c Comment) IsEdited() bool {
169+
return c.IncludesCreatedEdit
170+
}
171+
172+
func (c Comment) Reactions() ReactionGroups {
173+
return c.ReactionGroups
174+
}
175+
176+
func (c Comment) Status() string {
177+
return ""
178+
}
179+
180+
func (c Comment) Link() string {
181+
return ""
182+
}

api/queries_issue.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,11 @@ func milestoneNodeIdToDatabaseId(nodeId string) (string, error) {
481481
}
482482
return splitted[1], nil
483483
}
484+
485+
func (i Issue) Link() string {
486+
return i.URL
487+
}
488+
489+
func (i Issue) Identifier() string {
490+
return i.ID
491+
}

0 commit comments

Comments
 (0)
X Tutup