Skip to content

Commit

Permalink
chore(contributors): update CONTRIBUTORS.md for @username
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanpulver committed Aug 30, 2024
1 parent 81b40b7 commit 0ac3c34
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/update_contributors.yml
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
36 changes: 36 additions & 0 deletions scripts/update_contributors.py
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)

0 comments on commit 0ac3c34

Please sign in to comment.