Skip to content
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

Merged
merged 1 commit into from
Feb 9, 2022
Merged

Conversation

matthyx
Copy link
Contributor

@matthyx matthyx commented Jan 20, 2022

fixes #11994

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 20, 2022
@k8s-ci-robot k8s-ci-robot added area/prow Issues or PRs related to prow area/prow/plugins Issues or PRs related to prow's plugins for the hook component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jan 20, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 20, 2022
@parispittman
Copy link

/lgtm

thank you SO MUCH for your work @matthyx :)) this is great for the community

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 20, 2022
@dims
Copy link
Member

dims commented Jan 20, 2022

i have not reviewed prow plugins before. LGTM. thanks @matthyx

@mrbobbytables
Copy link
Member

/assign @BenTheElder

RewardMessage = `
Thanks for serving the community in this new capacity!

Next steps:
Copy link
Contributor

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!
Copy link
Contributor

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?

Copy link
Member

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:

Suggested change
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
Copy link
Contributor

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?

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Contributor

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.

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 {
Copy link
Contributor

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.

@BenTheElder
Copy link
Member

https://github.com/kubernetes/test-infra/pull/24937/files#r789177567 (@stevekuznetsov's comment) in particular

neat idea :)

@matthyx
Copy link
Contributor Author

matthyx commented Jan 24, 2022

Thanks for the reviews, I'll come back to this tomorrow!

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 26, 2022
}

// Reward all new owners.
newOwners := headRepo.AllOwners().Difference(baseRepo.AllOwners())
Copy link
Contributor Author

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)

Copy link
Contributor

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

@matthyx matthyx force-pushed the reward-bot branch 3 times, most recently from 910b52c to 0dfcb8f Compare January 26, 2022 13:43
@matthyx
Copy link
Contributor Author

matthyx commented Jan 28, 2022

@stevekuznetsov could you just check the new plugin logic, and then I'll fix the rest? Cheers!

@stevekuznetsov
Copy link
Contributor

@matthyx sorry, I've not been at my desk - will look this morning :)

@matthyx
Copy link
Contributor Author

matthyx commented Jan 28, 2022

Let's see what Cole has to say 😀
/cc @cjwagner

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)
Copy link
Member

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.

func (o *RepoOwners) AllOwners() sets.String {
allOwners := sets.NewString()
for k := range o.approvers {
allOwners.Insert(k)
Copy link
Member

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.Strings at the leaf level.

Please also add a simple unit test for this.

Copy link
Contributor Author

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 {
Copy link
Member

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(), ", ")))
Copy link
Member

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),
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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.

@matthyx
Copy link
Contributor Author

matthyx commented Feb 1, 2022

Thanks @cjwagner I'll fix that soon!

@matthyx matthyx force-pushed the reward-bot branch 3 times, most recently from 4bae078 to 21139bb Compare February 3, 2022 16:20
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 3, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 8, 2022
@matthyx
Copy link
Contributor Author

matthyx commented Feb 8, 2022

/retest

@matthyx
Copy link
Contributor Author

matthyx commented Feb 8, 2022

@cjwagner I have added tests, it should be ready to review. Thanks in advance!

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Matthias!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 9, 2022
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 9, 2022
@k8s-ci-robot k8s-ci-robot merged commit 52cbacb into kubernetes:master Feb 9, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 9, 2022
@matthyx matthyx deleted the reward-bot branch February 9, 2022 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow/plugins Issues or PRs related to prow's plugins for the hook component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Owners File Recognition/Reward Bot
8 participants