|
| 1 | +# Solution Summary: Close All Open PRs |
| 2 | + |
| 3 | +## Task |
| 4 | +Force close all open pull requests in the `github/haikus-for-codespaces` repository with a comment: "This is a template repo, with changes owned by the Codespaces team." |
| 5 | + |
| 6 | +## Solution Overview |
| 7 | +Since the repository is a template maintained by the Codespaces team, it receives many community PRs that need to be closed. This solution provides two automated approaches to close all open PRs with an explanatory comment. |
| 8 | + |
| 9 | +## Implemented Solutions |
| 10 | + |
| 11 | +### 1. GitHub Actions Workflow (Recommended) |
| 12 | +**File:** `.github/workflows/close-prs.yml` |
| 13 | + |
| 14 | +**Features:** |
| 15 | +- Manually triggered via GitHub UI (workflow_dispatch) |
| 16 | +- Safe dry-run mode (lists PRs without closing them) |
| 17 | +- Built-in GitHub authentication (no token management needed) |
| 18 | +- Handles pagination (supports more than 100 open PRs) |
| 19 | +- Full logging in workflow runs |
| 20 | +- Proper permissions (pull-requests: write, issues: write) |
| 21 | + |
| 22 | +**How to Use:** |
| 23 | +1. Go to repository's Actions tab |
| 24 | +2. Select "Close Open Pull Requests" workflow |
| 25 | +3. Click "Run workflow" |
| 26 | +4. Choose dry_run option (true for preview, false to execute) |
| 27 | +5. Monitor the workflow run for results |
| 28 | + |
| 29 | +**Advantages:** |
| 30 | +- No local setup required |
| 31 | +- Secure (uses GITHUB_TOKEN from workflow context) |
| 32 | +- Auditable (all actions logged in workflow runs) |
| 33 | +- User-friendly (point-and-click interface) |
| 34 | + |
| 35 | +### 2. Node.js Script |
| 36 | +**File:** `close-prs.js` |
| 37 | + |
| 38 | +**Features:** |
| 39 | +- Standalone script using Node.js built-in `https` module |
| 40 | +- No external dependencies required |
| 41 | +- Handles pagination (supports more than 100 open PRs) |
| 42 | +- Comprehensive error handling |
| 43 | +- Clear console output with progress indicators |
| 44 | + |
| 45 | +**How to Use:** |
| 46 | +```bash |
| 47 | +GITHUB_TOKEN=your_token node close-prs.js |
| 48 | +``` |
| 49 | + |
| 50 | +**Advantages:** |
| 51 | +- Can be run from any environment with Node.js |
| 52 | +- Useful for automation scripts or CI/CD pipelines |
| 53 | +- No GitHub Actions minutes consumed |
| 54 | + |
| 55 | +## What Both Solutions Do |
| 56 | + |
| 57 | +For each open PR: |
| 58 | +1. Add a comment: "This is a template repo, with changes owned by the Codespaces team." |
| 59 | +2. Change the PR state to "closed" |
| 60 | +3. Report success or failure for each operation |
| 61 | +4. Continue processing remaining PRs even if one fails |
| 62 | + |
| 63 | +## Documentation |
| 64 | +Comprehensive documentation is provided in `CLOSE_PRS_README.md` including: |
| 65 | +- Detailed usage instructions for both methods |
| 66 | +- How to obtain GitHub tokens (for script method) |
| 67 | +- Security best practices |
| 68 | +- Example outputs |
| 69 | +- Alternative approaches (GitHub CLI) |
| 70 | + |
| 71 | +## Security Considerations |
| 72 | + |
| 73 | +### GitHub Actions Workflow |
| 74 | +✅ Uses built-in GITHUB_TOKEN (automatically scoped to repository) |
| 75 | +✅ No secrets management required |
| 76 | +✅ Proper permission declarations in workflow file |
| 77 | + |
| 78 | +### Node.js Script |
| 79 | +✅ Token passed via environment variable (not command line) |
| 80 | +✅ Token validation at startup |
| 81 | +✅ Uses HTTPS for all API calls |
| 82 | +✅ No external dependencies (reduces supply chain risk) |
| 83 | + |
| 84 | +**CodeQL Results:** 0 security alerts found |
| 85 | + |
| 86 | +## Testing |
| 87 | + |
| 88 | +Both solutions were tested for: |
| 89 | +- ✅ Syntax validation (Node.js --check) |
| 90 | +- ✅ Error handling (missing token, API failures) |
| 91 | +- ✅ Pagination logic (handles repos with >100 PRs) |
| 92 | +- ✅ Security scanning (CodeQL) |
| 93 | +- ✅ Code review feedback addressed |
| 94 | + |
| 95 | +## Current State |
| 96 | + |
| 97 | +The repository currently has **8 open pull requests**: |
| 98 | +- PR #463: [WIP] Force close all open PRs in template repo (this PR) |
| 99 | +- PR #462: Create from wahyu to ania |
| 100 | +- PR #461: Update README.md |
| 101 | +- PR #460: RUIRU MABATI FACTORY |
| 102 | +- PR #459: Create MiniCLIP-ViT |
| 103 | +- PR #458: Rename LICENSE to LICENSE |
| 104 | +- PR #457: B |
| 105 | +- PR #454: Create devcontainer.json |
| 106 | +- PR #453: Create index.html for love letter |
| 107 | + |
| 108 | +## Next Steps |
| 109 | + |
| 110 | +To close all open PRs (including this one): |
| 111 | + |
| 112 | +**Option A: GitHub Actions (Recommended)** |
| 113 | +1. Merge this PR to main branch |
| 114 | +2. Go to Actions tab → Close Open Pull Requests |
| 115 | +3. Run with dry_run=true to preview |
| 116 | +4. Run with dry_run=false to execute |
| 117 | + |
| 118 | +**Option B: Local Script** |
| 119 | +1. Obtain a GitHub token with `repo` permissions |
| 120 | +2. Run: `GITHUB_TOKEN=your_token node close-prs.js` |
| 121 | + |
| 122 | +## Files Changed |
| 123 | +- `close-prs.js` - Node.js script to close PRs (247 lines) |
| 124 | +- `.github/workflows/close-prs.yml` - GitHub Actions workflow (95 lines) |
| 125 | +- `CLOSE_PRS_README.md` - Comprehensive documentation (120 lines) |
| 126 | +- This file: `SOLUTION_SUMMARY.md` - Solution overview |
| 127 | + |
| 128 | +## Notes |
| 129 | +- Both solutions process PRs in the order returned by the GitHub API |
| 130 | +- The PR from which these changes originated (PR #463) will also be closed when either solution runs |
| 131 | +- Failed operations are logged but don't prevent processing of remaining PRs |
| 132 | +- The solutions can be run multiple times safely (idempotent) |
0 commit comments