PR auto add reviewers and assignee - cesnietor/dev-docs GitHub Wiki

Ok so I got tired of adding the assignee and reviewers to the PRs and created a function using git cli.

Sharing in case it's helpful for someone:

  1. Create Personal Access Token with
  2. repo and admin:org (at least read:org permissions)
  3. Authenticate with your new token:
% gh auth login
What account do you want to log into? GitHub.com
What is your preferred protocol for Git operations on this host? HTTPS
How would you like to authenticate GitHub CLI? Paste an authentication token
  1. Edit your PR like:
gh pr edit https://<your-repo>/pull/637 --add-reviewer "githubuser,githubuser2" --add-assignee <yourgithubuser>

Add this utility function to your ~/.zshrc if wanted to automate it :

Usage: edit_pr <pull_request_url> [--include-design-team] (Update to use your handler and include the proper reviewers)

edit_pr() {
    # Check if the first argument is provided
    if [ -z "$1" ]; then
        echo "Usage: edit_pr <pull_request_url> [--include-design-team]"
        return 1
    fi

    # Assign arguments to variables
    local url="$1"
    local reviewers

    # Define the default and second reviewers lists
    default_reviewers="githubuser,githubuser2"
    design_team_reviewers="githubuser1,githubuser3"

    # Check if the second argument is "--include-design-team"
    if [ "$2" = "--include-design-team" ]; then
        reviewers="$default_reviewers,$design_team_reviewers"
    else
        reviewers="$default_reviewers"
    fi

    # Run the command
    gh pr edit "$url" --add-reviewer "$reviewers" --add-assignee <replace_yourgithubuser>
}

Use it like : edit_pr https://<your-repo>/pull/637 or edit_pr https://<your-repo>/pull/637 --include-design-team And it will add the reviewers by default.

⚠️ **GitHub.com Fallback** ⚠️