Skip to content

Commit

Permalink
Update pr-stats.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
leopic authored Aug 10, 2024
1 parent e746938 commit 45de6b5
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions .github/workflows/pr-stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: PR Stats

on:
workflow_dispatch:
push:
branches:
- stats

jobs:
pr-stats:
Expand All @@ -13,18 +10,13 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run pr_stats.sh
- name: Generate PR stats
env:
GITHUB_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
NUM_PRS: 500
run: |
# GitHub repository information
REPO=${REPO}
# Number of PRs to fetch
NUM_PRS=500
# Fetch the last NUM_PRS PRs
prs=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/pulls?state=closed&per_page=$NUM_PRS" | jq -r '.[].number')
Expand All @@ -39,35 +31,36 @@ jobs:
# Loop through each PR number
for pr in $prs; do
# Fetch the PR details
pr_details=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/pulls/$pr")
# Fetch the PR details
pr_details=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/pulls/$pr")
# Extract lines added and deleted
lines_added=$(echo $pr_details | jq '.additions')
lines_deleted=$(echo $pr_details | jq '.deletions')
# Extract lines added and deleted
lines_added=$(echo $pr_details | jq '.additions')
lines_deleted=$(echo $pr_details | jq '.deletions')
# Calculate lines changed
lines_changed=$((lines_added + lines_deleted))
# Calculate lines changed
lines_changed=$((lines_added + lines_deleted))
# Accumulate totals
total_added=$((total_added + lines_added))
total_deleted=$((total_deleted + lines_deleted))
total_changed=$((total_changed + lines_changed))
# Accumulate totals
total_added=$((total_added + lines_added))
total_deleted=$((total_deleted + lines_deleted))
total_changed=$((total_changed + lines_changed))
# Add to the list of lines changed
lines_changed_list+=($lines_changed)
# Add to the list of lines changed
lines_changed_list+=($lines_changed)
# Output individual PR stats
echo "PR #$pr - Added: $lines_added, Deleted: $lines_deleted, Changed: $lines_changed"
# Output individual PR stats
echo "PR #$pr - Added: $lines_added, Deleted: $lines_deleted, Changed: $lines_changed"
done
# Calculate average lines changed
num_prs=${#lines_changed_list[@]}
average_changed=$((total_changed / num_prs))
# Output total stats
echo "Total lines added: $total_added"
echo "Total lines deleted: $total_deleted"
echo "Total lines changed: $total_changed"
echo "Average lines changed: $average_changed"
echo "| Total PRs: $num_prs"
echo "| Total lines added: $total_added"
echo "| Total lines deleted: $total_deleted"
echo "| Total lines changed: $total_changed"
echo "| Average lines changed: $average_changed"

0 comments on commit 45de6b5

Please sign in to comment.