Skip to content

Commit f51669e

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr-count
2 parents 9cd53b8 + 58f6bef commit f51669e

27 files changed

+548
-155
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
- name: Build
2424
shell: bash
2525
run: |
26-
go test ./...
26+
go test -race ./...
2727
go build -v ./cmd/gh

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# gh - The GitHub CLI tool
1+
# GitHub CLI
22

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.
@@ -24,15 +24,16 @@ And if you spot bugs or have features that you'd really like to see in `gh`, ple
2424
- `gh repo [view, create, clone, fork]`
2525
- `gh help`
2626

27-
Check out the [docs][] for more information.
27+
## Documentation
2828

29+
Read the [official docs](https://cli.github.com/manual/) for more information.
2930

3031
## Comparison with hub
3132

3233
For many years, [hub][] was the unofficial GitHub CLI tool. `gh` is a new project for us to explore
3334
what an official GitHub CLI tool can look like with a fundamentally different design. While both
3435
tools bring GitHub to the terminal, `hub` behaves as a proxy to `git` and `gh` is a standalone
35-
tool.
36+
tool. Check out our [more detailed explanation](/docs/gh-vs-hub.md) to learn more.
3637

3738

3839
## Installation and Upgrading
@@ -83,7 +84,14 @@ Install and upgrade:
8384
1. Download the `.deb` file from the [releases page][]
8485
2. `sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb` install the downloaded file
8586

86-
### Fedora/Centos Linux
87+
### Fedora Linux
88+
89+
Install and upgrade:
90+
91+
1. Download the `.rpm` file from the [releases page][]
92+
2. `sudo dnf install gh_*_linux_amd64.rpm` install the downloaded file
93+
94+
### Centos Linux
8795

8896
Install and upgrade:
8997

@@ -109,7 +117,7 @@ $ yay -S github-cli
109117

110118
Install a prebuilt binary from the [releases page][]
111119

112-
### [Build from source](/source.md)
120+
### [Build from source](/docs/source.md)
113121

114122
[docs]: https://cli.github.com/manual
115123
[scoop]: https://scoop.sh

api/fake_http.go

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

1414
// FakeHTTP provides a mechanism by which to stub HTTP responses through
1515
type FakeHTTP struct {
16-
// Requests stores references to sequental requests that RoundTrip has received
16+
// Requests stores references to sequential requests that RoundTrip has received
1717
Requests []*http.Request
1818
count int
1919
responseStubs []*http.Response

api/queries_issue.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
171171
return &payload, nil
172172
}
173173

174-
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int) (*IssuesAndTotalCount, error) {
174+
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string) (*IssuesAndTotalCount, error) {
175175
var states []string
176176
switch state {
177177
case "open", "":
@@ -185,10 +185,10 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
185185
}
186186

187187
query := fragments + `
188-
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
188+
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String, $author: String) {
189189
repository(owner: $owner, name: $repo) {
190190
hasIssuesEnabled
191-
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
191+
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author}) {
192192
totalCount
193193
nodes {
194194
...issue
@@ -213,6 +213,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
213213
if assigneeString != "" {
214214
variables["assignee"] = assigneeString
215215
}
216+
if authorString != "" {
217+
variables["author"] = authorString
218+
}
216219

217220
var response struct {
218221
Repository struct {

api/queries_issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestIssueList(t *testing.T) {
3838
} } }
3939
`))
4040

41-
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251)
41+
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251, "")
4242
if err != nil {
4343
t.Fatalf("unexpected error: %v", err)
4444
}

api/queries_pr.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type PullRequestsPayload struct {
1111
ViewerCreated PullRequestAndTotalCount
1212
ReviewRequested PullRequestAndTotalCount
13-
CurrentPRs []PullRequest
13+
CurrentPR *PullRequest
1414
}
1515

1616
type PullRequestAndTotalCount struct {
@@ -262,13 +262,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
262262
reviewRequested = append(reviewRequested, edge.Node)
263263
}
264264

265-
var currentPRs []PullRequest
266-
if resp.Repository.PullRequest != nil {
267-
currentPRs = append(currentPRs, *resp.Repository.PullRequest)
268-
} else {
265+
var currentPR = resp.Repository.PullRequest
266+
if currentPR == nil {
269267
for _, edge := range resp.Repository.PullRequests.Edges {
270268
if edge.Node.HeadLabel() == currentPRHeadRef {
271-
currentPRs = append(currentPRs, edge.Node)
269+
currentPR = &edge.Node
270+
break // Take the most recent PR for the current branch
272271
}
273272
}
274273
}
@@ -282,7 +281,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
282281
PullRequests: reviewRequested,
283282
TotalCount: resp.ReviewRequested.TotalCount,
284283
},
285-
CurrentPRs: currentPRs,
284+
CurrentPR: currentPR,
286285
}
287286

288287
return &payload, nil
@@ -507,6 +506,7 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) (*P
507506
}
508507
}`
509508

509+
var check = make(map[int]struct{})
510510
var prs []PullRequest
511511
pageLimit := min(limit, 100)
512512
variables := map[string]interface{}{}
@@ -583,7 +583,12 @@ loop:
583583
}
584584

585585
for _, edge := range prData.Edges {
586+
if _, exists := check[edge.Node.Number]; exists {
587+
continue
588+
}
589+
586590
prs = append(prs, edge.Node)
591+
check[edge.Node.Number] = struct{}{}
587592
if len(prs) == limit {
588593
break loop
589594
}

api/queries_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func ForkRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
224224
type RepoCreateInput struct {
225225
Name string `json:"name"`
226226
Visibility string `json:"visibility"`
227-
Homepage string `json:"homepage,omitempty"`
227+
HomepageURL string `json:"homepageUrl,omitempty"`
228228
Description string `json:"description,omitempty"`
229229

230230
OwnerID string `json:"ownerId,omitempty"`

api/queries_repo_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package api
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"io/ioutil"
7+
"testing"
8+
)
9+
10+
func Test_RepoCreate(t *testing.T) {
11+
http := &FakeHTTP{}
12+
client := NewClient(ReplaceTripper(http))
13+
14+
http.StubResponse(200, bytes.NewBufferString(`{}`))
15+
16+
input := RepoCreateInput{
17+
Description: "roasted chesnuts",
18+
HomepageURL: "http://example.com",
19+
}
20+
21+
_, err := RepoCreate(client, input)
22+
if err != nil {
23+
t.Fatalf("unexpected error: %v", err)
24+
}
25+
26+
if len(http.Requests) != 1 {
27+
t.Fatalf("expected 1 HTTP request, seen %d", len(http.Requests))
28+
}
29+
30+
var reqBody struct {
31+
Query string
32+
Variables struct {
33+
Input map[string]interface{}
34+
}
35+
}
36+
37+
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
38+
json.Unmarshal(bodyBytes, &reqBody)
39+
if description := reqBody.Variables.Input["description"].(string); description != "roasted chesnuts" {
40+
t.Errorf("expected description to be %q, got %q", "roasted chesnuts", description)
41+
}
42+
if homepage := reqBody.Variables.Input["homepageUrl"].(string); homepage != "http://example.com" {
43+
t.Errorf("expected homepageUrl to be %q, got %q", "http://example.com", homepage)
44+
}
45+
}

command/completion.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import (
99

1010
func init() {
1111
RootCmd.AddCommand(completionCmd)
12-
completionCmd.Flags().StringP("shell", "s", "bash", "The type of shell")
12+
completionCmd.Flags().StringP("shell", "s", "bash", "Shell type: {bash|zsh|fish|powershell}")
1313
}
1414

1515
var completionCmd = &cobra.Command{
16-
Use: "completion",
17-
Hidden: true,
18-
Short: "Generates completion scripts",
19-
Long: `To enable completion in your shell, run:
16+
Use: "completion",
17+
Short: "Generate shell completion scripts",
18+
Long: `Generate shell completion scripts for GitHub CLI commands.
2019
21-
eval "$(gh completion)"
20+
For example, for bash you could add this to your '~/.bash_profile':
2221
23-
You can add that to your '~/.bash_profile' to enable completion whenever you
24-
start a new shell.
22+
eval "$(gh completion)"
2523
26-
When installing with Homebrew, see https://docs.brew.sh/Shell-Completion
24+
When installing GitHub CLI through a package manager, however, it's possible that
25+
no additional shell configuration is necessary to gain completion support. For
26+
Homebrew, see <https://docs.brew.sh/Shell-Completion>
2727
`,
2828
RunE: func(cmd *cobra.Command, args []string) error {
2929
shellType, err := cmd.Flags().GetString("shell")
@@ -36,6 +36,8 @@ When installing with Homebrew, see https://docs.brew.sh/Shell-Completion
3636
return RootCmd.GenBashCompletion(cmd.OutOrStdout())
3737
case "zsh":
3838
return RootCmd.GenZshCompletion(cmd.OutOrStdout())
39+
case "powershell":
40+
return RootCmd.GenPowerShellCompletion(cmd.OutOrStdout())
3941
case "fish":
4042
return cobrafish.GenCompletion(RootCmd, cmd.OutOrStdout())
4143
default:

command/completion_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ func TestCompletion_fish(t *testing.T) {
3838
}
3939
}
4040

41+
func TestCompletion_powerShell(t *testing.T) {
42+
output, err := RunCommand(completionCmd, `completion -s powershell`)
43+
if err != nil {
44+
t.Fatal(err)
45+
}
46+
47+
if !strings.Contains(output.String(), "Register-ArgumentCompleter") {
48+
t.Errorf("problem in fish completion:\n%s", output)
49+
}
50+
}
51+
4152
func TestCompletion_unsupported(t *testing.T) {
4253
_, err := RunCommand(completionCmd, `completion -s csh`)
4354
if err == nil || err.Error() != `unsupported shell type "csh"` {

0 commit comments

Comments
 (0)