Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 3d18fa7

Browse files
Automating adding Hacktoberfest labels (#136)
* Automating adding Hacktoberfest labels This PR introduces two key improvements to streamline our Hackathon process: PR Template for Hackathon Contributors: Added a standardized template to guide contributors in providing necessary information for their Pull Requests. Auto-labeling GitHub Action: Implemented an automated system to apply labels to issues. This enhancement allows us to: Efficiently track points across repositories Accurately count the number of contributors per PR These changes will facilitate better organization and provide real-time insights into Hackathon participation. For an up-to-date view of participant standings, please refer to our leaderboard: TBD54566975/developer.tbd.website#1680 * Create PULL_REQUEST_TEMPLATE.md
1 parent 0dc82e3 commit 3d18fa7

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!--
2+
For Work In Progress Pull Requests, please use the Draft PR feature,
3+
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.
4+
5+
For a timely review/response, please avoid force-pushing additional
6+
commits if your PR already received reviews or comments.
7+
8+
Before submitting a Pull Request, please ensure you've done the following:
9+
- 📖 Read the TBD Developer Website Contributing Guide: https://github.com/TBD54566975/developer.tbd.website/blob/main/CONTRIBUTING.md.
10+
- 📖 Read the TBD Developer Website Code of Conduct: https://github.com/TBD54566975/developer.tbd.website/blob/main/CODE_OF_CONDUCT.md.
11+
- 👷‍♀️ Create small PRs. In most cases, this will be possible.
12+
- ✅ Provide tests for your changes.
13+
- 📝 Use descriptive commit messages.
14+
- 📗 Update any related documentation and include any relevant screenshots.
15+
-->
16+
17+
## What type of PR is this? (check all applicable)
18+
19+
- [ ] ♻️ Refactor
20+
- [ ] ✨ New Feature
21+
- [ ] 🐛 Bug Fix
22+
- [ ] 📝 Documentation Update
23+
- [ ] 👷 Example Application
24+
- [ ] 🧑‍💻 Code Snippet
25+
- [ ] 🎨 Design
26+
- [ ] 📖 Content
27+
- [ ] 🧪 Tests
28+
- [ ] 🔖 Release
29+
- [ ] 🚩 Other
30+
31+
## Description
32+
33+
<!-- Please do not leave this blank -->
34+
35+
This PR [adds/removes/fixes/replaces] this [feature/bug/etc].
36+
37+
## Related Tickets & Documents
38+
<!--
39+
Please use this format link issue numbers: Resolves #123
40+
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
41+
-->
42+
Resolves #
43+
44+
## Mobile & Desktop Screenshots/Recordings
45+
46+
<!-- Visual changes require screenshots -->
47+
48+
## Added code snippets?
49+
- [ ] 👍 yes
50+
- [ ] 🙅 no, because they aren't needed
51+
52+
## Added tests?
53+
54+
- [ ] 👍 yes
55+
- [ ] 🙅 no, because they aren't needed
56+
- [ ] 🙋 no, because I need help
57+
58+
### No tests? Add a note
59+
<!--
60+
If you didn't provide tests with this PR, please explain here why they aren't needed.
61+
-->
62+
63+
## Added to documentation?
64+
65+
- [ ] 📜 readme
66+
- [ ] 📜 contributing.md
67+
- [ ] 📓 general documentation
68+
- [ ] 🙅 no documentation needed
69+
70+
### No docs? Add a note
71+
<!--
72+
If you didn't provide documentation with this PR, please explain here why it's not needed.
73+
-->
74+
75+
## [optional] Are there any post-deployment tasks we need to perform?
76+
77+
78+
79+
## [optional] What gif best describes this PR or how it makes you feel?
80+
81+
82+
83+
<!-- note: PRs with deletes sections will be marked invalid -->
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Propagate Issue Labels to PR
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
jobs:
6+
copy_labels:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
- name: Get issue number from PR body
12+
id: issue_number
13+
uses: actions/github-script@v6
14+
with:
15+
github-token: ${{ secrets.GITHUB_TOKEN }}
16+
script: |
17+
const prBody = context.payload.pull_request.body || '';
18+
// Remove HTML comments
19+
const bodyWithoutComments = prBody.replace(/<!--[\s\S]*?-->/g, '');
20+
// Find issue number
21+
const match = bodyWithoutComments.match(/(?:Resolves|Closes) #(\d+)/);
22+
const issueNumber = match ? match[1] : null;
23+
if (issueNumber) {
24+
console.log(`Issue number found: ${issueNumber}`);
25+
core.setOutput('has_issue', 'true');
26+
core.setOutput('issue_number', issueNumber);
27+
} else {
28+
console.log('No issue number found in PR body');
29+
core.setOutput('has_issue', 'false');
30+
}
31+
- name: Get labels from linked issue
32+
if: steps.issue_number.outputs.has_issue == 'true'
33+
uses: actions/github-script@v6
34+
id: issue_labels
35+
with:
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
script: |
38+
const issue_number = ${{ steps.issue_number.outputs.issue_number }};
39+
try {
40+
const issue = await github.rest.issues.get({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
issue_number: parseInt(issue_number)
44+
});
45+
return issue.data.labels.map(label => label.name);
46+
} catch (error) {
47+
console.log(`Error fetching issue labels: ${error}`);
48+
return [];
49+
}
50+
- name: Check for required labels
51+
if: steps.issue_number.outputs.has_issue == 'true' && steps.issue_labels.outputs.result != '[]'
52+
id: check_labels
53+
uses: actions/github-script@v6
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
script: |
57+
const labels = ${{ steps.issue_labels.outputs.result }};
58+
const hacktoberfestLabel = labels.some(label => label.toLowerCase().includes('hacktoberfest'));
59+
const sizeLabelPresent = labels.some(label => ['small', 'medium', 'large'].includes(label.toLowerCase()));
60+
return hacktoberfestLabel || sizeLabelPresent;
61+
- name: Add labels to PR
62+
if: steps.issue_number.outputs.has_issue == 'true' && steps.check_labels.outputs.result == 'true'
63+
uses: actions/github-script@v6
64+
with:
65+
github-token: ${{ secrets.GITHUB_TOKEN }}
66+
script: |
67+
const pr_number = context.issue.number;
68+
const labels = ${{ steps.issue_labels.outputs.result }};
69+
try {
70+
await github.rest.issues.addLabels({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
issue_number: pr_number,
74+
labels: labels
75+
});
76+
console.log('Labels added successfully');
77+
} catch (error) {
78+
console.log(`Error adding labels: ${error}`);
79+
}

0 commit comments

Comments
 (0)