-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(contributors): update CONTRIBUTORS.md for @username
- Loading branch information
1 parent
81b40b7
commit 0ac3c34
Showing
2 changed files
with
76 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,40 @@ | ||
name: Update Contributors Tiers | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
update-contributors: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Count Merged PRs | ||
id: count_prs | ||
run: | | ||
PR_COUNT=$(gh pr list --author ${{ github.actor }} --state merged --repo ${{ github.repository }} --json number --jq '. | length') | ||
echo "PR_COUNT=$PR_COUNT" >> $GITHUB_ENV | ||
- name: Update CONTRIBUTORS.md | ||
run: | | ||
python scripts/update_contributors.py ${{ github.actor }} $PR_COUNT | ||
- name: Commit and Push Changes to Dedicated Branch | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git checkout -B contributors-updates | ||
git add CONTRIBUTORS.md | ||
git commit -m "Update CONTRIBUTORS.md for ${{ github.actor }}" | ||
git push --set-upstream origin contributors-updates |
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,36 @@ | ||
import sys | ||
import os | ||
|
||
contributor = sys.argv[1] | ||
pr_count = int(sys.argv[2]) | ||
|
||
tiers = { | ||
"Valued Contributor": 10, | ||
"Frequent Contributor": 5, | ||
"First Contributor": 1 | ||
} | ||
|
||
contributors_file_path = os.path.join(os.path.dirname(__file__), '..', 'CONTRIBUTORS.md') | ||
|
||
with open(contributors_file_path, "r") as file: | ||
lines = file.readlines() | ||
|
||
found = False | ||
new_lines = [] | ||
for line in lines: | ||
if contributor in line: | ||
found = True | ||
for tier, count in tiers.items(): | ||
if pr_count >= count: | ||
line = f"| @{contributor} | ![{tier} Badge](https://img.shields.io/badge/{tier.replace(' ', '%20')}-Achieved-blue) |\n" | ||
break | ||
new_lines.append(line) | ||
|
||
if not found: | ||
for tier, count in tiers.items(): | ||
if pr_count >= count: | ||
new_lines.append(f"| @{contributor} | ![{tier} Badge](https://img.shields.io/badge/{tier.replace(' ', '%20')}-Achieved-blue) |\n") | ||
break | ||
|
||
with open(contributors_file_path, "w") as file: | ||
file.writelines(new_lines) |