diff --git a/api/queries_issue.go b/api/queries_issue.go index ae27878a6..2c2010307 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -24,6 +24,7 @@ type Issue struct { URL string State string Body string + CreatedAt time.Time UpdatedAt time.Time Comments struct { TotalCount int @@ -278,6 +279,7 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e hasIssuesEnabled issue(number: $issue_number) { title + state body author { login @@ -292,6 +294,7 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e } number url + createdAt } } }` diff --git a/api/queries_pr.go b/api/queries_pr.go index 0f11f4392..905bd2066 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -301,6 +301,7 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu url number title + state body author { login @@ -320,6 +321,7 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu } } isCrossRepository + isDraft maintainerCanModify } } @@ -356,6 +358,7 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea nodes { number title + state body author { login diff --git a/command/issue.go b/command/issue.go index 1b747c6e6..9e57556e1 100644 --- a/command/issue.go +++ b/command/issue.go @@ -228,6 +228,11 @@ func issueView(cmd *cobra.Command, args []string) error { } +func issueStateTitleWithColor(state string) string { + colorFunc := colorFuncForState(state) + return colorFunc(strings.Title(strings.ToLower(state))) +} + func listHeader(repoName string, itemName string, matchCount int, totalMatchCount int, hasFilters bool) string { if totalMatchCount == 0 { if hasFilters { @@ -248,17 +253,16 @@ func listHeader(repoName string, itemName string, matchCount int, totalMatchCoun } func printIssuePreview(out io.Writer, issue *api.Issue) error { - coloredLabels := labelList(*issue) - if coloredLabels != "" { - coloredLabels = utils.Gray(fmt.Sprintf("(%s)", coloredLabels)) - } + now := time.Now() + ago := now.Sub(issue.CreatedAt) fmt.Fprintln(out, utils.Bold(issue.Title)) + fmt.Fprintf(out, "%s", issueStateTitleWithColor(issue.State)) fmt.Fprintln(out, utils.Gray(fmt.Sprintf( - "opened by %s. %s. %s", + " • %s opened %s • %s", issue.Author.Login, + utils.FuzzyAgo(ago), utils.Pluralize(issue.Comments.TotalCount, "comment"), - coloredLabels, ))) if issue.Body != "" { diff --git a/command/issue_test.go b/command/issue_test.go index 4c1826d4b..099f80f17 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -12,6 +12,7 @@ import ( "github.com/cli/cli/internal/run" "github.com/cli/cli/test" + "github.com/google/go-cmp/cmp" ) func TestIssueStatus(t *testing.T) { @@ -284,81 +285,77 @@ func TestIssueView_web_numberArgWithHash(t *testing.T) { eq(t, url, "https://github.com/OWNER/REPO/issues/123") } -func TestIssueView(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") - - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { "hasIssuesEnabled": true, "issue": { - "number": 123, - "body": "**bold story**", - "title": "ix of coins", - "author": { - "login": "marseilles" +func TestIssueView_Preview(t *testing.T) { + tests := map[string]struct { + ownerRepo string + command string + fixture string + expectedOutputs []string + }{ + "Open issue": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_preview.json", + expectedOutputs: []string{ + "ix of coins", + "Open • marseilles opened about 292 years ago • 9 comments", + "bold story", + "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + }, }, - "labels": { - "nodes": [ - {"name": "tarot"} - ] + "Open issue with no label": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_previewNoLabel.json", + expectedOutputs: []string{ + "ix of coins", + "Open • marseilles opened about 292 years ago • 9 comments", + "bold story", + "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + }, }, - "comments": { - "totalCount": 9 + "Open issue with empty body": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_previewWithEmptyBody.json", + expectedOutputs: []string{ + "ix of coins", + "Open • marseilles opened about 292 years ago • 9 comments", + "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + }, + }, + "Closed issue": { + ownerRepo: "master", + command: "issue view 123", + fixture: "../test/fixtures/issueView_previewClosedState.json", + expectedOutputs: []string{ + "ix of coins", + "Closed • marseilles opened about 292 years ago • 9 comments", + "bold story", + "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123", + }, }, - "url": "https://github.com/OWNER/REPO/issues/123" - } } } } - `)) - - output, err := RunCommand(issueViewCmd, "issue view 123") - if err != nil { - t.Errorf("error running command `issue view`: %v", err) } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + initBlankContext("OWNER/REPO", tc.ownerRepo) + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") - eq(t, output.Stderr(), "") + jsonFile, _ := os.Open(tc.fixture) + defer jsonFile.Close() + http.StubResponse(200, jsonFile) - test.ExpectLines(t, output.String(), - "ix of coins", - `opened by marseilles. 9 comments. \(tarot\)`, - "bold story", - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123") -} + output, err := RunCommand(issueViewCmd, tc.command) + if err != nil { + t.Errorf("error running command `%v`: %v", tc.command, err) + } -func TestIssueView_WithEmptyBody(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") + eq(t, output.Stderr(), "") - http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { "hasIssuesEnabled": true, "issue": { - "number": 123, - "body": "", - "title": "ix of coins", - "author": { - "login": "marseilles" - }, - "labels": { - "nodes": [ - {"name": "tarot"} - ] - }, - "comments": { - "totalCount": 9 - }, - "url": "https://github.com/OWNER/REPO/issues/123" - } } } } - `)) - - output, err := RunCommand(issueViewCmd, "issue view 123") - if err != nil { - t.Errorf("error running command `issue view`: %v", err) + test.ExpectLines(t, output.String(), tc.expectedOutputs...) + }) } - - eq(t, output.Stderr(), "") - - test.ExpectLines(t, output.String(), - "ix of coins", - `opened by marseilles. 9 comments. \(tarot\)`, - "View this issue on GitHub: https://github.com/OWNER/REPO/issues/123") } func TestIssueView_web_notFound(t *testing.T) { @@ -659,3 +656,23 @@ func Test_listHeader(t *testing.T) { }) } } + +func TestIssueStateTitleWithColor(t *testing.T) { + tests := map[string]struct { + state string + want string + }{ + "Open state": {state: "OPEN", want: "Open"}, + "Closed state": {state: "CLOSED", want: "Closed"}, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + got := issueStateTitleWithColor(tc.state) + diff := cmp.Diff(tc.want, got) + if diff != "" { + t.Fatalf(diff) + } + }) + } +} diff --git a/command/pr.go b/command/pr.go index 7c8799248..e494d88b5 100644 --- a/command/pr.go +++ b/command/pr.go @@ -226,14 +226,22 @@ func prList(cmd *cobra.Command, args []string) error { return nil } +func prStateTitleWithColor(pr api.PullRequest) string { + prStateColorFunc := colorFuncForPR(pr) + if pr.State == "OPEN" && pr.IsDraft { + return prStateColorFunc(strings.Title(strings.ToLower("Draft"))) + } + return prStateColorFunc(strings.Title(strings.ToLower(pr.State))) +} + func colorFuncForPR(pr api.PullRequest) func(string) string { if pr.State == "OPEN" && pr.IsDraft { return utils.Gray - } else { - return colorFuncForState(pr.State) } + return colorFuncForState(pr.State) } +// colorFuncForState returns a color function for a PR/Issue state func colorFuncForState(state string) func(string) string { switch state { case "OPEN": @@ -320,8 +328,9 @@ func prView(cmd *cobra.Command, args []string) error { func printPrPreview(out io.Writer, pr *api.PullRequest) error { fmt.Fprintln(out, utils.Bold(pr.Title)) + fmt.Fprintf(out, "%s", prStateTitleWithColor(*pr)) fmt.Fprintln(out, utils.Gray(fmt.Sprintf( - "%s wants to merge %s into %s from %s", + " • %s wants to merge %s into %s from %s", pr.Author.Login, utils.Pluralize(pr.Commits.TotalCount, "commit"), pr.BaseRefName, @@ -453,8 +462,7 @@ func printPrs(w io.Writer, totalCount int, prs ...api.PullRequest) { fmt.Fprint(w, utils.Green("✓ Approved")) } } else { - s := strings.Title(strings.ToLower(pr.State)) - fmt.Fprintf(w, " - %s", prStateColorFunc(s)) + fmt.Fprintf(w, " - %s", prStateTitleWithColor(pr)) } fmt.Fprint(w, "\n") diff --git a/command/pr_test.go b/command/pr_test.go index 78c5672b0..db9fd5fd0 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -11,8 +11,10 @@ import ( "strings" "testing" + "github.com/cli/cli/api" "github.com/cli/cli/internal/run" "github.com/cli/cli/test" + "github.com/google/go-cmp/cmp" "github.com/google/shlex" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -400,82 +402,111 @@ func TestPRList_filteringAssigneeLabels(t *testing.T) { } } -func TestPRView_preview(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") - - jsonFile, _ := os.Open("../test/fixtures/prViewPreview.json") - defer jsonFile.Close() - http.StubResponse(200, jsonFile) - - output, err := RunCommand(prViewCmd, "pr view 12") - if err != nil { - t.Errorf("error running command `pr view`: %v", err) +func TestPRView_Preview(t *testing.T) { + tests := map[string]struct { + ownerRepo string + args string + fixture string + expectedOutputs []string + }{ + "Open PR": { + ownerRepo: "master", + args: "pr view 12", + fixture: "../test/fixtures/prViewPreview.json", + expectedOutputs: []string{ + "Blueberries are from a fork", + "Open • nobody wants to merge 12 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12", + }, + }, + "Open PR for the current branch": { + ownerRepo: "blueberries", + args: "pr view", + fixture: "../test/fixtures/prView.json", + expectedOutputs: []string{ + "Blueberries are a good fruit", + "Open • nobody wants to merge 8 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10", + }, + }, + "Open PR wth empty body for the current branch": { + ownerRepo: "blueberries", + args: "pr view", + fixture: "../test/fixtures/prView_EmptyBody.json", + expectedOutputs: []string{ + "Blueberries are a good fruit", + "Open • nobody wants to merge 8 commits into master from blueberries", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10", + }, + }, + "Closed PR": { + ownerRepo: "master", + args: "pr view 12", + fixture: "../test/fixtures/prViewPreviewClosedState.json", + expectedOutputs: []string{ + "Blueberries are from a fork", + "Closed • nobody wants to merge 12 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12", + }, + }, + "Merged PR": { + ownerRepo: "master", + args: "pr view 12", + fixture: "../test/fixtures/prViewPreviewMergedState.json", + expectedOutputs: []string{ + "Blueberries are from a fork", + "Merged • nobody wants to merge 12 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12", + }, + }, + "Draft PR": { + ownerRepo: "master", + args: "pr view 12", + fixture: "../test/fixtures/prViewPreviewDraftState.json", + expectedOutputs: []string{ + "Blueberries are from a fork", + "Draft • nobody wants to merge 12 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12", + }, + }, + "Draft PR by branch": { + ownerRepo: "master", + args: "pr view blueberries", + fixture: "../test/fixtures/prViewPreviewDraftStatebyBranch.json", + expectedOutputs: []string{ + "Blueberries are a good fruit", + "Draft • nobody wants to merge 8 commits into master from blueberries", + "blueberries taste good", + "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10", + }, + }, } - eq(t, output.Stderr(), "") + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + initBlankContext("OWNER/REPO", tc.ownerRepo) + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") - test.ExpectLines(t, output.String(), - "Blueberries are from a fork", - "nobody wants to merge 12 commits into master from blueberries", - "blueberries taste good", - "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12") -} + jsonFile, _ := os.Open(tc.fixture) + defer jsonFile.Close() + http.StubResponse(200, jsonFile) -func TestPRView_previewCurrentBranch(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") + output, err := RunCommand(prViewCmd, tc.args) + if err != nil { + t.Errorf("error running command `%v`: %v", tc.args, err) + } - jsonFile, _ := os.Open("../test/fixtures/prView.json") - defer jsonFile.Close() - http.StubResponse(200, jsonFile) + eq(t, output.Stderr(), "") - restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable { - return &test.OutputStub{} - }) - defer restoreCmd() - - output, err := RunCommand(prViewCmd, "pr view") - if err != nil { - t.Errorf("error running command `pr view`: %v", err) + test.ExpectLines(t, output.String(), tc.expectedOutputs...) + }) } - - eq(t, output.Stderr(), "") - - test.ExpectLines(t, output.String(), - "Blueberries are a good fruit", - "nobody wants to merge 8 commits into master from blueberries", - "blueberries taste good", - "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10") -} - -func TestPRView_previewCurrentBranchWithEmptyBody(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") - - jsonFile, _ := os.Open("../test/fixtures/prView_EmptyBody.json") - defer jsonFile.Close() - http.StubResponse(200, jsonFile) - - restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable { - return &test.OutputStub{} - }) - defer restoreCmd() - - output, err := RunCommand(prViewCmd, "pr view") - if err != nil { - t.Errorf("error running command `pr view`: %v", err) - } - - eq(t, output.Stderr(), "") - - test.ExpectLines(t, output.String(), - "Blueberries are a good fruit", - "nobody wants to merge 8 commits into master from blueberries", - "View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10") } func TestPRView_web_currentBranch(t *testing.T) { @@ -717,3 +748,25 @@ func TestReplaceExcessiveWhitespace(t *testing.T) { eq(t, replaceExcessiveWhitespace("hello goodbye"), "hello goodbye") eq(t, replaceExcessiveWhitespace(" hello \n goodbye "), "hello goodbye") } + +func TestPrStateTitleWithColor(t *testing.T) { + tests := map[string]struct { + pr api.PullRequest + want string + }{ + "Format OPEN state": {pr: api.PullRequest{State: "OPEN", IsDraft: false}, want: "Open"}, + "Format OPEN state for Draft PR": {pr: api.PullRequest{State: "OPEN", IsDraft: true}, want: "Draft"}, + "Format CLOSED state": {pr: api.PullRequest{State: "CLOSED", IsDraft: false}, want: "Closed"}, + "Format MERGED state": {pr: api.PullRequest{State: "MERGED", IsDraft: false}, want: "Merged"}, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + got := prStateTitleWithColor(tc.pr) + diff := cmp.Diff(tc.want, got) + if diff != "" { + t.Fatalf(diff) + } + }) + } +} diff --git a/go.mod b/go.mod index aab4c58d4..896bfd300 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/briandowns/spinner v1.9.0 github.com/charmbracelet/glamour v0.1.1-0.20200320173916-301d3bcf3058 github.com/dlclark/regexp2 v1.2.0 // indirect + github.com/google/go-cmp v0.2.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/hashicorp/go-version v1.2.0 github.com/henvic/httpretty v0.0.4 diff --git a/go.sum b/go.sum index a5f4af4b9..40379e814 100644 --- a/go.sum +++ b/go.sum @@ -61,6 +61,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f h1:5CjVwnuUcp5adK4gmY6i72gpVFVnZDP2h5TmPScB6u4= github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4= diff --git a/test/fixtures/issueView_preview.json b/test/fixtures/issueView_preview.json new file mode 100644 index 000000000..db971d849 --- /dev/null +++ b/test/fixtures/issueView_preview.json @@ -0,0 +1,28 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + { + "name": "tarot" + } + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/issueView_previewClosedState.json b/test/fixtures/issueView_previewClosedState.json new file mode 100644 index 000000000..978927125 --- /dev/null +++ b/test/fixtures/issueView_previewClosedState.json @@ -0,0 +1,28 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "CLOSED", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + { + "name": "tarot" + } + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/issueView_previewNoLabel.json b/test/fixtures/issueView_previewNoLabel.json new file mode 100644 index 000000000..1891100eb --- /dev/null +++ b/test/fixtures/issueView_previewNoLabel.json @@ -0,0 +1,25 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "**bold story**", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/issueView_previewWithEmptyBody.json b/test/fixtures/issueView_previewWithEmptyBody.json new file mode 100644 index 000000000..6e87a42b6 --- /dev/null +++ b/test/fixtures/issueView_previewWithEmptyBody.json @@ -0,0 +1,28 @@ +{ + "data": { + "repository": { + "hasIssuesEnabled": true, + "issue": { + "number": 123, + "body": "", + "title": "ix of coins", + "state": "OPEN", + "created_at": "2011-01-26T19:01:12Z", + "author": { + "login": "marseilles" + }, + "labels": { + "nodes": [ + { + "name": "tarot" + } + ] + }, + "comments": { + "totalCount": 9 + }, + "url": "https://github.com/OWNER/REPO/issues/123" + } + } + } +} diff --git a/test/fixtures/prStatus.json b/test/fixtures/prStatus.json index d2996b71c..a226663a3 100644 --- a/test/fixtures/prStatus.json +++ b/test/fixtures/prStatus.json @@ -8,8 +8,10 @@ "node": { "number": 10, "title": "Blueberries are a good fruit", + "state": "OPEN", "url": "https://github.com/cli/cli/pull/10", "headRefName": "blueberries", + "isDraft": false, "headRepositoryOwner": { "login": "OWNER" }, @@ -26,8 +28,10 @@ "node": { "number": 8, "title": "Strawberries are not actually berries", + "state": "OPEN", "url": "https://github.com/cli/cli/pull/8", - "headRefName": "strawberries" + "headRefName": "strawberries", + "isDraft": false } } ] @@ -39,16 +43,18 @@ "node": { "number": 9, "title": "Apples are tasty", + "state": "OPEN", "url": "https://github.com/cli/cli/pull/9", - "headRefName": "apples" - } - }, - { + "headRefName": "apples", + "isDraft": false + } }, { "node": { "number": 11, "title": "Figs are my favorite", + "state": "OPEN", "url": "https://github.com/cli/cli/pull/1", - "headRefName": "figs" + "headRefName": "figs", + "isDraft": true } } ] diff --git a/test/fixtures/prStatusFork.json b/test/fixtures/prStatusFork.json index df184aaea..c9a7a5b3a 100644 --- a/test/fixtures/prStatusFork.json +++ b/test/fixtures/prStatusFork.json @@ -8,8 +8,10 @@ "node": { "number": 10, "title": "Blueberries are a good fruit", + "state": "OPEN", "url": "https://github.com/PARENT/REPO/pull/10", "headRefName": "blueberries", + "isDraft": false, "headRepositoryOwner": { "login": "OWNER" }, diff --git a/test/fixtures/prView.json b/test/fixtures/prView.json index 02277d7a5..826f10100 100644 --- a/test/fixtures/prView.json +++ b/test/fixtures/prView.json @@ -6,6 +6,7 @@ { "number": 12, "title": "Blueberries are from a fork", + "state": "OPEN", "body": "yeah", "url": "https://github.com/OWNER/REPO/pull/12", "headRefName": "blueberries", @@ -19,11 +20,13 @@ "author": { "login": "nobody" }, - "isCrossRepository": true + "isCrossRepository": true, + "isDraft": false }, { "number": 10, "title": "Blueberries are a good fruit", + "state": "OPEN", "body": "**blueberries taste good**", "url": "https://github.com/OWNER/REPO/pull/10", "baseRefName": "master", @@ -37,7 +40,8 @@ "commits": { "totalCount": 8 }, - "isCrossRepository": false + "isCrossRepository": false, + "isDraft": false } ] } diff --git a/test/fixtures/prViewPreview.json b/test/fixtures/prViewPreview.json index e40946774..379fd253b 100644 --- a/test/fixtures/prViewPreview.json +++ b/test/fixtures/prViewPreview.json @@ -4,6 +4,7 @@ "pullRequest": { "number": 12, "title": "Blueberries are from a fork", + "state": "OPEN", "body": "**blueberries taste good**", "url": "https://github.com/OWNER/REPO/pull/12", "author": { @@ -17,7 +18,8 @@ "headRepositoryOwner": { "login": "hubot" }, - "isCrossRepository": true + "isCrossRepository": true, + "isDraft": false } } } diff --git a/test/fixtures/prViewPreviewClosedState.json b/test/fixtures/prViewPreviewClosedState.json new file mode 100644 index 000000000..9df2c1038 --- /dev/null +++ b/test/fixtures/prViewPreviewClosedState.json @@ -0,0 +1,25 @@ +{ + "data": { + "repository": { + "pullRequest": { + "number": 12, + "title": "Blueberries are from a fork", + "state": "CLOSED", + "body": "**blueberries taste good**", + "url": "https://github.com/OWNER/REPO/pull/12", + "author": { + "login": "nobody" + }, + "commits": { + "totalCount": 12 + }, + "baseRefName": "master", + "headRefName": "blueberries", + "headRepositoryOwner": { + "login": "hubot" + }, + "isCrossRepository": true + } + } + } +} diff --git a/test/fixtures/prViewPreviewDraftState.json b/test/fixtures/prViewPreviewDraftState.json new file mode 100644 index 000000000..69ab57b11 --- /dev/null +++ b/test/fixtures/prViewPreviewDraftState.json @@ -0,0 +1,26 @@ +{ + "data": { + "repository": { + "pullRequest": { + "number": 12, + "title": "Blueberries are from a fork", + "state": "OPEN", + "body": "**blueberries taste good**", + "url": "https://github.com/OWNER/REPO/pull/12", + "author": { + "login": "nobody" + }, + "commits": { + "totalCount": 12 + }, + "baseRefName": "master", + "headRefName": "blueberries", + "headRepositoryOwner": { + "login": "hubot" + }, + "isCrossRepository": true, + "isDraft": true + } + } + } +} diff --git a/test/fixtures/prViewPreviewDraftStatebyBranch.json b/test/fixtures/prViewPreviewDraftStatebyBranch.json new file mode 100644 index 000000000..c9d0eef59 --- /dev/null +++ b/test/fixtures/prViewPreviewDraftStatebyBranch.json @@ -0,0 +1,50 @@ +{ + "data": { + "repository": { + "pullRequests": { + "nodes": [ + { + "number": 12, + "title": "Blueberries are from a fork", + "state": "OPEN", + "body": "yeah", + "url": "https://github.com/OWNER/REPO/pull/12", + "headRefName": "blueberries", + "baseRefName": "master", + "headRepositoryOwner": { + "login": "hubot" + }, + "commits": { + "totalCount": 12 + }, + "author": { + "login": "nobody" + }, + "isCrossRepository": true, + "isDraft": false + }, + { + "number": 10, + "title": "Blueberries are a good fruit", + "state": "OPEN", + "body": "**blueberries taste good**", + "url": "https://github.com/OWNER/REPO/pull/10", + "baseRefName": "master", + "headRefName": "blueberries", + "author": { + "login": "nobody" + }, + "headRepositoryOwner": { + "login": "OWNER" + }, + "commits": { + "totalCount": 8 + }, + "isCrossRepository": false, + "isDraft": true + } + ] + } + } + } +} diff --git a/test/fixtures/prViewPreviewMergedState.json b/test/fixtures/prViewPreviewMergedState.json new file mode 100644 index 000000000..d62449092 --- /dev/null +++ b/test/fixtures/prViewPreviewMergedState.json @@ -0,0 +1,25 @@ +{ + "data": { + "repository": { + "pullRequest": { + "number": 12, + "title": "Blueberries are from a fork", + "state": "MERGED", + "body": "**blueberries taste good**", + "url": "https://github.com/OWNER/REPO/pull/12", + "author": { + "login": "nobody" + }, + "commits": { + "totalCount": 12 + }, + "baseRefName": "master", + "headRefName": "blueberries", + "headRepositoryOwner": { + "login": "hubot" + }, + "isCrossRepository": true + } + } + } +} diff --git a/test/fixtures/prView_EmptyBody.json b/test/fixtures/prView_EmptyBody.json index 651f49ce0..36fdc308b 100644 --- a/test/fixtures/prView_EmptyBody.json +++ b/test/fixtures/prView_EmptyBody.json @@ -6,6 +6,7 @@ { "number": 12, "title": "Blueberries are from a fork", + "state": "OPEN", "body": "yeah", "url": "https://github.com/OWNER/REPO/pull/12", "headRefName": "blueberries", @@ -24,6 +25,7 @@ { "number": 10, "title": "Blueberries are a good fruit", + "state": "OPEN", "body": "", "url": "https://github.com/OWNER/REPO/pull/10", "baseRefName": "master",