generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automating adding Hacktoberfest labels (#810)
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 --------- Co-authored-by: Rizel Scarlett <[email protected]>
- Loading branch information
1 parent
30de237
commit fe6ca82
Showing
2 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!-- | ||
For Work In Progress Pull Requests, please use the Draft PR feature, | ||
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details. | ||
For a timely review/response, please avoid force-pushing additional | ||
commits if your PR already received reviews or comments. | ||
Before submitting a Pull Request, please ensure you've done the following: | ||
- 📖 Read the TBD Developer Website Contributing Guide: https://github.com/TBD54566975/developer.tbd.website/blob/main/CONTRIBUTING.md. | ||
- 📖 Read the TBD Developer Website Code of Conduct: https://github.com/TBD54566975/developer.tbd.website/blob/main/CODE_OF_CONDUCT.md. | ||
- 👷♀️ Create small PRs. In most cases, this will be possible. | ||
- ✅ Provide tests for your changes. | ||
- 📝 Use descriptive commit messages. | ||
- 📗 Update any related documentation and include any relevant screenshots. | ||
--> | ||
|
||
## What type of PR is this? (check all applicable) | ||
|
||
- [ ] ♻️ Refactor | ||
- [ ] ✨ New Feature | ||
- [ ] 🐛 Bug Fix | ||
- [ ] 📝 Documentation Update | ||
- [ ] 👷 Example Application | ||
- [ ] 🧑💻 Code Snippet | ||
- [ ] 🎨 Design | ||
- [ ] 📖 Content | ||
- [ ] 🧪 Tests | ||
- [ ] 🔖 Release | ||
- [ ] 🚩 Other | ||
|
||
## Description | ||
|
||
<!-- Please do not leave this blank --> | ||
|
||
This PR [adds/removes/fixes/replaces] this [feature/bug/etc]. | ||
|
||
## Related Tickets & Documents | ||
<!-- | ||
Please use this format link issue numbers: Resolves #123 | ||
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 | ||
--> | ||
Resolves # | ||
|
||
## Mobile & Desktop Screenshots/Recordings | ||
|
||
<!-- Visual changes require screenshots --> | ||
|
||
## Added code snippets? | ||
- [ ] 👍 yes | ||
- [ ] 🙅 no, because they aren't needed | ||
|
||
## Added tests? | ||
|
||
- [ ] 👍 yes | ||
- [ ] 🙅 no, because they aren't needed | ||
- [ ] 🙋 no, because I need help | ||
|
||
### No tests? Add a note | ||
<!-- | ||
If you didn't provide tests with this PR, please explain here why they aren't needed. | ||
--> | ||
|
||
## Added to documentation? | ||
|
||
- [ ] 📜 readme | ||
- [ ] 📜 contributing.md | ||
- [ ] 📓 general documentation | ||
- [ ] 🙅 no documentation needed | ||
|
||
### No docs? Add a note | ||
<!-- | ||
If you didn't provide documentation with this PR, please explain here why it's not needed. | ||
--> | ||
|
||
## [optional] Are there any post-deployment tasks we need to perform? | ||
|
||
|
||
|
||
## [optional] What gif best describes this PR or how it makes you feel? | ||
|
||
|
||
|
||
<!-- note: PRs with deletes sections will be marked invalid --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Propagate Issue Labels to PR | ||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
jobs: | ||
copy_labels: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Get issue number from PR body | ||
id: issue_number | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const prBody = context.payload.pull_request.body || ''; | ||
// Remove HTML comments | ||
const bodyWithoutComments = prBody.replace(/<!--[\s\S]*?-->/g, ''); | ||
// Find issue number | ||
const match = bodyWithoutComments.match(/(?:Resolves|Closes) #(\d+)/); | ||
const issueNumber = match ? match[1] : null; | ||
if (issueNumber) { | ||
console.log(`Issue number found: ${issueNumber}`); | ||
core.setOutput('has_issue', 'true'); | ||
core.setOutput('issue_number', issueNumber); | ||
} else { | ||
console.log('No issue number found in PR body'); | ||
core.setOutput('has_issue', 'false'); | ||
} | ||
- name: Get labels from linked issue | ||
if: steps.issue_number.outputs.has_issue == 'true' | ||
uses: actions/github-script@v6 | ||
id: issue_labels | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const issue_number = ${{ steps.issue_number.outputs.issue_number }}; | ||
try { | ||
const issue = await github.rest.issues.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: parseInt(issue_number) | ||
}); | ||
return issue.data.labels.map(label => label.name); | ||
} catch (error) { | ||
console.log(`Error fetching issue labels: ${error}`); | ||
return []; | ||
} | ||
- name: Check for required labels | ||
if: steps.issue_number.outputs.has_issue == 'true' && steps.issue_labels.outputs.result != '[]' | ||
id: check_labels | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const labels = ${{ steps.issue_labels.outputs.result }}; | ||
const hacktoberfestLabel = labels.some(label => label.toLowerCase().includes('hacktoberfest')); | ||
const sizeLabelPresent = labels.some(label => ['small', 'medium', 'large'].includes(label.toLowerCase())); | ||
return hacktoberfestLabel || sizeLabelPresent; | ||
- name: Add labels to PR | ||
if: steps.issue_number.outputs.has_issue == 'true' && steps.check_labels.outputs.result == 'true' | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const pr_number = context.issue.number; | ||
const labels = ${{ steps.issue_labels.outputs.result }}; | ||
try { | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: pr_number, | ||
labels: labels | ||
}); | ||
console.log('Labels added successfully'); | ||
} catch (error) { | ||
console.log(`Error adding labels: ${error}`); | ||
} |