diff --git a/.github/workflows/pr-size-warning.yml b/.github/workflows/pr-size-warning.yml new file mode 100644 index 00000000..138b43bc --- /dev/null +++ b/.github/workflows/pr-size-warning.yml @@ -0,0 +1,77 @@ +name: PR Size and Artifact Check + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + pull-requests: read + +jobs: + check-pr-size: + runs-on: ubuntu-latest + + env: + GH_TOKEN: ${{ github.token }} + MAX_FILES: 50 + MAX_LINES: 1000 + + steps: + - name: Analyze PR Size and Artifacts + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + CHANGED_FILES=${{ github.event.pull_request.changed_files }} + ADDITIONS=${{ github.event.pull_request.additions }} + DELETIONS=${{ github.event.pull_request.deletions }} + TOTAL_LINES=$((ADDITIONS + DELETIONS)) + + echo "PR Stats:" + echo "- Files changed: $CHANGED_FILES" + echo "- Additions: $ADDITIONS" + echo "- Deletions: $DELETIONS" + echo "- Total lines changed: $TOTAL_LINES" + + WARNINGS="" + + # Check for oversized PRs + if [ "$CHANGED_FILES" -gt "$MAX_FILES" ] || [ "$TOTAL_LINES" -gt "$MAX_LINES" ]; then + MSG="PR is unusually large ($CHANGED_FILES files, $TOTAL_LINES lines changed). Advisory threshold: $MAX_FILES files or $MAX_LINES lines." + echo "::warning title=Large PR Detected::$MSG" + WARNINGS="${WARNINGS} + - ⚠️ **Large PR Detected** + - $MSG + - Consider splitting this PR into smaller reviewable changes. + " + fi + + # Check for generated artifact directories + FILES=$(gh pr view "$PR_NUMBER" \ + --repo "${{ github.repository }}" \ + --json files \ + --jq '.files[].path') + + if echo "$FILES" | grep -qE 'playwright-report/|test-results/'; then + MSG="Generated testing artifacts detected (playwright-report/ or test-results/). Please remove them from commits." + echo "::warning title=Generated Artifacts Included::$MSG" + WARNINGS="${WARNINGS} + - 🚫 **Generated Artifacts Detected** + - $MSG + " + fi + + # Publish GitHub Step Summary + if [ -n "$WARNINGS" ]; then + { + echo "## ⚠️ PR Review Advisory" + echo + echo "$WARNINGS" + echo + echo "> This workflow is advisory only and will not fail CI." + } >> "$GITHUB_STEP_SUMMARY" + else + { + echo "## ✅ PR Size and Content Check Passed" + echo + echo "No unusually large diffs or generated artifacts detected." + } >> "$GITHUB_STEP_SUMMARY" + fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9bebba48..151a8145 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -182,6 +182,12 @@ Your PR should include: Try to keep one pull request focused on one problem. If a change touches unrelated areas, split it into separate PRs when possible. +### PR Size and Generated Artifacts + +To keep reviews manageable, an automated workflow will post an advisory warning if a PR exceeds **50 changed files** or **1,000 total lines**. We encourage splitting unusually large changes into smaller, focused pull requests. + +Additionally, please ensure you never commit auto-generated artifacts (such as `playwright-report/`, `test-results/`, `dist/`, or `.vite/`). The workflow will flag these if they are accidentally included. If this happens, remove them using `git rm --cached -r `. + ## Contribution Scoring Every merged pull request can be scored for GSSoC using labels applied by the project admin or mentor. The scoring engine reads these labels after the PR is merged, so contributors should focus on clear scope, good implementation, and complete review notes rather than self-assigning score labels. @@ -404,4 +410,4 @@ Never commit these auto-generated paths: If CI fails, run: ```bash git rm --cached -echo 'frontend/dist/' >> .gitignore \ No newline at end of file +echo 'frontend/dist/' >> .gitignore