Skip to content

Commit 9d98bcb

Browse files
authored
[tooling] Add contribution comment on pull request (#208)
1 parent 8bd2b1c commit 9d98bcb

13 files changed

+127
-6
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Link the exercise discussion issue
88

99
- [ ] If you require a new remote repository on the `Git-Mastery` organization, have you [created a request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.md) for it?
1010
- [ ] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme?
11-
- [ ] Have you tested the download script using `test-download.sh`?
11+
- [ ] Have you tested your changes using the instructions posted?
1212
- [ ] Have you verified that this exercise does not already exist or is not currently in review?
1313
- [ ] Did you introduce a new grading mechanism that should belong to [`git-autograder`](https://github.com/git-mastery/git-autograder)?
1414
- [ ] Did you introduce a new dependency that should belong to [`app`](https://github.com/git-mastery/app)?

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ jobs:
1414
steps:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
17+
1718
- name: Setup Python
1819
uses: actions/setup-python@v5
1920
with:
2021
python-version: "3.13"
22+
2123
- name: Run validation script
2224
run: |
23-
python validate-exercise-config.py
25+
python scripts/validate-exercise-config.py
2426
2527
unit_tests:
2628
runs-on: ubuntu-latest
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Post contribution message in pull request
2+
on:
3+
pull_request:
4+
types: [opened]
5+
6+
jobs:
7+
post_contribution_message:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v6
12+
13+
- name: Setup Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: "3.13"
17+
18+
- name: Install dependencies
19+
run: |
20+
pip install requests PyGithub
21+
22+
- name: Run post contribution message script
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
PR_NUMBER: ${{ github.event.pull_request.number }}
26+
COMMIT_AUTHOR: ${{ github.event.pull_request.user.login }}
27+
FORK_AUTHOR: ${{ github.event.pull_request.head.repo.owner.login }}
28+
FORK_REPO: ${{ github.event.pull_request.head.repo.name }}
29+
FORK_BRANCH: ${{ github.event.pull_request.head.ref }}
30+
run: |
31+
python scripts/post-contribution-message.py

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Generate exercise-directory.md
2121
run: |
22-
python create-exercise-directory.py
22+
python scripts/create-exercise-directory.py
2323
mv exercise-directory.md index.md
2424
2525
- name: Deploy to gh-pages

new.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ read choice
55

66
case "$choice" in
77
"hands-on" | "h" | "H")
8-
python new-hands-on.py
8+
python scripts/new-hands-on.py
99
;;
1010
"exercise" | "e" | "E")
11-
python new-exercise.py
11+
python scripts/new-exercise.py
1212
;;
1313
*)
1414
echo "Invalid choice. Please enter 'hands-on' (h) or 'exercise' (e)."

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ repo-smith
99
# Developer tooling dependencies
1010
ruff
1111
mypy
12+
PyGithub
13+
requests
14+
types-requests
File renamed without changes.
File renamed without changes.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os
2+
3+
from github import Github
4+
5+
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
6+
PR_NUMBER = os.environ.get("PR_NUMBER")
7+
COMMIT_AUTHOR = os.environ.get("COMMIT_AUTHOR")
8+
FORK_AUTHOR = os.environ.get("FORK_AUTHOR")
9+
FORK_REPO = os.environ.get("FORK_REPO")
10+
FORK_BRANCH = os.environ.get("FORK_BRANCH")
11+
12+
if not all(
13+
[GITHUB_TOKEN, PR_NUMBER, COMMIT_AUTHOR, FORK_AUTHOR, FORK_REPO, FORK_BRANCH]
14+
):
15+
raise ValueError("Missing required environment variables")
16+
17+
assert PR_NUMBER is not None
18+
PR_NUMBER_INT = int(PR_NUMBER)
19+
20+
gh = Github(GITHUB_TOKEN)
21+
repo = gh.get_repo("git-mastery/exercises")
22+
pr = repo.get_pull(PR_NUMBER_INT)
23+
24+
comment = f"""
25+
Hi @{COMMIT_AUTHOR}, thank you for your contribution! 🎉
26+
27+
This PR comes from your fork `{FORK_AUTHOR}/{FORK_REPO}` on branch `{FORK_BRANCH}`.
28+
29+
Before you request for a review, please ensure that you have tested your changes locally!
30+
31+
> [!IMPORTANT]
32+
> The previously recommended way of using `./test-download.py` is no longer the best way to test your changes locally.
33+
>
34+
> Please read the following instructions for the latest instructions.
35+
36+
### Prerequisites
37+
38+
Ensure that you have the `gitmastery` app installed locally ([instructions](https://git-mastery.github.io/companion-app/index.html))
39+
40+
### Testing steps
41+
42+
If you already have a local Git-Mastery root to test, you can skip the following step.
43+
44+
Create a Git-Mastery root locally:
45+
46+
```bash
47+
gitmastery setup
48+
```
49+
50+
Navigate into the Git-Mastery root (defaults to `gitmastery-exercises/`):
51+
52+
```bash
53+
cd gitmastery-exercises/
54+
```
55+
56+
Edit the `.gitmastery.json` configuration file. You need to set the following values under the `exercises_source` key.
57+
58+
```json
59+
{{
60+
# other fields...
61+
"exercises_source": {{
62+
"username": "{FORK_AUTHOR}",
63+
"repository": "{FORK_REPO}",
64+
"branch": "{FORK_BRANCH}",
65+
}}
66+
}}
67+
```
68+
69+
Then, you can use the `gitmastery` app to download and verify your changes locally.
70+
71+
```bash
72+
gitmastery download <your new change>
73+
gitmastery verify
74+
```
75+
76+
### Checklist
77+
78+
- [ ] (For exercises and hands-ons) I have verified that the downloading behavior works
79+
- [ ] (For exercises only) I have verified that the verification behavior is accurate
80+
81+
> [!IMPORTANT]
82+
> To any reviewers of this pull request, please use the same instructions above to test the changes.
83+
""".lstrip()
84+
85+
pr.create_issue_comment(comment)

0 commit comments

Comments
 (0)