Skip to content

Commit 9ecbdb2

Browse files
committed
Merge branch 'trunk' of https://github.com/cli/cli into feature/repo-with-gitignore-license
2 parents a44a3c8 + 640a089 commit 9ecbdb2

File tree

9 files changed

+68
-38
lines changed

9 files changed

+68
-38
lines changed

.github/workflows/releases.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,18 @@ jobs:
197197
GIT_AUTHOR_NAME: cli automation
198198
GIT_COMMITTER_EMAIL: noreply@github.com
199199
GIT_AUTHOR_EMAIL: noreply@github.com
200+
- name: Bump Winget manifest
201+
shell: pwsh
202+
env:
203+
WINGETCREATE_VERSION: v0.2.0.29-preview
204+
GITHUB_TOKEN: ${{ secrets.UPLOAD_GITHUB_TOKEN }}
205+
run: |
206+
$tagname = $env:GITHUB_REF.Replace("refs/tags/", "")
207+
$version = $tagname.Replace("v", "")
208+
$url = "https://github.com/cli/cli/releases/download/${tagname}/gh_${version}_windows_amd64.msi"
209+
iwr https://github.com/microsoft/winget-create/releases/download/${env:WINGETCREATE_VERSION}/wingetcreate.exe -OutFile wingetcreate.exe
210+
211+
.\wingetcreate.exe update GitHub.cli --url $url --version $version
212+
if ($version -notmatch "-") {
213+
.\wingetcreate.exe submit .\manifests\g\GitHub\cli\${version}\ --token $env:GITHUB_TOKEN
214+
}

cmd/gh/main.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,17 @@ func mainRun() exitCode {
159159

160160
cs := cmdFactory.IOStreams.ColorScheme()
161161

162-
if cmd != nil && cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
163-
fmt.Fprintln(stderr, cs.Bold("Welcome to GitHub CLI!"))
164-
fmt.Fprintln(stderr)
165-
fmt.Fprintln(stderr, "To authenticate, please run `gh auth login`.")
166-
return exitAuth
162+
authError := errors.New("authError")
163+
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
164+
// require that the user is authenticated before running most commands
165+
if cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
166+
fmt.Fprintln(stderr, cs.Bold("Welcome to GitHub CLI!"))
167+
fmt.Fprintln(stderr)
168+
fmt.Fprintln(stderr, "To authenticate, please run `gh auth login`.")
169+
return authError
170+
}
171+
172+
return nil
167173
}
168174

169175
rootCmd.SetArgs(expandedArgs)
@@ -177,6 +183,8 @@ func mainRun() exitCode {
177183
fmt.Fprint(stderr, "\n")
178184
}
179185
return exitCancel
186+
} else if errors.Is(err, authError) {
187+
return exitAuth
180188
}
181189

182190
printError(stderr, err, cmd, hasDebug)

pkg/cmd/actions/actions.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,30 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
type ActionsOptions struct {
13-
IO *iostreams.IOStreams
14-
}
15-
1612
func NewCmdActions(f *cmdutil.Factory) *cobra.Command {
17-
opts := ActionsOptions{
18-
IO: f.IOStreams,
19-
}
13+
cs := f.IOStreams.ColorScheme()
2014

2115
cmd := &cobra.Command{
2216
Use: "actions",
2317
Short: "Learn about working with GitHub actions",
24-
Long: actionsExplainer(nil),
18+
Long: actionsExplainer(cs),
2519
Run: func(cmd *cobra.Command, args []string) {
26-
actionsRun(opts)
20+
fmt.Fprintln(f.IOStreams.Out, actionsExplainer(cs))
2721
},
2822
Annotations: map[string]string{
2923
"IsActions": "true",
3024
},
3125
}
3226

27+
cmdutil.DisableAuthCheck(cmd)
28+
3329
return cmd
3430
}
3531

3632
func actionsExplainer(cs *iostreams.ColorScheme) string {
37-
header := "Welcome to GitHub Actions on the command line."
38-
runHeader := "Interacting with workflow runs"
39-
workflowHeader := "Interacting with workflow files"
40-
if cs != nil {
41-
header = cs.Bold(header)
42-
runHeader = cs.Bold(runHeader)
43-
workflowHeader = cs.Bold(workflowHeader)
44-
}
33+
header := cs.Bold("Welcome to GitHub Actions on the command line.")
34+
runHeader := cs.Bold("Interacting with workflow runs")
35+
workflowHeader := cs.Bold("Interacting with workflow files")
4536

4637
return heredoc.Docf(`
4738
%s
@@ -70,8 +61,3 @@ func actionsExplainer(cs *iostreams.ColorScheme) string {
7061
<https://docs.github.com/en/actions/guides/managing-github-actions-with-github-cli>
7162
`, header, runHeader, workflowHeader)
7263
}
73-
74-
func actionsRun(opts ActionsOptions) {
75-
cs := opts.IO.ColorScheme()
76-
fmt.Fprintln(opts.IO.Out, actionsExplainer(cs))
77-
}

pkg/cmd/factory/default_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ func Test_ioStreams_pager(t *testing.T) {
333333
}
334334
}
335335
f := New("1")
336-
if tt.config != nil {
337-
f.Config = func() (config.Config, error) {
336+
f.Config = func() (config.Config, error) {
337+
if tt.config == nil {
338+
return config.NewBlankConfig(), nil
339+
} else {
338340
return tt.config, nil
339341
}
340342
}
@@ -363,8 +365,10 @@ func Test_ioStreams_prompt(t *testing.T) {
363365
for _, tt := range tests {
364366
t.Run(tt.name, func(t *testing.T) {
365367
f := New("1")
366-
if tt.config != nil {
367-
f.Config = func() (config.Config, error) {
368+
f.Config = func() (config.Config, error) {
369+
if tt.config == nil {
370+
return config.NewBlankConfig(), nil
371+
} else {
368372
return tt.config, nil
369373
}
370374
}

pkg/cmd/gist/create/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
5858
Gists can be created from one or multiple files. Alternatively, pass "-" as
5959
file name to read from standard input.
6060
61-
By default, gists are private; use '--public' to make publicly listed ones.
61+
By default, gists are secret; use '--public' to make publicly listed ones.
6262
`),
6363
Example: heredoc.Doc(`
6464
# publish file 'hello.py' as a public gist
@@ -97,7 +97,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
9797

9898
cmd.Flags().StringVarP(&opts.Description, "desc", "d", "", "A description for this gist")
9999
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser with created gist")
100-
cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: private)")
100+
cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: secret)")
101101
cmd.Flags().StringVarP(&opts.FilenameOverride, "filename", "f", "", "Provide a filename to be used when reading from STDIN")
102102
return cmd
103103
}

pkg/cmd/issue/list/list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
8282
cmd.Flags().StringVarP(&opts.Assignee, "assignee", "a", "", "Filter by assignee")
8383
cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by labels")
8484
cmd.Flags().StringVarP(&opts.State, "state", "s", "open", "Filter by state: {open|closed|all}")
85+
_ = cmd.RegisterFlagCompletionFunc("state", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
86+
return []string{"open", "closed", "all"}, cobra.ShellCompDirectiveNoSpace
87+
})
8588
cmd.Flags().IntVarP(&opts.LimitResults, "limit", "L", 30, "Maximum number of issues to fetch")
8689
cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author")
8790
cmd.Flags().StringVar(&opts.Mention, "mention", "", "Filter by mention")

pkg/cmd/pr/list/list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
8484
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the browser to list the pull requests")
8585
cmd.Flags().IntVarP(&opts.LimitResults, "limit", "L", 30, "Maximum number of items to fetch")
8686
cmd.Flags().StringVarP(&opts.State, "state", "s", "open", "Filter by state: {open|closed|merged|all}")
87+
_ = cmd.RegisterFlagCompletionFunc("state", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
88+
return []string{"open", "closed", "merged", "all"}, cobra.ShellCompDirectiveNoSpace
89+
})
8790
cmd.Flags().StringVarP(&opts.BaseBranch, "base", "B", "", "Filter by base branch")
8891
cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by labels")
8992
cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author")

pkg/cmdutil/auth_check.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8-
// TODO can have this set a PersistentPreRun so we don't have to set for all child commands of auth,
9-
// config
10-
118
func DisableAuthCheck(cmd *cobra.Command) {
129
if cmd.Annotations == nil {
1310
cmd.Annotations = map[string]string{}
@@ -37,7 +34,7 @@ func CheckAuth(cfg config.Config) bool {
3734
}
3835

3936
func IsAuthCheckEnabled(cmd *cobra.Command) bool {
40-
if !cmd.Runnable() {
37+
if cmd.Name() == "help" {
4138
return false
4239
}
4340
for c := cmd; c.Parent() != nil; c = c.Parent() {

pkg/cmdutil/repo_override.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10+
func executeParentHooks(cmd *cobra.Command, args []string) error {
11+
for cmd.HasParent() {
12+
cmd = cmd.Parent()
13+
if cmd.PersistentPreRunE != nil {
14+
return cmd.PersistentPreRunE(cmd, args)
15+
}
16+
}
17+
return nil
18+
}
19+
1020
func EnableRepoOverride(cmd *cobra.Command, f *Factory) {
1121
cmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
1222

13-
cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
23+
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
24+
if err := executeParentHooks(cmd, args); err != nil {
25+
return err
26+
}
1427
repoOverride, _ := cmd.Flags().GetString("repo")
1528
f.BaseRepo = OverrideBaseRepoFunc(f, repoOverride)
29+
return nil
1630
}
1731
}
1832

0 commit comments

Comments
 (0)