X Tutup
Skip to content

Commit 51eb2cb

Browse files
author
Nate Smith
authored
Merge branch 'master' into pr-count
2 parents f51669e + 3334bdd commit 51eb2cb

18 files changed

+776
-270
lines changed

auth/oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
4747

4848
q := url.Values{}
4949
q.Set("client_id", oa.ClientID)
50-
q.Set("redirect_uri", fmt.Sprintf("http://localhost:%d/callback", port))
50+
q.Set("redirect_uri", fmt.Sprintf("http://127.0.0.1:%d/callback", port))
5151
// TODO: make scopes configurable
5252
q.Set("scope", "repo")
5353
q.Set("state", state)

command/issue.go

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/cli/cli/git"
1515
"github.com/cli/cli/internal/ghrepo"
1616
"github.com/cli/cli/pkg/githubtemplate"
17-
"github.com/cli/cli/pkg/text"
1817
"github.com/cli/cli/utils"
1918
"github.com/spf13/cobra"
2019
"github.com/spf13/pflag"
@@ -133,22 +132,8 @@ func issueList(cmd *cobra.Command, args []string) error {
133132
fmt.Fprintf(colorableErr(cmd), "\n%s\n\n", title)
134133

135134
out := cmd.OutOrStdout()
136-
table := utils.NewTablePrinter(out)
137-
for _, issue := range listResult.Issues {
138-
issueNum := strconv.Itoa(issue.Number)
139-
if table.IsTTY() {
140-
issueNum = "#" + issueNum
141-
}
142-
labels := labelList(issue)
143-
if labels != "" && table.IsTTY() {
144-
labels = fmt.Sprintf("(%s)", labels)
145-
}
146-
table.AddField(issueNum, nil, colorFuncForState(issue.State))
147-
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
148-
table.AddField(labels, nil, utils.Gray)
149-
table.EndRow()
150-
}
151-
table.Render()
135+
136+
printIssues(out, "", len(listResult.Issues), listResult.Issues)
152137

153138
return nil
154139
}
@@ -372,7 +357,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
372357
interactive := title == "" || body == ""
373358

374359
if interactive {
375-
tb, err := titleBodySurvey(cmd, title, body, templateFiles)
360+
tb, err := titleBodySurvey(cmd, title, body, defaults{}, templateFiles)
376361
if err != nil {
377362
return fmt.Errorf("could not collect title and/or body: %w", err)
378363
}
@@ -423,21 +408,26 @@ func issueCreate(cmd *cobra.Command, args []string) error {
423408
}
424409

425410
func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) {
411+
table := utils.NewTablePrinter(w)
426412
for _, issue := range issues {
427-
number := utils.Green("#" + strconv.Itoa(issue.Number))
428-
coloredLabels := labelList(issue)
429-
if coloredLabels != "" {
430-
coloredLabels = utils.Gray(fmt.Sprintf(" (%s)", coloredLabels))
413+
issueNum := strconv.Itoa(issue.Number)
414+
if table.IsTTY() {
415+
issueNum = "#" + issueNum
416+
}
417+
issueNum = prefix + issueNum
418+
labels := labelList(issue)
419+
if labels != "" && table.IsTTY() {
420+
labels = fmt.Sprintf("(%s)", labels)
431421
}
432-
433422
now := time.Now()
434423
ago := now.Sub(issue.UpdatedAt)
435-
436-
fmt.Fprintf(w, "%s%s %s%s %s\n", prefix, number,
437-
text.Truncate(70, replaceExcessiveWhitespace(issue.Title)),
438-
coloredLabels,
439-
utils.Gray(utils.FuzzyAgo(ago)))
424+
table.AddField(issueNum, nil, colorFuncForState(issue.State))
425+
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
426+
table.AddField(labels, nil, utils.Gray)
427+
table.AddField(utils.FuzzyAgo(ago), nil, utils.Gray)
428+
table.EndRow()
440429
}
430+
table.Render()
441431
remaining := totalCount - len(issues)
442432
if remaining > 0 {
443433
fmt.Fprintf(w, utils.Gray("%sAnd %d more\n"), prefix, remaining)

command/issue_test.go

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

13+
"github.com/cli/cli/test"
1314
"github.com/cli/cli/utils"
1415
)
1516

@@ -28,10 +29,10 @@ func TestIssueStatus(t *testing.T) {
2829
}
2930

3031
expectedIssues := []*regexp.Regexp{
31-
regexp.MustCompile(`#8.*carrots`),
32-
regexp.MustCompile(`#9.*squash`),
33-
regexp.MustCompile(`#10.*broccoli`),
34-
regexp.MustCompile(`#11.*swiss chard`),
32+
regexp.MustCompile(`(?m)8.*carrots.*about.*ago`),
33+
regexp.MustCompile(`(?m)9.*squash.*about.*ago`),
34+
regexp.MustCompile(`(?m)10.*broccoli.*about.*ago`),
35+
regexp.MustCompile(`(?m)11.*swiss chard.*about.*ago`),
3536
}
3637

3738
for _, r := range expectedIssues {
@@ -230,7 +231,7 @@ func TestIssueView(t *testing.T) {
230231
var seenCmd *exec.Cmd
231232
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
232233
seenCmd = cmd
233-
return &outputStub{}
234+
return &test.OutputStub{}
234235
})
235236
defer restoreCmd()
236237

@@ -264,7 +265,7 @@ func TestIssueView_numberArgWithHash(t *testing.T) {
264265
var seenCmd *exec.Cmd
265266
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
266267
seenCmd = cmd
267-
return &outputStub{}
268+
return &test.OutputStub{}
268269
})
269270
defer restoreCmd()
270271

@@ -387,7 +388,7 @@ func TestIssueView_notFound(t *testing.T) {
387388
var seenCmd *exec.Cmd
388389
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
389390
seenCmd = cmd
390-
return &outputStub{}
391+
return &test.OutputStub{}
391392
})
392393
defer restoreCmd()
393394

@@ -434,7 +435,7 @@ func TestIssueView_urlArg(t *testing.T) {
434435
var seenCmd *exec.Cmd
435436
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
436437
seenCmd = cmd
437-
return &outputStub{}
438+
return &test.OutputStub{}
438439
})
439440
defer restoreCmd()
440441

@@ -519,7 +520,7 @@ func TestIssueCreate_web(t *testing.T) {
519520
var seenCmd *exec.Cmd
520521
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
521522
seenCmd = cmd
522-
return &outputStub{}
523+
return &test.OutputStub{}
523524
})
524525
defer restoreCmd()
525526

@@ -545,7 +546,7 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
545546
var seenCmd *exec.Cmd
546547
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
547548
seenCmd = cmd
548-
return &outputStub{}
549+
return &test.OutputStub{}
549550
})
550551
defer restoreCmd()
551552

command/pr.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ func prStatus(cmd *cobra.Command, args []string) error {
8181
return err
8282
}
8383

84+
repoOverride, _ := cmd.Flags().GetString("repo")
8485
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
85-
if err != nil {
86+
if err != nil && repoOverride == "" && err.Error() != "git: not on any branch" {
8687
return err
8788
}
8889

@@ -100,6 +101,8 @@ func prStatus(cmd *cobra.Command, args []string) error {
100101
printHeader(out, "Current branch")
101102
if prPayload.CurrentPR != nil {
102103
printPrs(out, 0, *prPayload.CurrentPR)
104+
} else if currentPRHeadRef == "" {
105+
printMessage(out, " There is no current branch")
103106
} else {
104107
message := fmt.Sprintf(" There is no pull request associated with %s", utils.Cyan("["+currentPRHeadRef+"]"))
105108
printMessage(out, message)

command/pr_checkout_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/cli/cli/context"
10+
"github.com/cli/cli/test"
1011
"github.com/cli/cli/utils"
1112
)
1213

@@ -46,7 +47,7 @@ func TestPRCheckout_sameRepo(t *testing.T) {
4647
return &errorStub{"exit status: 1"}
4748
default:
4849
ranCommands = append(ranCommands, cmd.Args)
49-
return &outputStub{}
50+
return &test.OutputStub{}
5051
}
5152
})
5253
defer restoreCmd()
@@ -98,7 +99,7 @@ func TestPRCheckout_urlArg(t *testing.T) {
9899
return &errorStub{"exit status: 1"}
99100
default:
100101
ranCommands = append(ranCommands, cmd.Args)
101-
return &outputStub{}
102+
return &test.OutputStub{}
102103
}
103104
})
104105
defer restoreCmd()
@@ -147,7 +148,7 @@ func TestPRCheckout_branchArg(t *testing.T) {
147148
return &errorStub{"exit status: 1"}
148149
default:
149150
ranCommands = append(ranCommands, cmd.Args)
150-
return &outputStub{}
151+
return &test.OutputStub{}
151152
}
152153
})
153154
defer restoreCmd()
@@ -193,10 +194,10 @@ func TestPRCheckout_existingBranch(t *testing.T) {
193194
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
194195
switch strings.Join(cmd.Args, " ") {
195196
case "git show-ref --verify --quiet refs/heads/feature":
196-
return &outputStub{}
197+
return &test.OutputStub{}
197198
default:
198199
ranCommands = append(ranCommands, cmd.Args)
199-
return &outputStub{}
200+
return &test.OutputStub{}
200201
}
201202
})
202203
defer restoreCmd()
@@ -248,7 +249,7 @@ func TestPRCheckout_differentRepo_remoteExists(t *testing.T) {
248249
return &errorStub{"exit status: 1"}
249250
default:
250251
ranCommands = append(ranCommands, cmd.Args)
251-
return &outputStub{}
252+
return &test.OutputStub{}
252253
}
253254
})
254255
defer restoreCmd()
@@ -300,7 +301,7 @@ func TestPRCheckout_differentRepo(t *testing.T) {
300301
return &errorStub{"exit status 1"}
301302
default:
302303
ranCommands = append(ranCommands, cmd.Args)
303-
return &outputStub{}
304+
return &test.OutputStub{}
304305
}
305306
})
306307
defer restoreCmd()
@@ -349,10 +350,10 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
349350
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
350351
switch strings.Join(cmd.Args, " ") {
351352
case "git config branch.feature.merge":
352-
return &outputStub{[]byte("refs/heads/feature\n")}
353+
return &test.OutputStub{[]byte("refs/heads/feature\n")}
353354
default:
354355
ranCommands = append(ranCommands, cmd.Args)
355-
return &outputStub{}
356+
return &test.OutputStub{}
356357
}
357358
})
358359
defer restoreCmd()
@@ -399,10 +400,10 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
399400
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
400401
switch strings.Join(cmd.Args, " ") {
401402
case "git config branch.feature.merge":
402-
return &outputStub{[]byte("refs/heads/feature\n")}
403+
return &test.OutputStub{[]byte("refs/heads/feature\n")}
403404
default:
404405
ranCommands = append(ranCommands, cmd.Args)
405-
return &outputStub{}
406+
return &test.OutputStub{}
406407
}
407408
})
408409
defer restoreCmd()
@@ -452,7 +453,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
452453
return &errorStub{"exit status 1"}
453454
default:
454455
ranCommands = append(ranCommands, cmd.Args)
455-
return &outputStub{}
456+
return &test.OutputStub{}
456457
}
457458
})
458459
defer restoreCmd()

0 commit comments

Comments
 (0)
X Tutup