-
Notifications
You must be signed in to change notification settings - Fork 1.8k
60 lines (50 loc) · 2.59 KB
/
metrics-merge-rate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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