This repository provides two methods to close all open pull requests with a comment explaining that this is a template repository maintained by the Codespaces team:
- Node.js Script - Run locally with a GitHub token
- GitHub Actions Workflow - Trigger from the GitHub UI (recommended)
- Go to the repository on GitHub
- Click on Actions tab
- Select Close Open Pull Requests workflow from the left sidebar
- Click Run workflow button
- Choose whether to do a dry run first (recommended):
- Select
truefor dry run (lists PRs without closing them) - Select
falseto actually close the PRs
- Select
- Click Run workflow to start
- No need to install anything locally
- Uses built-in GitHub authentication
- Safe dry-run mode to preview what will happen
- All actions are logged in the workflow run
- Can be scheduled or triggered by events
This script closes all open pull requests in the github/haikus-for-codespaces repository with a comment explaining that this is a template repository maintained by the Codespaces team.
- Node.js installed
- A GitHub Personal Access Token with
repopermissions
- Go to https://github.com/settings/tokens
- Click "Generate new token" (classic)
- Give it a descriptive name like "Close PRs Script"
- Select the
reposcope (full control of private repositories) - Click "Generate token"
- Copy the token immediately (you won't be able to see it again)
# Set your GitHub token as an environment variable
export GITHUB_TOKEN=your_github_token_here
# Run the script
node close-prs.jsOr in a single command:
GITHUB_TOKEN=your_github_token_here node close-prs.js- Fetches all open pull requests in the repository
- For each open PR:
- Adds a comment: "This is a template repo, with changes owned by the Codespaces team."
- Closes the pull request
- Reports the status of each operation
Fetching open PRs for github/haikus-for-codespaces...
Found 8 open pull request(s).
Processing PR #463: [WIP] Force close all open PRs in template repo
Adding comment...
Closing PR...
✓ Successfully closed PR #463
Processing PR #462: Create from wahyu to ania
Adding comment...
Closing PR...
✓ Successfully closed PR #462
...
Done!
- Never commit your GitHub token to the repository
- Use environment variables to pass sensitive credentials
- The token should have minimal required permissions (repo scope)
- Consider deleting the token after use
If you have gh (GitHub CLI) installed, you can also use it:
# List all open PRs
gh pr list --repo github/haikus-for-codespaces --state open
# Close each PR with a comment (manual approach)
gh pr close <PR_NUMBER> --repo github/haikus-for-codespaces --comment "This is a template repo, with changes owned by the Codespaces team."- This script uses the native Node.js
httpsmodule (no external dependencies required) - The script will process all open PRs, including the one it was created from
- Failed operations are logged but don't stop the script from processing remaining PRs