Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@doi-t
Copy link
Contributor

@doi-t doi-t commented Mar 17, 2020

Closes #652

Mostly tests for each state. Changes for the core logics are a few lines in command/issue.go, command/pr.go and GraphQL queries.

Since colors matter, I tried to test PR/Issue states with ansi escape sequence to compare colors along with its string but couldn't figure out an efficient way to do... I might be missing something for it.

Test cases for gh [pr|issue] view --preview

I use (Bullet: U+2022) as a separator. It is a bit ugly in below captures but I think it is my terminal font problem. 💦

  • Open issue
    Screen Shot 2020-03-18 at 6 57 53

  • Closed issue
    Screen Shot 2020-03-18 at 6 59 48

  • Open PR

    • Query by number
      Screen Shot 2020-03-18 at 7 17 05
    • Query by branch name
      Screen Shot 2020-03-18 at 7 17 32
  • Draft PR

    • Query by number
      Screen Shot 2020-03-18 at 7 14 55
    • Query by branch name
      Screen Shot 2020-03-18 at 7 15 07
    • (idea) We could change Open to Draft like below if it is more appropriate
      Screen Shot 2020-03-18 at 9 19 43
  • Closed PR

    • Query by number
      Screen Shot 2020-03-18 at 7 04 47
    • Query by branch name
      Screen Shot 2020-03-18 at 7 20 27
  • Merged PR

    • Query by number
      Screen Shot 2020-03-18 at 7 00 45
    • Query by branch name
      Screen Shot 2020-03-18 at 7 15 45

utils/utils.go Outdated
}

// ColorFuncForState returns a color function for a PR/Issue state
func ColorFuncForState(state string) func(string) string {
Copy link
Contributor Author

@doi-t doi-t Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since colorFuncForState was referenced from both command/issue.go and command/pr.go, I moved it to utils.go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you move this back to the command package, since it's only needed there? We're trying to slim down the utils package until we can remove it.

I can live in either issue.go or pr.go; it doesn't matter.

@doi-t doi-t marked this pull request as ready for review March 17, 2020 23:49
@ampinsk
Copy link
Contributor

ampinsk commented Mar 18, 2020

(idea) We could change Open to Draft like below if it is more appropriate

I like this idea! This would match better with github.com:

Screen Shot 2020-03-17 at 5 35 11 PM

@doi-t
Copy link
Contributor Author

doi-t commented Mar 18, 2020

Updated code to show Draft instead of Open for a Draft PR!

Comfirmed that it works for both PR by number and PR for a branch name.
Screen Shot 2020-03-18 at 22 05 56
Screen Shot 2020-03-18 at 22 05 44

@doi-t
Copy link
Contributor Author

doi-t commented Mar 19, 2020

It seems that this PR will have further conflicts with #665. I agree with the breaking backwards compatibility! So (maybe?) I should wait for merging #665 and resolve conflicts here. 🤔

@doi-t doi-t force-pushed the view-the-current-state branch from 7509efa to 0ba0a07 Compare March 20, 2020 09:17
@doi-t
Copy link
Contributor Author

doi-t commented Mar 25, 2020

@mislav @vilmibm
Hi! It seems that issues for stability and the default behavior are prioritized these days so that I assume that this PR is not in the queue for review yet. But let me make sure your thoughts especially for testing at least.
Is it ok to make another PR for #663 based on this branch (doi-t:view-the-current-state)? In this PR, I introduced table-driven testing of PR/Issue previews to test several PR/Issue states (Closed, Merged, Draft) and I would like to expand it more in another PR to test PR/Issue metadata because it allows me to avoid repeated codes and easily add more tests for the preview outputs (I even think that it could eventually be a shared helper function for other test cases 🤔).
Of course, I will take care of any conflicts with the upstream for it. Hope it is not too different from your plan. Please let me know if there is anything that I can make things better. 🙏

@mislav
Copy link
Contributor

mislav commented Mar 26, 2020

Is it ok to make another PR for #663 based on this branch

Of course! That sounds reasonable. Please feel free to make a nested PR 👍

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. Thanks for the hard work @doi-t! ✨

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := issueStateTitleWithColor(tc.state)
diff := cmp.Diff(tc.want, got)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL go-cmp! 🏆

http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
Copy link
Contributor

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 🥇

utils/utils.go Outdated
}

// ColorFuncForState returns a color function for a PR/Issue state
func ColorFuncForState(state string) func(string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you move this back to the command package, since it's only needed there? We're trying to slim down the utils package until we can remove it.

I can live in either issue.go or pr.go; it doesn't matter.

@doi-t
Copy link
Contributor Author

doi-t commented Apr 1, 2020

@mislav
Thank you for the review! I need to solve the conflicts to reflect changes of #665. Please wait a moment before the merge. I will poke you again if I make a notable change through solving the conflicts.

@doi-t
Copy link
Contributor Author

doi-t commented Apr 2, 2020

@mislav
I've solved the conflicts. I've also rolled back colorFuncForState 4c2f15f and simplified tests with the new testing helper test.ExpectLines 7eabbf5.

I believe it is ready for merge now if it looks good to you!

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks excellent to me. Thank you for the hard work 🌟

@doi-t doi-t changed the title Viewing issues and PRs in CLI should show the state (open, closed, merged) Show the state (open, closed, merged) in issue view and pr view Apr 3, 2020
@mislav mislav merged commit e10ccef into cli:master Apr 3, 2020
@doi-t doi-t deleted the view-the-current-state branch April 4, 2020 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Viewing issues and PRs in CLI should show the state (open, closed, merged)

3 participants