Skip to content

Clean up fetch data #276

Clean up fetch data

Clean up fetch data #276

Workflow file for this run

name: Check PR size
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check_pr_size:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate changed lines
id: diff_check
run: |
# Get the target branch commit (base) and the PR branch commit (head)
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Base SHA: $BASE_SHA"
echo "Head SHA: $HEAD_SHA"
# Compute the merge base between the two branches
MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA")
echo "Merge Base: $MERGE_BASE"
# Calculate added and deleted lines between the merge base and the head commit
TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \
| awk '{ added += $1; deleted += $2 } END { print added + deleted }')
# Default to 0 if nothing is output
TOTAL_CHANGED=${TOTAL_CHANGED:-0}
echo "Total changed lines: $TOTAL_CHANGED"
# Make the total available for later steps
echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT"
- name: Fail if too many changes
if: ${{ steps.diff_check.outputs.total > 500 }}
run: |
echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit."
echo "Please reduce the size of this PR."
exit 1