Search code examples
bashgitgithub-cli

How to create a Pull Request via GitHub CLI with multiple assignees?


I am trying to automate a pull request creation process for GitHub using the GitHub CLI.

I am currently utilizing the following script and it works like a charm:

(
  # Parentheses are used here to avoid the exposure of temporal variables to the outer scope.
  # Tested on macOS bash only.
  
  cd ~/Projects/pet_projects/basic_temperature
   
  # Pushes the release branch to the remote repository.
  git push origin release_nemo

  # Logs in to GitHub CLI using pre-generated access token.
  # https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
  gh auth login --with-token < ~/Projects/pet_projects/.github_cli_access_token
   
# Sets HEREDOC to PR_TITLE variable.
# Indentation is avoided here intentionally.
# https://stackoverflow.com/a/1655389/12201472
read -r -d '' PR_TITLE <<-'TEXT'
This is a Placeholder PR to check whether all specs are green [Current Release][Nemo]
TEXT
 
# Sets HEREDOC to PR_BODY variable.
# Indentation is avoided here intentionally.
# https://stackoverflow.com/a/1655389/12201472
read -r -d '' PR_BODY <<-'MARKDOWN'
[RELEASE CARD TODO]() (**❗This PR is NOT completed yet!❗**)
      
### Already included cards:
- None.
 
### Cards to be included:
- None.
 
### Previous Release TODO
MARKDOWN
 
  gh pr create \
    --title "${PR_TITLE}" \
    --body "${PR_BODY}" \
    --base master \
    --head release_nemo \
    --assignee @me \
    --label Release \
    --web
)

The only problem which I have right now, it is not clear to me how to update this command

gh pr create \
  --title "${PR_TITLE}" \
  --body "${PR_BODY}" \
  --base master \
  --head release_nemo \
  --assignee @me \
  --label Release \
  --web

to assign multiple assignees to the newly created PR?

I have read the gh pr create docs carefully and I haven't found a way how to achieve it yet.

Thanks in advance for any help.


Solution

  • The gh command uses github.com/spf13/cobra for command line flag parsing, and the Assignees field is a StringSlice. According to the cobra docs, you can provide the flag multiple times or separate multiple values with a comma.

    So you can do --assignee @me --assignee @you or --assignee @me,@you.