Skip to content

Commit 7724954

Browse files
[GitHub] Add greeting comment to opened PRs from new contributors (llvm#72384)
This includes some commonly needed information like how to add reviewers. This is implemented as a job before the labeler, so that on a new PR the comment is added before there are any subscribers and only the author gets a nofitication. The labeler job depends on the greeter having run or having been skipped. So if the PR wasn't just opened, or it's from a regular contributor, the labeling still happens. But we can be sure that when a greeting comment is left, it's the very first thing we do.
1 parent b211752 commit 7724954

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

.github/workflows/new-prs.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,43 @@ on:
1515
- synchronize
1616

1717
jobs:
18-
automate-prs-labels:
18+
greeter:
19+
runs-on: ubuntu-latest
1920
permissions:
2021
pull-requests: write
22+
# Only comment on PRs that have been opened for the first time, by someone
23+
# new to LLVM or to GitHub as a whole.
24+
if: >-
25+
(github.repository == 'llvm/llvm-project') &&
26+
(github.event.action == 'opened') &&
27+
(github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' ||
28+
github.event.pull_request.author_association == 'FIRST_TIMER')
29+
steps:
30+
- name: Setup Automation Script
31+
run: |
32+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
33+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
34+
chmod a+x github-automation.py
35+
pip install -r requirements.txt
36+
37+
- name: Greet Author
38+
run: |
39+
./github-automation.py \
40+
--token '${{ secrets.GITHUB_TOKEN }}' \
41+
pr-greeter \
42+
--issue-number "${{ github.event.pull_request.number }}"
43+
44+
automate-prs-labels:
45+
# Greet first so that only the author gets that notification.
46+
needs: greeter
2147
runs-on: ubuntu-latest
2248
# Ignore PRs with more than 10 commits. Pull requests with a lot of
2349
# commits tend to be accidents usually when someone made a mistake while trying
2450
# to rebase. We want to ignore these pull requests to avoid excessive
2551
# notifications.
52+
# always() means that even if greeter is skipped, this job will run.
2653
if: >
27-
github.repository == 'llvm/llvm-project' &&
54+
always() && github.repository == 'llvm/llvm-project' &&
2855
github.event.pull_request.draft == false &&
2956
github.event.pull_request.commits < 10
3057
steps:

llvm/utils/git/github-automation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,39 @@ def _get_curent_team(self) -> Optional[github.Team.Team]:
207207
return None
208208

209209

210+
class PRGreeter:
211+
def __init__(self, token: str, repo: str, pr_number: int):
212+
repo = github.Github(token).get_repo(repo)
213+
self.pr = repo.get_issue(pr_number).as_pull_request()
214+
215+
def run(self) -> bool:
216+
# We assume that this is only called for a PR that has just been opened
217+
# by a user new to LLVM and/or GitHub itself.
218+
219+
# This text is using Markdown formatting.
220+
comment = f"""\
221+
Thank you for submitting a Pull Request (PR) to the LLVM Project!
222+
223+
This PR will be automatically labeled and the relevant teams will be
224+
notified.
225+
226+
If you wish to, you can add reviewers by using the "Reviewers" section on this page.
227+
228+
If this is not working for you, it is probably because you do not have write
229+
permissions for the repository. In which case you can instead tag reviewers by
230+
name in a comment by using `@` followed by their GitHub username.
231+
232+
If you have received no comments on your PR for a week, you can request a review
233+
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
234+
is once a week. Please remember that you are asking for valuable time from other developers.
235+
236+
If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html).
237+
238+
You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/)."""
239+
self.pr.as_issue().create_comment(comment)
240+
return True
241+
242+
210243
def setup_llvmbot_git(git_dir="."):
211244
"""
212245
Configure the git repo in `git_dir` with the llvmbot account so
@@ -651,6 +684,9 @@ def execute_command(self) -> bool:
651684
pr_subscriber_parser.add_argument("--label-name", type=str, required=True)
652685
pr_subscriber_parser.add_argument("--issue-number", type=int, required=True)
653686

687+
pr_greeter_parser = subparsers.add_parser("pr-greeter")
688+
pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
689+
654690
release_workflow_parser = subparsers.add_parser("release-workflow")
655691
release_workflow_parser.add_argument(
656692
"--llvm-project-dir",
@@ -701,6 +737,9 @@ def execute_command(self) -> bool:
701737
args.token, args.repo, args.issue_number, args.label_name
702738
)
703739
pr_subscriber.run()
740+
elif args.command == "pr-greeter":
741+
pr_greeter = PRGreeter(args.token, args.repo, args.issue_number)
742+
pr_greeter.run()
704743
elif args.command == "release-workflow":
705744
release_workflow = ReleaseWorkflow(
706745
args.token,

0 commit comments

Comments
 (0)