Close Action
Automatically close pull requests
The Close Action allows you to automatically close pull requests based on validation results. This is useful for enforcing strict policies, handling abandoned PRs, or automating the rejection of PRs that don’t meet specific criteria.
Configuration
Message explaining why the PR was closed (supports templates)
Basic Usage
Examples
Simple Close
Close a PR without detailed explanation:
Close with Explanation
Close a PR with a detailed explanation:
Close with Template Variables
Use template variables to provide context-specific explanations:
How It Works
Process Template
If a reason
is provided, the action processes the template, replacing variables with actual values
Add Comment
If a reason
is provided, it adds a comment with the explanation
Close PR
It changes the PR state to “closed”
Practical Use Cases
Enforce PR Policies
Close PRs that violate important policies:
Automated PR Cleanup
Automatically close stale or abandoned PRs:
Enforce Branch Naming
Close PRs with incorrect branch naming:
Close Duplicate PRs
Close PRs detected as duplicates:
Best Practices
Automatically closing PRs can be discouraging to contributors - use sparingly and with clear communication
Alternatives to Consider
Instead of immediately closing PRs, consider these alternatives:
- Comment with guidance: Explain issues but allow the author to fix them
- Label for visibility: Add labels like “needs-work” or “invalid”
- Request changes: Use GitHub’s review functionality to request changes
- Set expectations: Clearly communicate when a PR might be closed
Template Variables
The Close Action supports these template variables:
Variable | Description |
---|---|
{{ pull_request.user.login }} | PR author’s username |
{{ pull_request.title }} | PR title |
{{ pull_request.body }} | PR description |
{{ pull_request.number }} | PR number |
{{ repository.name }} | Repository name |
{{ repository.full_name }} | Full repository name (owner/repo) |
{{ validation_summary }} | Summary of all validation results |