Skip to content

pr status: show number of approvals#2261

Closed
despreston wants to merge 3 commits intocli:trunkfrom
despreston:des/approval-count
Closed

pr status: show number of approvals#2261
despreston wants to merge 3 commits intocli:trunkfrom
despreston:des/approval-count

Conversation

@despreston
Copy link
Contributor

closes #2210

This commit adds the total count of PR approvals in the pr status command output.

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.

Thanks for taking this on!

Let's discuss the design of the feature some more in the original issue thread, but as for the code in question, I've left a comment about correctly parsing Review records.


for _, review := range pr.Reviews.Nodes {
if review.State == "APPROVED" {
totalApprovals++
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: this will count repeated approvals by the same person as multiple approvals.

I sometimes approve a single PR multiple times, usually to acknowledge that I've scanned over code updates since I've last reviewed. Multiple approvals from the same person should technically count as a single approval.

Moreover, if I leave 2 reviews where the first one is Approved and the second one is Request Changes, then my previous review should be discarded and should not qualify as an approval. Only the (chronologically) latest review status (other than a Comment status, which is neutral) from a single person should ever be taken into account.

See

func parseReviewers(pr api.PullRequest) []*reviewerState {

@despreston despreston requested a review from mislav October 29, 2020 14:22
@despreston
Copy link
Contributor Author

@mislav Sorry to bother but do you have a timeline for when this can be reviewed again?

@vilmibm
Copy link
Contributor

vilmibm commented Jan 20, 2021

@mislav

  • change to N/X

@alexcwatt
Copy link

In the discussion here it sounded like this could ship as N approvals per @mislav. Or are you looking for N/x approvals @vilmibm?

I'm happy to help with this PR in any way I can. @despreston thanks for working on this 🚀 Having the count of approvals would make my life easier 😄

@despreston
Copy link
Contributor Author

aha is that what the "n/x" means?? I would be happy to update this if that's what's needed, or hand it over to @alexcwatt if he wants to contribute to this.

@mislav
Copy link
Contributor

mislav commented May 7, 2021

Sorry for the inactivity, y'all.

We decided that if we were to ship this, we wanted to show N/X Approvals, where X is the minimum number of approvals per branch protection rules. Once the approval requirement has been satisfied, we can go back to showing just "Approved" without specific numbers.

@alexcwatt
Copy link

alexcwatt commented May 7, 2021

@mislav Thanks for getting back - that makes sense. In my use case, the minimum hard requirement for the number of approvals of 1 is lower than the soft requirement of 2... so just seeing "Approved" wouldn't help me know which PR's I should still seek a second approval on.

Perhaps there could be some sort of flag to show the counts always?

@mislav
Copy link
Contributor

mislav commented May 7, 2021

so just seeing "Approved" wouldn't help me know which PR's I should still seek a second approval on.

I see! That's a good counterpoint, thank you.

Let's then go with "N Approved" when the base branch has no minimum approval requirements, and "N/X Approved" otherwise.

From a linguistic perspective, "N Approval(s)" would be more correct, but then we would have think about pluralization rules in the "N/X" case, so let's just not go there right now and stick with "Approved".

@alexcwatt
Copy link

That sounds great @mislav!

@despreston If you're able to update this that would be awesome. Otherwise I will get to it later (literally getting married tomorrow so not for a little while! 💒).

@despreston
Copy link
Contributor Author

I can take this on. Should have something by next week.

despreston added 2 commits May 7, 2021 11:05
This commit changes the approval count in the PR status command so that
it only counts the most recent review from each reviewer.
If the base branch has no minimum approval requirements, show "N
Approved" reviews. Otherwise, show "N/X Approved".
@despreston
Copy link
Contributor Author

@mislav Pushed a change but I'm still not 100% I read the api correctly. If that's the case, lmk and I can dig in again.

@despreston
Copy link
Contributor Author

@mislav @vilmibm Can someone please let me know what the status is for this feature? I really dont mind pushing this across the finish line, but it's a bit of a pain to deal with merge conflicts because the PR has been open for so long.

@mislav mislav added the enhancement a request to improve CLI label Aug 4, 2021
@despreston
Copy link
Contributor Author

lol this is silly as hell but I deleted this branch locally, then changed my mind, and now I can't figure out how to push the changes to this branch. Here are the steps I took:

  1. Checkout des/approval-count from this repo (cli/cli).
  2. Make my changes and commit.
  3. Change the remote to point to my cloned cli/cli repo (despreston/cli).
  4. ??? How can I push those changes to this place?

https://github.com/despreston/cli/tree/des/approval-count is the branch with the latest changes. I just needed to fix that latest merge conflict.

@alexcwatt
Copy link

  1. Change the remote to point to my cloned cli/cli repo (despreston/cli).
  2. ??? How can I push those changes to this place?

https://github.com/despreston/cli/tree/des/approval-count is the branch with the latest changes. I just needed to fix that latest merge conflict.

git push takes an argument for the remote. I'm not sure if you're saying that you can now do git push origin and push to your remote, or if you need to use a different name. https://git-scm.com/docs/git-push

@mislav
Copy link
Contributor

mislav commented Aug 30, 2021

@despreston You have deleted the head branch; therefore this PR had stopped receiving updates from your fork. It doesn't matter that you later pushed the branch again—I don't think the PR can be "fixed" again. Please open a new PR!

@despreston
Copy link
Contributor Author

Lesson learned: don't delete the head branch before the thing is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement a request to improve CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display the number of approvals in 'pr status'

4 participants