Skip to content

Edit PR with GH CLI

Actions
Action para editar um Pull Request existente usando o comando gh pr edit e seus flags
v1
Latest
Star (0)

gh PR Editor Action

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.


✨ Features

  • Full gh pr edit Support: 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.

🛠️ Usage

1. Prerequisites

  • 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_TOKEN must be set to a valid GitHub token with the required write permissions for Pull Requests.

2. Example Workflow Integration

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"'

📥 Inputs

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").

⚙️ How It Works

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_OPTIONS

If 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.

🛡️ Security and Authentication

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.


🔗 Related Documentation

❓ Support

If you find a bug or have a question, open an issue.

Edit PR with GH CLI is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Action para editar um Pull Request existente usando o comando gh pr edit e seus flags
v1
Latest

Edit PR with GH CLI is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.