X Tutup
Skip to content

Commit 1ce09ff

Browse files
committed
Merge branch 'master' into reviewers-in-pr-view
2 parents 67907c8 + 80d7513 commit 1ce09ff

36 files changed

+1285
-309
lines changed

.github/CONTRIBUTING.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,42 @@
66

77
Hi! Thanks for your interest in contributing to the GitHub CLI!
88

9-
Given that this project is very early and still in beta, we're only accepting pull requests for bug fixes right now. We'd love to
10-
hear about ideas for new features as issues, though!
9+
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.
1110

1211
Please do:
1312

1413
* open an issue if things aren't working as expected
1514
* open an issue to propose a significant change
16-
* open a PR to fix a bug
15+
* open a pull request to fix a bug
16+
* open a pull request to fix documentation about a command
17+
* open a pull request if a member of the GitHub CLI team has given the ok after discussion in an issue
1718

18-
## Submitting a bug fix
19+
Please avoid:
1920

20-
0. Clone this repository
21-
0. Create a new branch: `git checkout -b my-branch-name`
22-
0. Make your change, add tests, and ensure tests pass
23-
0. Make a PR: `gh pr create --web`
21+
* adding installation instructions specifically for your OS/package manager
22+
23+
## Building the project
24+
25+
Prerequisites:
26+
- Go 1.13
27+
28+
Build with: `make` or `go build -o bin/gh ./cmd/gh`
29+
30+
Run the new binary as: `./bin/gh`
31+
32+
Run tests with: `make test` or `go test ./...`
33+
34+
## Submitting a pull request
35+
36+
1. Create a new branch: `git checkout -b my-branch-name`
37+
1. Make your change, add tests, and ensure tests pass
38+
1. Submit a pull request: `gh pr create --web`
2439

2540
Contributions to this project are [released][legal] to the public under the [project's open source license][license].
2641

2742
Please note that this project adheres to a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
2843

29-
We generate manual pages from source on every release! You do not need to submit PRs for those specifically; the docs will get updated if your PR gets accepted.
44+
We generate manual pages from source on every release. You do not need to submit pull requests for documentation specifically; manual pages for commands will automatically get updated after your pull requests gets accepted.
3045

3146
## Resources
3247

.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.13
13-
uses: actions/setup-go@v1
13+
uses: actions/setup-go@v2-beta
1414
with:
1515
go-version: 1.13
1616

.github/workflows/lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ name: Lint
22
on:
33
push:
44
paths:
5-
- '**.go'
6-
- go.mod
7-
- go.sum
5+
- "**.go"
6+
- go.mod
7+
- go.sum
88

99
jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212

1313
steps:
1414
- name: Set up Go 1.13
15-
uses: actions/setup-go@v1
15+
uses: actions/setup-go@v2-beta
1616
with:
1717
go-version: 1.13
1818

.github/workflows/releases.yml

Lines changed: 1 addition & 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.13
15-
uses: actions/setup-go@v1
15+
uses: actions/setup-go@v2-beta
1616
with:
1717
go-version: 1.13
1818
- name: Generate changelog

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ MSI installers are available for download on the [releases page][].
9393
Install and upgrade:
9494

9595
1. Download the `.deb` file from the [releases page][]
96-
2. `sudo apt install git && sudo dpkg -i gh_*_linux_amd64.deb` install the downloaded file
96+
2. `sudo apt install ./gh_*_linux_amd64.deb` install the downloaded file
9797

9898
### Fedora Linux
9999

api/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func (c Client) REST(method string, p string, body io.Reader, data interface{})
146146
return handleHTTPError(resp)
147147
}
148148

149+
if resp.StatusCode == http.StatusNoContent {
150+
return nil
151+
}
152+
149153
b, err := ioutil.ReadAll(resp.Body)
150154
if err != nil {
151155
return err

api/client_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,17 @@ func TestGraphQLError(t *testing.T) {
5050
t.Fatalf("got %q", err.Error())
5151
}
5252
}
53+
54+
func TestRESTGetDelete(t *testing.T) {
55+
http := &FakeHTTP{}
56+
57+
client := NewClient(
58+
ReplaceTripper(http),
59+
)
60+
61+
http.StubResponse(204, bytes.NewBuffer([]byte{}))
62+
63+
r := bytes.NewReader([]byte(`{}`))
64+
err := client.REST("DELETE", "applications/CLIENTID/grant", r, nil)
65+
eq(t, err, nil)
66+
}

api/queries_issue.go

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type IssuesAndTotalCount struct {
1818
TotalCount int
1919
}
2020

21+
// Ref. https://developer.github.com/v4/object/issue/
2122
type Issue struct {
2223
Number int
2324
Title string
@@ -32,15 +33,32 @@ type Issue struct {
3233
Author struct {
3334
Login string
3435
}
35-
36+
Assignees struct {
37+
Nodes []struct {
38+
Login string
39+
}
40+
TotalCount int
41+
}
3642
Labels struct {
37-
Nodes []IssueLabel
43+
Nodes []struct {
44+
Name string
45+
}
3846
TotalCount int
3947
}
40-
}
41-
42-
type IssueLabel struct {
43-
Name string
48+
ProjectCards struct {
49+
Nodes []struct {
50+
Project struct {
51+
Name string
52+
}
53+
Column struct {
54+
Name string
55+
}
56+
}
57+
TotalCount int
58+
}
59+
Milestone struct {
60+
Title string
61+
}
4462
}
4563

4664
const fragments = `
@@ -287,14 +305,35 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
287305
comments {
288306
totalCount
289307
}
290-
labels(first: 3) {
308+
number
309+
url
310+
createdAt
311+
assignees(first: 100) {
312+
nodes {
313+
login
314+
}
315+
totalCount
316+
}
317+
labels(first: 100) {
291318
nodes {
292319
name
293320
}
321+
totalCount
322+
}
323+
projectCards(first: 100) {
324+
nodes {
325+
project {
326+
name
327+
}
328+
column {
329+
name
330+
}
331+
}
332+
totalCount
333+
}
334+
milestone{
335+
title
294336
}
295-
number
296-
url
297-
createdAt
298337
}
299338
}
300339
}`

cmd/gh/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/cli/cli/command"
13-
"github.com/cli/cli/context"
13+
"github.com/cli/cli/internal/config"
1414
"github.com/cli/cli/update"
1515
"github.com/cli/cli/utils"
1616
"github.com/mgutz/ansi"
@@ -88,6 +88,6 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) {
8888
}
8989

9090
repo := updaterEnabled
91-
stateFilePath := path.Join(context.ConfigDir(), "state.yml")
91+
stateFilePath := path.Join(config.ConfigDir(), "state.yml")
9292
return update.CheckForUpdate(client, stateFilePath, repo, currentVersion)
9393
}

command/config.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package command
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func init() {
9+
RootCmd.AddCommand(configCmd)
10+
configCmd.AddCommand(configGetCmd)
11+
configCmd.AddCommand(configSetCmd)
12+
13+
configGetCmd.Flags().StringP("host", "h", "", "Get per-host setting")
14+
configSetCmd.Flags().StringP("host", "h", "", "Set per-host setting")
15+
16+
// TODO reveal and add usage once we properly support multiple hosts
17+
_ = configGetCmd.Flags().MarkHidden("host")
18+
// TODO reveal and add usage once we properly support multiple hosts
19+
_ = configSetCmd.Flags().MarkHidden("host")
20+
}
21+
22+
var configCmd = &cobra.Command{
23+
Use: "config",
24+
Short: "Set and get gh settings",
25+
Long: `Get and set key/value strings.
26+
27+
Current respected settings:
28+
- git_protocol: https or ssh. Default is https.
29+
- editor: if unset, defaults to environment variables.
30+
`,
31+
}
32+
33+
var configGetCmd = &cobra.Command{
34+
Use: "get <key>",
35+
Short: "Prints the value of a given configuration key.",
36+
Long: `Get the value for a given configuration key.
37+
38+
Examples:
39+
$ gh config get git_protocol
40+
https
41+
`,
42+
Args: cobra.ExactArgs(1),
43+
RunE: configGet,
44+
}
45+
46+
var configSetCmd = &cobra.Command{
47+
Use: "set <key> <value>",
48+
Short: "Updates configuration with the value of a given key.",
49+
Long: `Update the configuration by setting a key to a value.
50+
51+
Examples:
52+
$ gh config set editor vim
53+
`,
54+
Args: cobra.ExactArgs(2),
55+
RunE: configSet,
56+
}
57+
58+
func configGet(cmd *cobra.Command, args []string) error {
59+
key := args[0]
60+
hostname, err := cmd.Flags().GetString("host")
61+
if err != nil {
62+
return err
63+
}
64+
65+
ctx := contextForCommand(cmd)
66+
67+
cfg, err := ctx.Config()
68+
if err != nil {
69+
return err
70+
}
71+
72+
val, err := cfg.Get(hostname, key)
73+
if err != nil {
74+
return err
75+
}
76+
77+
if val != "" {
78+
out := colorableOut(cmd)
79+
fmt.Fprintf(out, "%s\n", val)
80+
}
81+
82+
return nil
83+
}
84+
85+
func configSet(cmd *cobra.Command, args []string) error {
86+
key := args[0]
87+
value := args[1]
88+
89+
hostname, err := cmd.Flags().GetString("host")
90+
if err != nil {
91+
return err
92+
}
93+
94+
ctx := contextForCommand(cmd)
95+
96+
cfg, err := ctx.Config()
97+
if err != nil {
98+
return err
99+
}
100+
101+
err = cfg.Set(hostname, key, value)
102+
if err != nil {
103+
return fmt.Errorf("failed to set %q to %q: %w", key, value, err)
104+
}
105+
106+
err = cfg.Write()
107+
if err != nil {
108+
return fmt.Errorf("failed to write config to disk: %w", err)
109+
}
110+
111+
return nil
112+
}

0 commit comments

Comments
 (0)
X Tutup