Skip to content

Commit e3773f3

Browse files
committed
[GitHub] Add Greeting comment to new contributor's PRs with useful information
This adds a new workflow that responds to PRs that are opened by new contributors with a comment thanking the author for their contribution, and provides answers to common problems (problem for now, could expand later). According to my testing, and the docs here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target `opened` will only trigger on the first opening, not a re-open. I considered including this comment in the one the labeller adds, but that means that it would be emailed to all subscribers not just the author. This comment is only left for authors new to the LLVM repo or to GitHub itself. This is done by checking the value in: https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
1 parent eb3c02f commit e3773f3

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.github/workflows/pr-greeter.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PR Greeter
2+
3+
on:
4+
pull_request_target:
5+
types: [ opened ]
6+
7+
permissions:
8+
content: read
9+
10+
jobs:
11+
greet:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
if: github.repository == 'llvm/llvm-project' && (github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' || github.event.pull_request.author_association == 'FIRST_TIMER')
16+
steps:
17+
- name: Setup Automation Script
18+
run: |
19+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
20+
curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
21+
chmod a+x github-automation.py
22+
pip install -r requirements.txt
23+
24+
- name: Greet Author
25+
run: |
26+
./github-automation.py \
27+
--token '${{ secrets.GITHUB_TOKEN }}' \
28+
pr-greeter \
29+
--issue-number "${{ github.event.pull_request.number }}"

llvm/utils/git/github-automation.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ def _get_curent_team(self) -> Optional[github.Team.Team]:
211211
return None
212212

213213

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

688+
pr_greeter_parser = subparsers.add_parser("pr-greeter")
689+
pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
690+
658691
release_workflow_parser = subparsers.add_parser("release-workflow")
659692
release_workflow_parser.add_argument(
660693
"--llvm-project-dir",
@@ -705,6 +738,9 @@ def execute_command(self) -> bool:
705738
args.token, args.repo, args.issue_number, args.label_name
706739
)
707740
pr_subscriber.run()
741+
elif args.command == "pr-greeter":
742+
pr_greeter = PRGreeter(args.token, args.repo, args.issue_number)
743+
pr_greeter.run()
708744
elif args.command == "release-workflow":
709745
release_workflow = ReleaseWorkflow(
710746
args.token,

0 commit comments

Comments
 (0)