This GitHub Action is useful for teams who want to programmatically update and manage existing Pull Requests directly within their CI/CD workflows, leveraging the official GitHub CLI for robust operations.
- Full
gh pr editSupport: Leverages the official GitHub CLI for robust editing, supporting flags like--title,--base,--add-label, and more. - Flexible Identification: Edit a PR using its number, URL, or the associated branch name.
- Simple Integration: One-step usage as a Composite Action in any workflow.
- Powered by GitHub CLI: Uses the official GitHub CLI for secure Pull Request management.
- Organization-wide: Can be used across any repository.
- This action expects the GitHub CLI (
gh) to be available (it is pre-installed on all GitHub-hosted runners, e.g.,ubuntu-latest). - The environment variable
GH_TOKENmust be set to a valid GitHub token with the required write permissions for Pull Requests.
name: Test gh PR Editor Action
on:
workflow_dispatch:
inputs:
pr_url:
description: 'URL or Identifier of the PR to edit'
required: true
jobs:
test-edit-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Edit Pull Request
uses: ws2git/gh-pr-editor-action@v1
env:
GH_TOKEN: ${{ github.token }}
with:
pr_identifier: ${{ github.event.inputs.pr_url }}
edit_options: '--title "Test" --body "testing"'| Name | Required | Description |
|---|---|---|
pr_identifier |
Yes | The target Pull Request identifier (number, URL, or branch name). |
edit_options |
No | A single string containing all the desired gh pr edit flags and their values (e.g., --title "New Title" --add-label "ready"). |
Internally, this action is a Composite Action that executes a shell command. It constructs the final gh pr edit command by combining the pr_identifier input with the edit_options input, and explicitly sets the repository context.
Script logic (Executed in action.yml):
gh pr edit "$PR_IDENTIFIER" --repo "$GITHUB_REPOSITORY" $EDIT_OPTIONSIf the required pr_identifier parameter is missing, the action will fail immediately due to the required: true setting in the action.yml. If the GH_TOKEN is missing or lacks sufficient permissions, the gh command will exit with an error.
This Action uses the GitHub CLI (gh) to perform the editing operation, and gh requires the authentication token to be provided through the environment variable GH_TOKEN.
Recommended: For operations within the current repository, use the default token ${{ github.token }}. This token has restricted, temporary permissions (based on the workflow's permissions block), which minimizes security risk.
env:
GH_TOKEN: ${{ github.token }}Crucial Permission Scopes: To edit a Pull Request, you must grant the necessary write permissions in your workflow:
permissions:
pull-requests: write # Required for editing PR details (title, body, labels, etc.)Advanced Operations/External Repositories: If you need elevated permissions (e.g., editing repository Projects) or access to external repositories, pass a PAT (Personal Access Token) stored as a Secret:
env:
GH_TOKEN: ${{ secrets.MY_PAT_SECRET }}Never expose the PAT in plain text.
If you find a bug or have a question, open an issue.