Skip to content

workflows: Add a simple pull request subscription workflow #64913

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

Merged
merged 5 commits into from
Sep 8, 2023

Conversation

tstellar
Copy link
Collaborator

@tstellar tstellar commented Aug 23, 2023

This new workflow will make it possible for people to subscribe to pull requests based on the labels that are added. Labels will be added automatically to the pull requests based on the modified files and each label will be associated with a GitHub team that will be notified when the label is added.

See https://discourse.llvm.org/t/changes-to-pull-request-subscription-system/73296

@github-actions
Copy link

This repository does not accept pull requests. Please follow http://llvm.org/docs/Contributing.html#how-to-submit-a-patch for contribution to LLVM.

@github-actions github-actions bot closed this Aug 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2023
@tstellar
Copy link
Collaborator Author

Example pr-subscribers team: https://github.com/orgs/llvm/teams/pr-subscribers-mips

@joker-eph
Copy link
Collaborator

Why aren't we using the native GitHub CODEOWNER files for subscription?

Right now something quite annoying with the issue subscription, which will also happens with the action is that the subscription does not send the initial email containing all the information. What I'm looking for with an auto-subscription to pull-request is a notification with the title, the description, and ideally 500 lines of the diff!

@MaskRay
Copy link
Member

MaskRay commented Aug 23, 2023

Why aren't we using the native GitHub CODEOWNER files for subscription?

Right now something quite annoying with the issue subscription, which will also happens with the action is that the subscription does not send the initial email containing all the information. What I'm looking for with an auto-subscription to pull-request is a notification with the title, the description, and ideally 500 lines of the diff!

Using a text file in the repository doesn't scale and adds unneeded churn to the repository.
We cannot afford a new commit every time someone wants to change their subscription rules.

@tstellar tstellar reopened this Aug 23, 2023
@tstellar
Copy link
Collaborator Author

Right now something quite annoying with the issue subscription, which will also happens with the action is that the subscription does not send the initial email containing all the information. What I'm looking for with an auto-subscription to pull-request is a notification with the title, the description, and ideally 500 lines of the diff!

@joker-eph Is this what Phabricator does?

@tstellar
Copy link
Collaborator Author

@joker-eph @MaskRay We could do a hybrid approach where we use CODEOWNERS but instead of putting individuals in the file, we create teams (like I'm proposing here) and specify the teams as the code owners in the files.

The main difference also between using CODEOWNERS and what I'm proposing is that with the CODEOWNERS file, people are added as reviewers and with what I'm proposing, people are just subscribed to the PR.

@joker-eph
Copy link
Collaborator

joker-eph commented Aug 23, 2023

@joker-eph Is this what Phabricator does?

Yes, here is an example of the email Phab sends initially, and it includes all Herald subscribers (and has all the infos you needs about the revision without opening Phab, on GitHub you'd need to open the link and an extra click to get the list of paths and the diff I believe):

Screenshot 2023-08-23 at 10 33 58 AM

Using a text file in the repository doesn't scale and adds unneeded churn to the repository.
We cannot afford a new commit every time someone wants to change their subscription rules.

I shared the concern, but ultimately I care more about my code reviewing experience, if we have to talk about things "we cannot afford", I would say "we cannot afford a sub-par code review workflow" first.

@tstellar
Copy link
Collaborator Author

I've done some testing and using the CODEOWNERS file does generate an email with the full PR summary:

[llvm_temp-issue-tester] Update README.md (PR #51).pdf

I think if we use teams rather than individuals in the file, it's going to be much easier to manage.

@joker-eph
Copy link
Collaborator

That seems fine to me! Are we gonna reuse the teams used for issues or have new ones?

@tstellar
Copy link
Collaborator Author

That seems fine to me! Are we gonna reuse the teams used for issues or have new ones?

I was thinking we would create new ones, just in case people just want to subscribe to pull requests or issues only.

@asl
Copy link
Collaborator

asl commented Aug 25, 2023

That seems fine to me! Are we gonna reuse the teams used for issues or have new ones?

Given that label-based issue notifications & subscriptions work now, we'd likely deprecate issue teams

@smeenai
Copy link
Collaborator

smeenai commented Aug 28, 2023

CODEOWNERS will subscribe you to an entire directory, right? Is there any solution for subscribing only to specific paths in a directory?

@boomanaiden154
Copy link
Contributor

CODEOWNERS will subscribe you to an entire directory, right? Is there any solution for subscribing only to specific paths in a directory?

You can use the same exact syntax that you can in a .gitignore, so you can definitely subscribe only to specific paths in a directory. How that would work with subscribing teams/avoiding code churn from individuals updating their rules probably needs more discussion though.

https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

This new workflows will make it possible for people to subscribe to
pull requests based on the files that are being modified.  Whenever
a pull request is created, this action will look through all of
the teams whose name begins with pr-subscribers- and it will try
to match the files changed in the pull request to a comma separated
list of globs in the team's description.

One limitation of this workflow is that it only runs when a pull
request is created, so any files added in subsequent updates will
not create notifications for the appropriate teams.  This is planned
to be fixed in a future update.
The labels are added based on the file paths so we still ultimately end
up with file path based subscriptions, but using labels as an intermediary
gives us more flexibility.
@tstellar tstellar requested a review from a team as a code owner September 8, 2023 04:17
@tstellar tstellar requested a review from cor3ntin September 8, 2023 04:21
patch = requests.get(self.pr.diff_url).text
except:
patch = ""
comment = "@llvm/{}".format(team.slug) + "\n\n<details><summary>Changes</summary><pre>\n" + patch + "\n</pre></details>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this shows up in the email, that's just gonna be great :)

Can we do it for issues when we're done with PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I tested and it shows up in the email notification. You do have to click in the email to expand the patch (if you are looking at the html version) like you do on the comment, but hopefully that's acceptable.
Email-Collapased
Email-Expanded

Can you file an issue for what format you want in the issue notifications?

Copy link
Member

@MaskRay MaskRay Sep 8, 2023

Choose a reason for hiding this comment

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

Does the patch variable contain ```? If not, maybe add ```diff and ```

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MaskRay Do you mean the patch text?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Sorry for the typo, I mean whether the variable patch = requests.get(self.pr.diff_url).text contains ```

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It won't normally have ```, but it could if one of the lines changed in the patch had it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the pre tag will prevent the markdown from being rendered if that is what your going for with the ``` suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

You are right. <pre></pre> is sufficient. Resolved I think.

Another nice-to-have thing is to list modified files before showing diff --git.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe list the diffstat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I'm not sure exactly how to do that, but I'll add it to my TODO.

@tstellar
Copy link
Collaborator Author

tstellar commented Sep 8, 2023

I rewrote this so now labels are added to PRs based on the files changed by the PR, and then teams are notified with an @ mention based on the labels. I also added a diff of the PR to go along with the mention, so subscribers can see the context in their email without having to click on the PR link.

Here is an example of what the comment/notification will look like.

if self.team_name != team.name.lower():
continue
try:
patch = requests.get(self.pr.diff_url).text
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be arbitrarily large? Shall we limit the size here with a subset?
I don't know the limit for a comment size with GitHub API but I would be afraid of the comment posting failing because of that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems like the comments are limited to 65536 characters. We can try to put some kind of limit on this.

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

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

This is a great improvement, if the email notification works I'd say ship-it and refine!

self.repo = github.Github(token).get_repo(repo)
self.org = github.Github(token).get_organization(self.repo.organization.login)
self.pr = self.repo.get_issue(pr_number).as_pull_request()
self._team_name = "pr-subscribers-{}".format(label_name).lower()
Copy link
Member

Choose a reason for hiding this comment

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

There is some discrepancy between the label names and the pr-subscribers- team names.

For example, backend:X86 vs pr-subscribers-x86, and the issue-subscriber name https://github.com/orgs/llvm/teams/issue-subscribers-backend-X86 .

That said, this is a small issue. I think we can rename pr-subscribers- team names to improve consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MaskRay Yes, we are going to have to create new teams. I think in this case what we will do is to make pr-subscribers-backend:X86 a parent team of pr-subscribers-x86, so when you mention pr-subscribers-backend:X86, members of pr-subscribers-x86 will be mentioned too.

I have a python script mapping the current team names to the new names, so we should be able to fix this for every team.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good! Thanks for the effort.

@MaskRay
Copy link
Member

MaskRay commented Sep 8, 2023

Thank you for creating this patch and starting https://discourse.llvm.org/t/changes-to-pull-request-subscription-system/73296 . I only got to understand how this patch will help the situation after reading the Discourse post. This looks great to replace the current pr-subscribers via .github/CODEOWNERS mechanism.

@MaskRay
Copy link
Member

MaskRay commented Sep 8, 2023

Consider linking to https://discourse.llvm.org/t/changes-to-pull-request-subscription-system/73296 in the description.

Copy link
Collaborator

@tru tru left a comment

Choose a reason for hiding this comment

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

LGTM. Make sure you run black on the python file before submitting.

@tstellar tstellar merged commit 5f16a3a into llvm:main Sep 8, 2023
@jrtc27
Copy link
Collaborator

jrtc27 commented Sep 8, 2023

Please make sure this is limited to llvm/llvm-project like other issue-related workflows, otherwise forks will start running this action

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants