Store tree-hash inside a comment and compare it before removing lgtm#9138
Store tree-hash inside a comment and compare it before removing lgtm#9138k8s-ci-robot merged 1 commit intokubernetes:masterfrom
Conversation
|
/lint |
k8s-ci-robot
left a comment
There was a problem hiding this comment.
@BenTheElder: 0 warnings.
Details
In response to this:
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
prow/github/types.go
Outdated
| // https://developer.github.com/v3/repos/commits/#get-a-single-commit | ||
| type SingleCommit struct { | ||
| URL string `json:"url"` | ||
| Sha string `json:"sha"` |
There was a problem hiding this comment.
nit: s/Sha/SHA/, SHA is an initialism
prow/plugins/lgtm/lgtm.go
Outdated
|
|
||
| if hasLGTM == true { | ||
| // Get combined status to see if we already know a lgtm tree-hash | ||
| combined, err := gc.GetCombinedStatus(org, repo, *pe.PullRequest.MergeSHA) |
There was a problem hiding this comment.
This won't be the right SHA because the PR just changed. This is the second point I mentioned here: #6353 (comment)
There was a problem hiding this comment.
Sorry, it wasn't clear on the mobile phone... please discard my previous comment. I will check if I can use another ref (The ref can be a SHA, a branch name, or a tag name.).
There was a problem hiding this comment.
The problem isn't with the ref, it is with the use of status contexts. Using a status context associates the state you want to store with a commit SHA that will necessarily change after a rebase. At that time you won't know what the previous SHA was so you won't be able to look up the state you stored.
|
When someone rebases and force-pushes their branch, don't we lose the commit you're adding this status to? |
stevekuznetsov
left a comment
There was a problem hiding this comment.
Not clear the approach will work
|
#bikeshed let's use a label |
|
If we store this state in a label we're going to end up creating a new label for the repository every time we add the |
|
Actually the tree-hash label is removed if the PR has changed code wise, so if you lgtm again, there will always be zero or one label at a time. |
I'm talking about labels accumulating in the repository, not on the PR. When you add a new label to a PR it also adds it as a new label to the repository. Because the labels include hashes they will always be unique which will create a lot of new labels in the repository. |
|
Oh, I see. Like what labelsync does? I'm too junior for that... what do other think? |
|
Sounds like it may be problematic after some time, assuming plugins that
list repo labels will incur extra time? Maybe we can delete the label when
it's removed or the PR is closed/merged?
…On Fri, Aug 24, 2018, 22:06 Cole Wagner ***@***.***> wrote:
Actually the tree-hash label is removed if the PR has changed code wise,
so if you lgtm again, there will always be zero or one label at a time.
I'm talking about labels accumulating in the repository, not on the PR.
When you add a new label to a PR it also adds it as a new label to the
repository. Because the labels include hashes they will always be unique
which will create a lot of new labels in the repository.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#9138 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADuFf0oZDEAW2qOkhMpIukRMQKOKzOTtks5uUE6hgaJpZM4WJW6u>
.
|
|
Not sure we want to make repo-scoped changes for this. What was the argument against recording it in a comment when we see a LGTM label added? |
|
I think it was spamming the reviewers with the comment notifications... |
|
You'd leave one comment when the LGTM label was added, right? I don't think that really constitutes as |
Then he asked @cblecker for his advice, with no answer. |
|
Sorry, the other issue got lost in my notifications. Yeah, this really isn't how Github labels are meant to be used, and we're inviting a bunch of potential problems by doing this. GitHub loads the list of all labels in a repo on so many pages.. the PR list, the issue list, every issue/PR if you have write access. I can see page load times increasing and the number of 🦄s skyrocketing. I also don't know if GitHub has a limit of labels per repo. k/k has an average of 64 PRs per day. If each of those is modified/rebased once, that is 128 labels per day, or just shy of 900 labels per week. Even if we cleaned them up after somehow, k/k has 960 open issues, so we'd need ~1000 labels for this. Not to mention, the hope was the label_sync could one day become authoritative and delete any labels it doesn't recognize. I don't see how this is tenable for us. |
|
@cjwagner @stevekuznetsov should be good now! |
cjwagner
left a comment
There was a problem hiding this comment.
Can we detect if the bot comment has been edited so that we can reject the comment if it has been modified by a human? If that isn't possible thats fine since only maintainers should have permission to edit other peoples' comments, but it would be a nice additional security check to do.
prow/plugins/lgtm/lgtm.go
Outdated
| m := addLGTMLabelNotificationRe.FindStringSubmatch(comment.Body) | ||
| if comment.User.Login == botname && m != nil { | ||
| log.Info("Removing tree-hash comment.") | ||
| if err := gc.DeleteComment(org, repoName, comment.ID); err != nil { |
There was a problem hiding this comment.
The comment deletion can be simplified and made more efficient if you use the CommentPruner client in the plugin client. You can follow the pattern used in the require-matching-label plugin. The shouldPrune function may assume that all bot comments it considers are bot comments.
There was a problem hiding this comment.
I have done so, but I need your (@cjwagner ) help to fix the unit tests... I have found nowhere an example on how to actually fake PruneComments deleting comments.
prow/plugins/lgtm/lgtm.go
Outdated
| if err := gc.RemoveLabel(org, repoName, number, LGTMLabel); err != nil { | ||
| return err | ||
| } | ||
| botname, err := gc.BotName() |
There was a problem hiding this comment.
We can skip trying to clean up the "LGTM added." comment in repos where StoreTreeHash is not enabled. This will save API tokens that would be used to list the issue comments.
If we fail to delete a few comments after a config change disables the feature in a repo it isn't a big deal.
prow/plugins/lgtm/lgtm.go
Outdated
| } | ||
| for _, comment := range comments { | ||
| if comment.User.Login == botname && comment.Body == removeLGTMLabelNoti { | ||
| if err := gc.DeleteComment(org, repoName, comment.ID); err != nil { |
There was a problem hiding this comment.
CommentPruner can be used here as well.
prow/plugins/lgtm/lgtm.go
Outdated
| } | ||
| hasLGTM = github.HasLabel(LGTMLabel, labels) | ||
|
|
||
| if hasLGTM == true { |
There was a problem hiding this comment.
nit: s/hasLGTM == true/hasLGTM/
You can actually get rid of hasLGTM entirely and just put github.HasLabel(LGTMLabel, labels) here.
prow/plugins/lgtm/lgtm.go
Outdated
| if err != nil { | ||
| log.WithError(err).Errorf("Failed to get pull request.") | ||
| } | ||
| SHA := *pr.MergeSHA |
There was a problem hiding this comment.
MergeSHA is a pointer so we need a nil check before accessing it.
In particular, this field is lazily calculated and may not always be specified.
prow/plugins/lgtm/lgtm.go
Outdated
| } | ||
| } | ||
| // Get the current tree-hash | ||
| commit, err := gc.GetSingleCommit(org, repo, *pe.PullRequest.MergeSHA) |
|
For the comment edited detection, we could compare |
|
@cjwagner I think we have all we need now :) |
prow/plugins/lgtm/lgtm.go
Outdated
| } | ||
| } | ||
| // Get the current tree-hash | ||
| if pe.PullRequest.MergeSHA != nil { |
There was a problem hiding this comment.
This check could go before gc.BotName and gc.ListIssueComments to save API tokens.
|
This LGTM. Please squash commits. |
b3e0eb2 to
76e2e5e
Compare
cjwagner
left a comment
There was a problem hiding this comment.
Thanks @matthyx!
As @stevekuznetsov mentioned:
Will need update from @kubernetes/sig-contributor-experience-pr-reviews and an e-mail blast when rolled out
But this PR only actually enables the plugin for kubernetes/test-infra which we don't need to send out an update for (except maybe a comment in sig-testing slack). We can test out the behavior before notifying the appropriate parties and rolling out to the rest of kubernetes.
Note that merging this PR won't have an affect until we bump Prow.
/lgtm
/hold cancel
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cjwagner, matthyx, stevekuznetsov The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@matthyx: Updated the
DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
| } | ||
| treeHash := commit.Commit.Tree.SHA | ||
| log.Info("Adding comment to store tree-hash: " + treeHash) | ||
| if err := gc.CreateComment(org, repoName, number, fmt.Sprintf(addLGTMLabelNotification, treeHash)); err != nil { |
There was a problem hiding this comment.
Would it reduce spam if we edited the comment vs pruning and creating every time?
|
This is great :). Can we pull the helpers out somewhere so |
|
@wking How would |
This seems like a bug to me. For example, say:
That's what we have now (as far as the |
|
The TLDR; it is intentional and part of the design for the set of approvers to not be changed by updates to the PR's code. |
That matches the docs here.
So basically it's an honor system among members of the organization once the approvers have blessed the general direction at some point in the PR's lifecycle [which may no longer correspond to the current direction]? Would you accept an PR to allow projects to opt-in to tighter handling when they do have sufficiently active/picky/paranoid code-owners? |
To some degree. In practice there is rarely just one reviewer looking at a PR and if a PR was significantly changed without any notice that would be a giant red flag.
I'm open to the idea, but the |
Fixes #6353
I have decided to stick with statuses to avoid spamming reviewers.
Also it makes more sense to me, as a lgtm refers to a commit.