Skip to content

gh pr create --web prevents selection of template #7804

Closed

Description

@ivirshup

Describe the bug

$ gh --version
gh version 2.32.1 (2023-07-24)
https://github.com/cli/cli/releases/tag/v2.32.1

If you pass --web to gh pr create you can't select a template either interactively or with the --template argument.

Steps to reproduce the behavior

I have a demo repo (https://github.com/ivirshup/gh-pr-create-web-with-template) with two pr templates:

  • .github/PULL_REQUEST_TEMPLATE/another_pr_template.md
  • .github/pull_request_template.md

Note

The bug still occurs if both templates are in the PULL_REQUEST_TEMPLATE directory.

Cloning this repo and preparing to open a pr

gh repo clone ivirshup/gh-pr-create-web-with-template
cd gh-pr-create-web-with-template

git checkout -b "a-branch"
git commit --allow-empty -m "Empty-Commit"

Opening a PR

git checkout main
git checkout -b "gh-pr-create-web-with-template"
git commit --allow-empty -m "Using gh pr create --web --template=another_pr_template.md"
gh pr create --web --template=another_pr_template.md

This creates a PR using .github/pull_request_template.md, without any warning or error.

image
git checkout main
git checkout -b "gh-pr-create-web"
git commit --allow-empty -m "Using gh pr create --web"
gh pr create --web

This creates a PR using .github/pull_request_template.md, there is no prompting to choose a different template.

image

If .github/pull_request_template.md had been put under PULL_REQUEST_TEMPLATES, I would have opened a blank PR.


git checkout main
git checkout -b "gh-pr-create"
git commit --allow-empty -m "Using gh pr create"
gh pr create

This allows selection of a template:

image

A template can also be specified correctly with --template so long as --web its not passed.

Expected vs actual behavior

I would expect gh pr create --web --template=another_pr_template.md to create a PR using the specified template.

I would have liked for gh pr create --web to have let me choose a pr template.

Logs

log
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹main›
$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹main›
$ git checkout -b "gh-pr-create"
Switched to a new branch 'gh-pr-create'
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create›
$ gh pr create
? Where should we push the 'gh-pr-create' branch? ivirshup/gh-pr-create-web-with-template

Creating pull request for gh-pr-create into main in ivirshup/gh-pr-create-web-with-template

? Title 

isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create›
$ git commit --allow-empty -m "Using gh pr create"
[gh-pr-create a08e79c] Using gh pr create
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create›
$ gh pr create      
? Where should we push the 'gh-pr-create' branch? ivirshup/gh-pr-create-web-with-template

Creating pull request for gh-pr-create into main in ivirshup/gh-pr-create-web-with-template

? Title Using gh pr create
? Choose a template another_pr_template.md
? Body <Received>
? What's next? Submit
remote: 
remote: 
To https://github.com/ivirshup/gh-pr-create-web-with-template.git
 * [new branch]      HEAD -> gh-pr-create
branch 'gh-pr-create' set up to track 'origin/gh-pr-create'.
https://github.com/ivirshup/gh-pr-create-web-with-template/pull/2
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create›
$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹main›
$ git checkout -b "gh-pr-create-web"
Switched to a new branch 'gh-pr-create-web'
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create-web›
$ git commit --allow-empty -m "Using gh pr create --web"
[gh-pr-create-web 18e1819] Using gh pr create --web
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create-web›
$ gh pr create --web
? Where should we push the 'gh-pr-create-web' branch? ivirshup/gh-pr-create-web-with-template
remote: 
remote: 
To https://github.com/ivirshup/gh-pr-create-web-with-template.git
 * [new branch]      HEAD -> gh-pr-create-web
branch 'gh-pr-create-web' set up to track 'origin/gh-pr-create-web'.
Opening github.com/ivirshup/gh-pr-create-web-with-template/compare/main...gh-pr-create-web in your browser.
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create-web›
$ git checkout main
git checkout -b "gh-pr-create-web-with-template"
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
Switched to a new branch 'gh-pr-create-web-with-template'
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create-web-with-template›
$ git commit --allow-empty -m "Using gh pr create --web --template=another_pr_template.md"
[gh-pr-create-web-with-template acf6799] Using gh pr create --web --template=another_pr_template.md
isaac@Mimir:~/tmp/gh-pr-create-web-with-template ‹gh-pr-create-web-with-template›
$ gh pr create --web --template=another_pr_template.md
? Where should we push the 'gh-pr-create-web-with-template' branch? ivirshup/gh-pr-create-web-with-template
remote: 
remote: 
To https://github.com/ivirshup/gh-pr-create-web-with-template.git
 * [new branch]      HEAD -> gh-pr-create-web-with-template
branch 'gh-pr-create-web-with-template' set up to track 'origin/gh-pr-create-web-with-template'.
Opening github.com/ivirshup/gh-pr-create-web-with-template/compare/main...gh-pr-create-web-with-template in your browser.

Activity

  1. samcoe commented on Aug 6, 2023

    @samcoe
    Contributor

    @ivirshup Thanks for writing in. I was able to reproduce this bug. The pr create command is not taking the --template flag into account when using the --web flag. Here is the place in the code that needs to be adjusted to fix the bug to include the template in the query parameters per this doc.

    As for allowing pr create --web to give the user a choice of template, that is a platform behavior that we do not have control over. The web does not have a nice template chooser when opening a pull request like there is when opening a new issue.

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    and removed on Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-prrelating to the gh pr commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions