-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add reward-owners plugin #24937
Add reward-owners plugin #24937
Conversation
/lgtm thank you SO MUCH for your work @matthyx :)) this is great for the community |
i have not reviewed prow plugins before. LGTM. thanks @matthyx |
/assign @BenTheElder |
RewardMessage = ` | ||
Thanks for serving the community in this new capacity! | ||
|
||
Next steps: |
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.
Do we want this to be a Markdown-formatted link?
Thanks for serving the community in this new capacity! | ||
|
||
Next steps: | ||
1- Reach out in #sig-contribex for your special badge swag! |
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.
Can we add a link to the channel?
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.
I think that would be:
1- Reach out in #sig-contribex for your special badge swag! | |
1- Reach out in [#sig-contribex](https://app.slack.com/client/T09NY5SBT/C1TU9EB9S) for your special badge swag! |
... Except the user also needs to be a member of the slack, so we might want to instead mention https://slack.k8s.io in this comment or some doc about joining the slack if there is one.
Next steps: | ||
1- Reach out in #sig-contribex for your special badge swag! | ||
|
||
2- Join #kubernetes-contributors in slack and [dev@kubernetes.io](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=dev@kubernetes.io) for all upstream info |
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.
Can we add a link to the channel?
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.
2- Join #kubernetes-contributors in slack and [dev@kubernetes.io](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=dev@kubernetes.io) for all upstream info | |
2- Join [#kubernetes-contributors](https://kubernetes.slack.com/archives/C09R23FHP) in slack and [dev@kubernetes.io](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=dev@kubernetes.io) for all upstream info |
addedUsers := sets.NewString() | ||
removedUsers := sets.NewString() | ||
for _, change := range changes { | ||
if (filepath.Base(change.Filename) == filenames.Owners || filepath.Base(change.Filename) == filenames.OwnersAliases) && change.Status != github.PullRequestFileRemoved { |
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.
IMO loading the YAML and doing a structured difference instead of using regex to parse a patch of a structured dataset might be nicer. Do we want to post this in all cases, or only if this is someone's first time becoming an OWNER? If so, we may just clone the new commit and traverse the owners set using our libraries to do the diff and figure out if this is a new member or someone owning new directories.
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.
first time becoming an OWNER would be best but didn't want to make the scope too complicated out of the gate 🙇🏻
continue | ||
} | ||
fmt.Println("let's reward", user) | ||
if err := ghc.CreateComment(org, repo, number, RewardMessage); err != nil { |
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.
We might make more of a coherent comment if we list the users, instead of posting (the same) information N times, once per user, in one PR.
https://github.com/kubernetes/test-infra/pull/24937/files#r789177567 (@stevekuznetsov's comment) in particular neat idea :) |
Thanks for the reviews, I'll come back to this tomorrow! |
} | ||
|
||
// Reward all new owners. | ||
newOwners := headRepo.AllOwners().Difference(baseRepo.AllOwners()) |
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.
@stevekuznetsov something like that? (please bear with me, I will fix tests and other details after you validate the approach)
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.
Yes, I think this is an appropriate way to do it. @cjwagner might know more of the subtle bits of the owners impl, but this looks right to me
910b52c
to
0dfcb8f
Compare
@stevekuznetsov could you just check the new plugin logic, and then I'll fix the rest? Cheers! |
@matthyx sorry, I've not been at my desk - will look this morning :) |
Let's see what Cole has to say 😀 |
prow/repoowners/repoowners.go
Outdated
log := c.logger.WithFields(logrus.Fields{"org": org, "repo": repo, "base": base, "sha": sha}) | ||
cloneRef := fmt.Sprintf("%s/%s", org, repo) | ||
fullName := fmt.Sprintf("%s:%s", cloneRef, base) | ||
|
||
entry, err := c.cacheEntryFor(org, repo, base, cloneRef, fullName, sha, log) |
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.
This cache only stores one value per org/repo which is normally perfectly efficient because we normally don't have look ups for old SHA values, only the current one. With this change we'll do look ups for old SHA values which will replace the cache value with a value that cause other consumers to cache miss.
We could mitigate this by adding an extra parameter to cacheEntryFor
to optionally prevent updates to the cache and use that when LoadRepoOwnersSha
is used rather than LoadRepoOwners
.
prow/repoowners/repoowners.go
Outdated
func (o *RepoOwners) AllOwners() sets.String { | ||
allOwners := sets.NewString() | ||
for k := range o.approvers { | ||
allOwners.Insert(k) |
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.
Both approvers
and reviews
are indexed by path, not by user so this would reward new OWNERS files rather than new users 🙃 . Instead loop over paths and regular expressions and union the sets.String
s at the leaf level.
Please also add a simple unit test for this.
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.
Oh, yeah... let me do this a bit later.
} | ||
|
||
func handlePullRequest(pc plugins.Agent, pre github.PullRequestEvent) error { | ||
if pre.Action != github.PullRequestActionOpened && pre.Action != github.PullRequestActionReopened && pre.Action != github.PullRequestActionSynchronize { |
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.
Shouldn't we post the message once the PR merges rather than when it is created and every time it is updated?
log.Debug("No new owner to reward, exiting.") | ||
return nil | ||
} | ||
return ghc.CreateComment(info.org, info.repo, info.number, fmt.Sprintf(RewardMessage, strings.Join(newOwners.List(), ", "))) |
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.
It might be a good idea to tag the users by prepending an @
to each username?
|
||
func helpProvider(_ *plugins.Configuration, _ []config.OrgRepo) (*pluginhelp.PluginHelp, error) { | ||
pluginHelp := &pluginhelp.PluginHelp{ | ||
Description: fmt.Sprintf("The reward-owners plugin watches in %s and %s files for modifications and welcomes new approvers and reviewers.", ownersconfig.DefaultOwnersFile, ownersconfig.DefaultOwnersAliasesFile), |
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.
It doesn't look like this plugin actually considers the OWNERS_ALIAS files?
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.
Well, repoowners
looks into OWNERS and OWNERS_ALIAS, doesn't it?
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.
Yeah, looking again this looks right. I think I forgot that the approvers
and reviewers
maps already have aliases expanded.
|
||
func handle(ghc githubClient, oc ownersClient, log *logrus.Entry, info info) error { | ||
log.Debug("Resolving repository owners for base branch...") | ||
baseRepo, err := oc.LoadRepoOwnersSha(info.org, info.repo, info.base.Ref, info.base.SHA) |
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.
It may be worth it to look up the files changed by the PR via the GH API before loading the owners files. Most PRs won't change OWNERS files at all and for those PRs it would probably be preferable to risk consuming some GH API rate limit in exchange for avoiding multiple repo fetches. We do this in verify-owners
for example.
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.
Yes I remember the clever chap that wrote it.
Thanks @cjwagner I'll fix that soon! |
4bae078
to
21139bb
Compare
/retest |
@cjwagner I have added tests, it should be ready to review. Thanks in advance! |
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.
LGTM, thanks Matthias!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cjwagner, matthyx The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
fixes #11994