diff --git a/.github/workflows/metrics-merge-rate.yml b/.github/workflows/metrics-merge-rate.yml new file mode 100644 index 000000000000..a654658f93da --- /dev/null +++ b/.github/workflows/metrics-merge-rate.yml @@ -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 diff --git a/.github/workflows/metrics-repo-stats.yml b/.github/workflows/metrics-repo-stats.yml new file mode 100644 index 000000000000..6d61a7261445 --- /dev/null +++ b/.github/workflows/metrics-repo-stats.yml @@ -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 }}