Skip to content

Commit

Permalink
add (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb authored Jul 18, 2024
1 parent 881e3ad commit 397842f
Showing 1 changed file with 146 additions and 0 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/update-contributor-highlights.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Update Contributor Highlights

on:
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight
workflow_dispatch:

jobs:
update-highlights:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # All history

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Calculate highlights
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python <<EOF
import os
from github import Github
from collections import defaultdict
import logging
EXCLUDED_USERS = ["statefb", "wadabee", "Yukinobu-Mine"] # Core maintainers
logging.basicConfig(level=logging.INFO)
def calculate_score(stats):
# Calculate score based on lines changed and number of PRs
WEIGHT_LINES_CHANGED = 0.7
WEIGHT_PRS = 1000
return stats["lines_changed"] * WEIGHT_LINES_CHANGED + stats["prs"] * WEIGHT_PRS
g = Github(os.environ['GITHUB_TOKEN'])
repo = g.get_repo('${{ github.repository }}')
contributors = defaultdict(lambda: {'commits': 0, 'prs': 0})
logging.info("Fetching commits...")
commits = repo.get_commits()
commit_count = 0
for commit in commits:
if commit.author:
stats = commit.stats
contributors[commit.author.login]["lines_changed"] += (
stats.additions + stats.deletions
)
commit_count += 1
if commit_count % 100 == 0:
logging.info(f"Processed {commit_count} commits...")
logging.info("Fetching pull requests...")
prs = repo.get_pulls(state="closed", sort="created", direction="desc")
pr_count = 0
for pr in prs:
if pr.merged and pr.user:
contributors[pr.user.login]["prs"] += 1
pr_count += 1
if pr_count % 10 == 0:
logging.info(f"Processed {pr_count} pull requests...")
logging.info(f"Total pull requests processed: {pr_count}")
logging.info(f"Total contributors: {len(contributors)}")
logging.info("Calculating contributor scores...")
highlighted_contributors = sorted(
contributors.items(), key=lambda x: calculate_score(x[1]), reverse=True
)
logging.info(f"Top 20 contributors: {highlighted_contributors[:20]}")
PLATINUM_THRESHOLD = 40000
platinum_contributors = [
(username, calculate_score(stats))
for username, stats in highlighted_contributors
if calculate_score(stats) >= PLATINUM_THRESHOLD and username not in EXCLUDED_USERS
]
logging.info(f"Platinum contributors: {platinum_contributors}")
platinum_icon = "🏆"
section_title = f"## {platinum_icon} Significant Contributors\n"
platinum_md = section_title + "\n".join(
[
f"- [{username}](https://github.com/{username})"
for username, score in platinum_contributors
]
)
readme_path = "README.md"
with open(readme_path, "r") as file:
readme_content = file.read()
# Find the "## Contacts" section
contacts_start = readme_content.find("## Contacts")
contacts_end = readme_content.find("\n\n", contacts_start)
# Find the "## Contributors" section
contributors_start = readme_content.find("## Contributors", contacts_end)
# Insert the platinum contributors section between "## Contacts" and "## Contributors"
new_readme_content = (
readme_content[:contacts_end]
+ "\n\n"
+ platinum_md
+ "\n\n"
+ readme_content[contributors_start:]
)
with open(readme_path, "w") as file:
file.write(new_readme_content)
EOF
- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update contributor highlights" || echo "No changes to commit"
git push
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update contributor highlights"
branch: update-contributor-highlights
title: "Update Contributor Highlights"
body: "This pull request updates the contributor highlights in the README.md file."

0 comments on commit 397842f

Please sign in to comment.