Skip to content

Commit da2116f

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr-create-push-default
2 parents 5726376 + 0432419 commit da2116f

File tree

17 files changed

+675
-251
lines changed

17 files changed

+675
-251
lines changed

api/pull_request_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func TestPullRequest_ChecksStatus(t *testing.T) {
2222
{ "status": "COMPLETED",
2323
"conclusion": "FAILURE" },
2424
{ "status": "COMPLETED",
25-
"conclusion": "ACTION_REQUIRED" }
25+
"conclusion": "ACTION_REQUIRED" },
26+
{ "status": "COMPLETED",
27+
"conclusion": "STALE" }
2628
]
2729
}
2830
}
@@ -32,8 +34,8 @@ func TestPullRequest_ChecksStatus(t *testing.T) {
3234
eq(t, err, nil)
3335

3436
checks := pr.ChecksStatus()
35-
eq(t, checks.Total, 7)
36-
eq(t, checks.Pending, 2)
37+
eq(t, checks.Total, 8)
38+
eq(t, checks.Pending, 3)
3739
eq(t, checks.Failing, 3)
3840
eq(t, checks.Passing, 2)
3941
}

api/queries_pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
120120
summary.Passing++
121121
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
122122
summary.Failing++
123-
case "EXPECTED", "REQUESTED", "QUEUED", "PENDING", "IN_PROGRESS":
123+
case "EXPECTED", "REQUESTED", "QUEUED", "PENDING", "IN_PROGRESS", "STALE":
124124
summary.Pending++
125125
default:
126126
panic(fmt.Errorf("unsupported status: %q", state))

api/queries_repo.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"bytes"
5+
"encoding/base64"
56
"encoding/json"
67
"errors"
78
"fmt"
@@ -10,16 +11,18 @@ import (
1011
"time"
1112

1213
"github.com/cli/cli/internal/ghrepo"
14+
"github.com/cli/cli/utils"
1315
)
1416

1517
// Repository contains information about a GitHub repo
1618
type Repository struct {
17-
ID string
18-
Name string
19-
URL string
20-
CloneURL string
21-
CreatedAt time.Time
22-
Owner RepositoryOwner
19+
ID string
20+
Name string
21+
Description string
22+
URL string
23+
CloneURL string
24+
CreatedAt time.Time
25+
Owner RepositoryOwner
2326

2427
IsPrivate bool
2528
HasIssuesEnabled bool
@@ -70,6 +73,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
7073
repository(owner: $owner, name: $name) {
7174
id
7275
hasIssuesEnabled
76+
description
7377
}
7478
}`
7579
variables := map[string]interface{}{
@@ -323,3 +327,43 @@ func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error) {
323327

324328
return &response.CreateRepository.Repository, nil
325329
}
330+
331+
func RepositoryReadme(client *Client, fullName string) (string, error) {
332+
type readmeResponse struct {
333+
Name string
334+
Content string
335+
}
336+
337+
var readme readmeResponse
338+
339+
err := client.REST("GET", fmt.Sprintf("repos/%s/readme", fullName), nil, &readme)
340+
if err != nil && !strings.HasSuffix(err.Error(), "'Not Found'") {
341+
return "", fmt.Errorf("could not get readme for repo: %w", err)
342+
}
343+
344+
decoded, err := base64.StdEncoding.DecodeString(readme.Content)
345+
if err != nil {
346+
return "", fmt.Errorf("failed to decode readme: %w", err)
347+
}
348+
349+
readmeContent := string(decoded)
350+
351+
if isMarkdownFile(readme.Name) {
352+
readmeContent, err = utils.RenderMarkdown(readmeContent)
353+
if err != nil {
354+
return "", fmt.Errorf("failed to render readme as markdown: %w", err)
355+
}
356+
}
357+
358+
return readmeContent, nil
359+
360+
}
361+
362+
func isMarkdownFile(filename string) bool {
363+
// kind of gross, but i'm assuming that 90% of the time the suffix will just be .md. it didn't
364+
// seem worth executing a regex for this given that assumption.
365+
return strings.HasSuffix(filename, ".md") ||
366+
strings.HasSuffix(filename, ".markdown") ||
367+
strings.HasSuffix(filename, ".mdown") ||
368+
strings.HasSuffix(filename, ".mkdown")
369+
}

command/issue.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func init() {
3838
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
3939

4040
issueCmd.AddCommand(issueViewCmd)
41-
issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
41+
issueViewCmd.Flags().BoolP("web", "w", false, "Open issue in browser")
4242
}
4343

4444
var issueCmd = &cobra.Command{
@@ -73,7 +73,7 @@ var issueViewCmd = &cobra.Command{
7373
}
7474
return nil
7575
},
76-
Short: "View an issue in the browser",
76+
Short: "View an issue",
7777
RunE: issueView,
7878
}
7979

@@ -213,17 +213,17 @@ func issueView(cmd *cobra.Command, args []string) error {
213213
}
214214
openURL := issue.URL
215215

216-
preview, err := cmd.Flags().GetBool("preview")
216+
web, err := cmd.Flags().GetBool("web")
217217
if err != nil {
218218
return err
219219
}
220220

221-
if preview {
222-
out := colorableOut(cmd)
223-
return printIssuePreview(out, issue)
224-
} else {
221+
if web {
225222
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL)
226223
return utils.OpenInBrowser(openURL)
224+
} else {
225+
out := colorableOut(cmd)
226+
return printIssuePreview(out, issue)
227227
}
228228

229229
}

command/issue_test.go

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func TestIssueList_disabledIssues(t *testing.T) {
216216
}
217217
}
218218

219-
func TestIssueView(t *testing.T) {
219+
func TestIssueView_web(t *testing.T) {
220220
initBlankContext("OWNER/REPO", "master")
221221
http := initFakeHTTP()
222222
http.StubRepoResponse("OWNER", "REPO")
@@ -235,7 +235,7 @@ func TestIssueView(t *testing.T) {
235235
})
236236
defer restoreCmd()
237237

238-
output, err := RunCommand(issueViewCmd, "issue view 123")
238+
output, err := RunCommand(issueViewCmd, "issue view -w 123")
239239
if err != nil {
240240
t.Errorf("error running command `issue view`: %v", err)
241241
}
@@ -250,7 +250,7 @@ func TestIssueView(t *testing.T) {
250250
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
251251
}
252252

253-
func TestIssueView_numberArgWithHash(t *testing.T) {
253+
func TestIssueView_web_numberArgWithHash(t *testing.T) {
254254
initBlankContext("OWNER/REPO", "master")
255255
http := initFakeHTTP()
256256
http.StubRepoResponse("OWNER", "REPO")
@@ -269,7 +269,7 @@ func TestIssueView_numberArgWithHash(t *testing.T) {
269269
})
270270
defer restoreCmd()
271271

272-
output, err := RunCommand(issueViewCmd, "issue view \"#123\"")
272+
output, err := RunCommand(issueViewCmd, "issue view -w \"#123\"")
273273
if err != nil {
274274
t.Errorf("error running command `issue view`: %v", err)
275275
}
@@ -284,7 +284,7 @@ func TestIssueView_numberArgWithHash(t *testing.T) {
284284
eq(t, url, "https://github.com/OWNER/REPO/issues/123")
285285
}
286286

287-
func TestIssueView_preview(t *testing.T) {
287+
func TestIssueView(t *testing.T) {
288288
initBlankContext("OWNER/REPO", "master")
289289
http := initFakeHTTP()
290290
http.StubRepoResponse("OWNER", "REPO")
@@ -309,28 +309,21 @@ func TestIssueView_preview(t *testing.T) {
309309
} } } }
310310
`))
311311

312-
output, err := RunCommand(issueViewCmd, "issue view -p 123")
312+
output, err := RunCommand(issueViewCmd, "issue view 123")
313313
if err != nil {
314314
t.Errorf("error running command `issue view`: %v", err)
315315
}
316316

317317
eq(t, output.Stderr(), "")
318318

319-
expectedLines := []*regexp.Regexp{
320-
regexp.MustCompile(`ix of coins`),
321-
regexp.MustCompile(`opened by marseilles. 9 comments. \(tarot\)`),
322-
regexp.MustCompile(`bold story`),
323-
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
324-
}
325-
for _, r := range expectedLines {
326-
if !r.MatchString(output.String()) {
327-
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
328-
return
329-
}
330-
}
319+
test.ExpectLines(t, output.String(),
320+
"ix of coins",
321+
`opened by marseilles. 9 comments. \(tarot\)`,
322+
"bold story",
323+
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
331324
}
332325

333-
func TestIssueView_previewWithEmptyBody(t *testing.T) {
326+
func TestIssueView_WithEmptyBody(t *testing.T) {
334327
initBlankContext("OWNER/REPO", "master")
335328
http := initFakeHTTP()
336329
http.StubRepoResponse("OWNER", "REPO")
@@ -355,27 +348,20 @@ func TestIssueView_previewWithEmptyBody(t *testing.T) {
355348
} } } }
356349
`))
357350

358-
output, err := RunCommand(issueViewCmd, "issue view -p 123")
351+
output, err := RunCommand(issueViewCmd, "issue view 123")
359352
if err != nil {
360353
t.Errorf("error running command `issue view`: %v", err)
361354
}
362355

363356
eq(t, output.Stderr(), "")
364357

365-
expectedLines := []*regexp.Regexp{
366-
regexp.MustCompile(`ix of coins`),
367-
regexp.MustCompile(`opened by marseilles. 9 comments. \(tarot\)`),
368-
regexp.MustCompile(`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`),
369-
}
370-
for _, r := range expectedLines {
371-
if !r.MatchString(output.String()) {
372-
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
373-
return
374-
}
375-
}
358+
test.ExpectLines(t, output.String(),
359+
"ix of coins",
360+
`opened by marseilles. 9 comments. \(tarot\)`,
361+
"View this issue on GitHub: https://github.com/OWNER/REPO/issues/123")
376362
}
377363

378-
func TestIssueView_notFound(t *testing.T) {
364+
func TestIssueView_web_notFound(t *testing.T) {
379365
initBlankContext("OWNER/REPO", "master")
380366
http := initFakeHTTP()
381367

@@ -392,7 +378,7 @@ func TestIssueView_notFound(t *testing.T) {
392378
})
393379
defer restoreCmd()
394380

395-
_, err := RunCommand(issueViewCmd, "issue view 9999")
381+
_, err := RunCommand(issueViewCmd, "issue view -w 9999")
396382
if err == nil || err.Error() != "graphql error: 'Could not resolve to an Issue with the number of 9999.'" {
397383
t.Errorf("error running command `issue view`: %v", err)
398384
}
@@ -420,7 +406,7 @@ func TestIssueView_disabledIssues(t *testing.T) {
420406
}
421407
}
422408

423-
func TestIssueView_urlArg(t *testing.T) {
409+
func TestIssueView_web_urlArg(t *testing.T) {
424410
initBlankContext("OWNER/REPO", "master")
425411
http := initFakeHTTP()
426412
http.StubRepoResponse("OWNER", "REPO")
@@ -439,7 +425,7 @@ func TestIssueView_urlArg(t *testing.T) {
439425
})
440426
defer restoreCmd()
441427

442-
output, err := RunCommand(issueViewCmd, "issue view https://github.com/OWNER/REPO/issues/123")
428+
output, err := RunCommand(issueViewCmd, "issue view -w https://github.com/OWNER/REPO/issues/123")
443429
if err != nil {
444430
t.Errorf("error running command `issue view`: %v", err)
445431
}

0 commit comments

Comments
 (0)