Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(actions): add workflow to calculate and surface PR merge rate #17684

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ci(actions): add workflow to calculate and surface PR merge rate
tay1orjones committed Oct 8, 2024
commit f580951370d0aa797a7fcc4237522c82291c39b7
60 changes: 60 additions & 0 deletions .github/workflows/metrics-merge-rate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Calculate PR Merge Rate

on:
schedule:
- cron: '0 12 * * 1' # Runs every Monday at 12:00 UTC
workflow_dispatch: # Allows manual runs from the GitHub Actions tab

jobs:
calculate-merge-rate:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Calculate merge rate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: 'carbon-design-system/carbon'
run: |
START_DATE=$(date --date="7 days ago" +%Y-%m-%d)
END_DATE=$(date +%Y-%m-%d)
echo "Calculating merge rate for the past week ($START_DATE to $END_DATE) for repository $REPO"
# Get merged PRs within the date range
MERGED_COUNT=$(gh pr list --repo "$REPO" --state merged --search "merged:$START_DATE..$END_DATE" --limit 1000 | wc -l)
# Get all PRs created within the date range
TOTAL_COUNT=$(gh pr list --repo "$REPO" --state all --search "created:$START_DATE..$END_DATE" --limit 1000 | wc -l)
if [ "$TOTAL_COUNT" -gt 0 ]; then
MERGE_RATE=$(echo "scale=2; ($MERGED_COUNT / $TOTAL_COUNT) * 100" | bc)
MERGE_MESSAGE="Merge Rate for the past week: $MERGE_RATE% (Merged PRs: $MERGED_COUNT, Total PRs created: $TOTAL_COUNT)"
else
MERGE_MESSAGE="No PRs found in the repository for the past week. Merge Rate: 0% (Merged PRs: $MERGED_COUNT, Total PRs created: $TOTAL_COUNT)"
fi
echo "$MERGE_MESSAGE"
echo "MERGE_MESSAGE=$MERGE_MESSAGE" >> $GITHUB_ENV
# Write to GitHub Actions Job Summary (markdown)
echo "## Weekly Merge Rate Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Date Range**: $START_DATE to $END_DATE" >> $GITHUB_STEP_SUMMARY
echo "- **Merged PRs**: $MERGED_COUNT" >> $GITHUB_STEP_SUMMARY
echo "- **Total PRs created**: $TOTAL_COUNT" >> $GITHUB_STEP_SUMMARY
echo "- **Merge Rate**: $MERGE_RATE%" >> $GITHUB_STEP_SUMMARY
- name: Send message to Slack
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
with:
payload: |
{
"username": "🚢 Merge rate",
"icon_url": "https://user-images.githubusercontent.com/3360588/192045905-5d9705af-92e2-4432-805e-15db98571e8b.png",
"channel": "#carbon-system-notifications",
"text": "${{ env.MERGE_MESSAGE }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
19 changes: 19 additions & 0 deletions .github/workflows/metrics-repo-stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Collect GitHub Repo Statistics

on:
schedule:
# Run this once per day, towards the end of the day for keeping the most
# recent data point most meaningful (hours are interpreted in UTC).
- cron: '0 14 * * *'
workflow_dispatch: # Allow for running this manually.

jobs:
j1:
name: github-repo-stats
runs-on: ubuntu-latest
steps:
- name: run-ghrs
# Use latest release.
uses: jgehrcke/github-repo-stats@306db38ad131cab2aa5f2cd3062bf6f8aa78c1aa #1.4.2
with:
ghtoken: ${{ secrets.PERSONAL_ACCESS_TOKEN }}