Calculate PR Merge Rate #8
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
name: Calculate PR Merge Rate | |
on: | |
schedule: | |
- cron: '0 1 * * 3' # Runs at 1:00 AM UTC every Wednesday | |
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- 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@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1 | |
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 |