From 569645a050dec9db212b9e49bde6ed2537012407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Jul 2020 14:34:44 +0200 Subject: [PATCH 1/6] Support `hosts.yml` existing while `config.yml` does not After a person copies `hosts.yml` to a headless system, they will still be forced to go through re-authentication flow unless they copy or initialize a `config.yml` as well. This fixes respecting authentication info from `hosts.yml` even if `config.yml` is missing. --- internal/config/config_file.go | 6 ++++- internal/config/config_file_test.go | 36 +++++++++++++++++++++++------ internal/config/config_type.go | 8 +++++-- internal/config/testing.go | 6 ++++- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/internal/config/config_file.go b/internal/config/config_file.go index 49a2770d3..af2c2d560 100644 --- a/internal/config/config_file.go +++ b/internal/config/config_file.go @@ -138,7 +138,11 @@ func migrateConfig(filename string) error { func ParseConfig(filename string) (Config, error) { _, root, err := parseConfigFile(filename) if err != nil { - return nil, err + if os.IsNotExist(err) { + root = NewBlankRoot() + } else { + return nil, err + } } if isLegacy(root) { diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.go index d19130bb5..f921d2c67 100644 --- a/internal/config/config_file_test.go +++ b/internal/config/config_file_test.go @@ -110,14 +110,36 @@ github.com: } func Test_parseConfigFile(t *testing.T) { - fileContents := []string{"", " ", "\n"} - for _, contents := range fileContents { - t.Run(fmt.Sprintf("contents: %q", contents), func(t *testing.T) { - defer StubConfig(contents, "")() + tests := []struct { + contents string + wantsErr bool + }{ + { + contents: "", + wantsErr: true, + }, + { + contents: " ", + wantsErr: false, + }, + { + contents: "\n", + wantsErr: false, + }, + } + + for _, tt := range tests { + t.Run(fmt.Sprintf("contents: %q", tt.contents), func(t *testing.T) { + defer StubConfig(tt.contents, "")() _, yamlRoot, err := parseConfigFile("config.yml") - eq(t, err, nil) - eq(t, yamlRoot.Content[0].Kind, yaml.MappingNode) - eq(t, len(yamlRoot.Content[0].Content), 0) + if tt.wantsErr != (err != nil) { + t.Fatalf("got error: %v", err) + } + if tt.wantsErr { + return + } + assert.Equal(t, yaml.MappingNode, yamlRoot.Content[0].Kind) + assert.Equal(t, 0, len(yamlRoot.Content[0].Content)) }) } } diff --git a/internal/config/config_type.go b/internal/config/config_type.go index a57d21dec..85e5c0d4a 100644 --- a/internal/config/config_type.go +++ b/internal/config/config_type.go @@ -123,7 +123,11 @@ func NewConfig(root *yaml.Node) Config { } func NewBlankConfig() Config { - return NewConfig(&yaml.Node{ + return NewConfig(NewBlankRoot()) +} + +func NewBlankRoot() *yaml.Node { + return &yaml.Node{ Kind: yaml.DocumentNode, Content: []*yaml.Node{ { @@ -168,7 +172,7 @@ func NewBlankConfig() Config { }, }, }, - }) + } } // This type implements a Config interface and represents a config file on disk. diff --git a/internal/config/testing.go b/internal/config/testing.go index 59c2ff212..a49178705 100644 --- a/internal/config/testing.go +++ b/internal/config/testing.go @@ -42,7 +42,11 @@ func StubConfig(main, hosts string) func() { ReadConfigFile = func(fn string) ([]byte, error) { switch path.Base(fn) { case "config.yml": - return []byte(main), nil + if main == "" { + return []byte(nil), os.ErrNotExist + } else { + return []byte(main), nil + } case "hosts.yml": if hosts == "" { return []byte(nil), os.ErrNotExist From b6206aa036c59ef0a6d0114ea2f7f65ce9d3b902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Jul 2020 16:14:11 +0200 Subject: [PATCH 2/6] Update the branch name in the `github/gh/gh` brew formula --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 0909fa8f7..fa6883834 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -61,7 +61,7 @@ brews: folder: Formula custom_block: | head do - url "https://github.com/cli/cli.git" + url "https://github.com/cli/cli.git", :branch => "trunk" depends_on "go" end install: | From ac7b56fc61f04ee0f64a33570e65931b87657925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jul 2020 17:01:37 +0200 Subject: [PATCH 3/6] Fix linter warning about sprintf within println --- command/root.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/root.go b/command/root.go index cf0e3cbb1..3693fd6f0 100644 --- a/command/root.go +++ b/command/root.go @@ -257,8 +257,8 @@ var ensureScopes = func(ctx context.Context, client *api.Client, wantedScopes .. } return reloadedClient, nil } else { - fmt.Fprintln(os.Stderr, fmt.Sprintf("Warning: gh now requires %s OAuth scopes.", wantedScopes)) - fmt.Fprintln(os.Stderr, fmt.Sprintf("Visit https://github.com/settings/tokens and edit your token to enable %s", wantedScopes)) + fmt.Fprintf(os.Stderr, "Warning: gh now requires %s OAuth scopes.\n", wantedScopes) + fmt.Fprintf(os.Stderr, "Visit https://github.com/settings/tokens and edit your token to enable %s\n", wantedScopes) if tokenFromEnv { fmt.Fprintln(os.Stderr, "or generate a new token for the GITHUB_TOKEN environment variable") } else { From 9c7d52f9f61a5afc79da2ecf723d060c11da4489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 2 Jul 2020 17:02:38 +0200 Subject: [PATCH 4/6] Bump golangci-lint --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index aff0ce343..39f048881 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -29,7 +29,7 @@ jobs: go mod verify go mod download - LINT_VERSION=1.26.0 + LINT_VERSION=1.27.0 curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \ tar xz --strip-components 1 --wildcards \*/golangci-lint mkdir -p bin && mv golangci-lint bin/ From 6cbcdf2a74e7b75b7741a3a6a733e4d3ce52920b Mon Sep 17 00:00:00 2001 From: Ravikanth C Date: Mon, 6 Jul 2020 19:33:17 +0530 Subject: [PATCH 5/6] Clarify how the branch can be retained after `pr merge` --- command/pr.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/command/pr.go b/command/pr.go index 79c65b874..e11884bbb 100644 --- a/command/pr.go +++ b/command/pr.go @@ -107,9 +107,14 @@ var prReopenCmd = &cobra.Command{ } var prMergeCmd = &cobra.Command{ Use: "merge [ | | ]", - Short: "Merge a pull request", Args: cobra.MaximumNArgs(1), - RunE: prMerge, + Short: "Merge a pull request", + Long: `Merge a pull request by providing the pull request number or url or the branch. + +By default, the source branch gets deleted after the pull request merge is complete. + +If the source branch needs be retained, '--delete-branch=false' should be specified.`, + RunE: prMerge, } var prReadyCmd = &cobra.Command{ Use: "ready [ | | ]", From e319aaa6abc1fc9338570d77d9c6ab65bc1567f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Jul 2020 12:21:25 +0200 Subject: [PATCH 6/6] Tweak `pr merge` docs --- command/pr.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/command/pr.go b/command/pr.go index e11884bbb..0c851b511 100644 --- a/command/pr.go +++ b/command/pr.go @@ -107,13 +107,14 @@ var prReopenCmd = &cobra.Command{ } var prMergeCmd = &cobra.Command{ Use: "merge [ | | ]", - Args: cobra.MaximumNArgs(1), Short: "Merge a pull request", - Long: `Merge a pull request by providing the pull request number or url or the branch. + Long: heredoc.Doc(` + Merge a pull request on GitHub. -By default, the source branch gets deleted after the pull request merge is complete. - -If the source branch needs be retained, '--delete-branch=false' should be specified.`, + By default, the head branch of the pull request will get deleted on both remote and local repositories. + To retain the branch, use '--delete-branch=false'. + `), + Args: cobra.MaximumNArgs(1), RunE: prMerge, } var prReadyCmd = &cobra.Command{