Skip to content

Commit 265db26

Browse files
committed
Merge remote-tracking branch 'origin/master' into detect-existing-fork
2 parents 965f270 + 988d36d commit 265db26

File tree

12 files changed

+373
-205
lines changed

12 files changed

+373
-205
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,23 +2,26 @@ package api
22

33
import (
44
"bytes"
5+
"encoding/base64"
56
"encoding/json"
67
"fmt"
78
"sort"
89
"strings"
910
"time"
1011

1112
"github.com/cli/cli/internal/ghrepo"
13+
"github.com/cli/cli/utils"
1214
)
1315

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

2326
IsPrivate bool
2427
HasIssuesEnabled bool
@@ -69,6 +72,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
6972
repository(owner: $owner, name: $name) {
7073
id
7174
hasIssuesEnabled
75+
description
7276
}
7377
}`
7478
variables := map[string]interface{}{
@@ -279,3 +283,43 @@ func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error) {
279283

280284
return &response.CreateRepository.Repository, nil
281285
}
286+
287+
func RepositoryReadme(client *Client, fullName string) (string, error) {
288+
type readmeResponse struct {
289+
Name string
290+
Content string
291+
}
292+
293+
var readme readmeResponse
294+
295+
err := client.REST("GET", fmt.Sprintf("repos/%s/readme", fullName), nil, &readme)
296+
if err != nil && !strings.HasSuffix(err.Error(), "'Not Found'") {
297+
return "", fmt.Errorf("could not get readme for repo: %w", err)
298+
}
299+
300+
decoded, err := base64.StdEncoding.DecodeString(readme.Content)
301+
if err != nil {
302+
return "", fmt.Errorf("failed to decode readme: %w", err)
303+
}
304+
305+
readmeContent := string(decoded)
306+
307+
if isMarkdownFile(readme.Name) {
308+
readmeContent, err = utils.RenderMarkdown(readmeContent)
309+
if err != nil {
310+
return "", fmt.Errorf("failed to render readme as markdown: %w", err)
311+
}
312+
}
313+
314+
return readmeContent, nil
315+
316+
}
317+
318+
func isMarkdownFile(filename string) bool {
319+
// kind of gross, but i'm assuming that 90% of the time the suffix will just be .md. it didn't
320+
// seem worth executing a regex for this given that assumption.
321+
return strings.HasSuffix(filename, ".md") ||
322+
strings.HasSuffix(filename, ".markdown") ||
323+
strings.HasSuffix(filename, ".mdown") ||
324+
strings.HasSuffix(filename, ".mkdown")
325+
}

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)