-
Couldn't load subscription status.
- Fork 7.3k
Show the state (open, closed, merged) in issue view and pr view #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+500
−159
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
94a1e6a
Add 'state' and 'createdAt' to the query for IssueByNumber
doi-t d429bab
Add 'state' to queries for pull requests
doi-t faa4bed
Move colorFuncForState for a PR/issue state to the utils package
doi-t caf26e4
Show the issue state for viewing issues in CLI
doi-t b8edb9f
Show the PR state for viewing PRs in CLI
doi-t e0bfd67
Fix tests for preview messages with a issue/PR state
doi-t 0475cf0
Extract test fixtures for 'issue view --preview'
doi-t 8cd6932
Add a test for the closed issue preview
doi-t 5a23113
Add tests for the Closed/Merged PR preview
doi-t c8a72c3
Add a test for viewing an issue without labels in CLI
doi-t 9a6026e
Format PR/Issue states with color
doi-t e85259d
Remove labels from the issue preview header
doi-t 46a632c
Fix utility function scopes
doi-t 0cfa4be
Add tests for utilities of PR/issue state format
doi-t 7b5a0b5
Add a missing isDraft for querying PR by number
doi-t 762e806
Add tests for viewing a Draft PR in CLI
doi-t 7ceffd0
Merge branch 'master' into view-the-current-state
doi-t cf69d7e
Add test fixtures for viewing Draft state in CLI
doi-t e50ba54
Rename OPEN state to Draft for a Draft PR
doi-t 327a804
Fix tests to support the "Draft" state badge
doi-t a5bd313
Cleanup
doi-t 1a5e9f1
Apply table driven testing for pr/issue preview commands
doi-t 0ba0a07
Merge branch 'master' into view-the-current-state
doi-t 7d42f46
Merge branch 'master' into view-the-current-state
doi-t 0095fe9
Merge branch 'master' into view-the-current-state
doi-t 4c2f15f
Roll back the place of colorFuncForState
doi-t 7eabbf5
Simplify expected output definitions with new line testing helper
doi-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(), "") | ||
|
|
||
| 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") | ||
| } | ||
| jsonFile, _ := os.Open(tc.fixture) | ||
| defer jsonFile.Close() | ||
| http.StubResponse(200, jsonFile) | ||
|
|
||
| func TestIssueView_WithEmptyBody(t *testing.T) { | ||
| initBlankContext("OWNER/REPO", "master") | ||
| http := initFakeHTTP() | ||
| http.StubRepoResponse("OWNER", "REPO") | ||
| output, err := RunCommand(issueViewCmd, tc.command) | ||
| if err != nil { | ||
| t.Errorf("error running command `%v`: %v", tc.command, err) | ||
| } | ||
|
|
||
| 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" | ||
| } } } } | ||
| `)) | ||
| eq(t, output.Stderr(), "") | ||
|
|
||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL go-cmp! 🏆 |
||
| if diff != "" { | ||
| t.Fatalf(diff) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Massive props for table-driven test 🥇