X Tutup
Skip to content

Commit cfddda8

Browse files
committed
Indicate workflow scope is GHE 3.0+ only during auth login
1 parent f807795 commit cfddda8

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

pkg/cmd/auth/shared/login_flow.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/MakeNowJust/heredoc"
1010
"github.com/cli/cli/api"
1111
"github.com/cli/cli/internal/authflow"
12+
"github.com/cli/cli/internal/ghinstance"
1213
"github.com/cli/cli/pkg/iostreams"
1314
"github.com/cli/cli/pkg/prompt"
1415
)
@@ -125,7 +126,7 @@ func Login(opts *LoginOptions) error {
125126
fmt.Fprint(opts.IO.ErrOut, heredoc.Docf(`
126127
Tip: you can generate a Personal Access Token here https://%s/settings/tokens
127128
The minimum required scopes are %s.
128-
`, hostname, scopesSentence(minimumScopes)))
129+
`, hostname, scopesSentence(minimumScopes, ghinstance.IsEnterprise(hostname))))
129130

130131
err := prompt.SurveyAskOne(&survey.Password{
131132
Message: "Paste your authentication token:",
@@ -193,11 +194,14 @@ func Login(opts *LoginOptions) error {
193194
return nil
194195
}
195196

196-
func scopesSentence(scopes []string) string {
197+
func scopesSentence(scopes []string, isEnterprise bool) string {
197198
quoted := make([]string, len(scopes))
198199
for i, s := range scopes {
199200
quoted[i] = fmt.Sprintf("'%s'", s)
201+
if s == "workflow" && isEnterprise {
202+
// remove when GHE 2.x reaches EOL
203+
quoted[i] += " (GHE 3.0+)"
204+
}
200205
}
201-
// TODO: insert an "and" before the last element
202206
return strings.Join(quoted, ", ")
203207
}

pkg/cmd/auth/shared/login_flow_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,55 @@ func TestLogin_ssh(t *testing.T) {
101101
assert.Equal(t, "ATOKEN", cfg["example.com:oauth_token"])
102102
assert.Equal(t, "ssh", cfg["example.com:git_protocol"])
103103
}
104+
105+
func Test_scopesSentence(t *testing.T) {
106+
type args struct {
107+
scopes []string
108+
isEnterprise bool
109+
}
110+
tests := []struct {
111+
name string
112+
args args
113+
want string
114+
}{
115+
{
116+
name: "basic scopes",
117+
args: args{
118+
scopes: []string{"repo", "read:org"},
119+
isEnterprise: false,
120+
},
121+
want: "'repo', 'read:org'",
122+
},
123+
{
124+
name: "empty",
125+
args: args{
126+
scopes: []string(nil),
127+
isEnterprise: false,
128+
},
129+
want: "",
130+
},
131+
{
132+
name: "workflow scope for dotcom",
133+
args: args{
134+
scopes: []string{"repo", "workflow"},
135+
isEnterprise: false,
136+
},
137+
want: "'repo', 'workflow'",
138+
},
139+
{
140+
name: "workflow scope for GHE",
141+
args: args{
142+
scopes: []string{"repo", "workflow"},
143+
isEnterprise: true,
144+
},
145+
want: "'repo', 'workflow' (GHE 3.0+)",
146+
},
147+
}
148+
for _, tt := range tests {
149+
t.Run(tt.name, func(t *testing.T) {
150+
if got := scopesSentence(tt.args.scopes, tt.args.isEnterprise); got != tt.want {
151+
t.Errorf("scopesSentence() = %q, want %q", got, tt.want)
152+
}
153+
})
154+
}
155+
}

0 commit comments

Comments
 (0)
X Tutup