Skip to content

Getting "template not found" errors for gh pr create --template=... #9220

Closed

Description

@dbatten5

Describe the bug

Running through the gh pr create interactive steps picks up template in .github/pull_request_template.md, however if I supply a --template option in gh pr create --template=/path/to/template then I get template "/path/to/template" not found. I've tried both relative and absolute paths and can't get either of them to pick up the template file successfully.

gh version 2.49.2 (2024-05-13)
https://github.com/cli/cli/releases/tag/v2.49.2

Steps to reproduce the behavior

  1. Have a template located at /path/to/template.md
  2. Run gh pr create --template /path/to/template.md
  3. See the error

Expected vs actual behavior

Expect to have the template injected into my editor for interactive editing. Actually just get an error

Activity

  1. williammartin commented on Jun 24, 2024

    @williammartin
    Member

    Have you tried just providing the name of the file e.g gh pr create --template template.md

    During the PR creation flow we request the templates from the API with a query like so:

    * Request at 2024-06-24 17:29:20.455123 +0200 CEST m=+6.414875459
    * Request to https://api.github.com/graphql
    > POST /graphql HTTP/1.1
    > Host: api.github.com
    > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
    > Authorization: token ████████████████████
    > Content-Length: 211
    > Content-Type: application/json
    > Graphql-Features: merge_queue
    > Time-Zone: Europe/Amsterdam
    > User-Agent: GitHub CLI 2.50.0
    
    GraphQL query:
    query PullRequestTemplates($name:String!$owner:String!){repository(owner: $owner, name: $name){pullRequestTemplates{filename,body}}}
    GraphQL variables: {"name":"test-repo","owner":"williammartin-test-org"}
    
    < HTTP/2.0 200 OK
    < Access-Control-Allow-Origin: *
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
    < Content-Security-Policy: default-src 'none'
    < Content-Type: application/json; charset=utf-8
    < Date: Mon, 24 Jun 2024 15:29:20 GMT
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Server: GitHub.com
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < Vary: Accept-Encoding, Accept, X-Requested-With
    < X-Accepted-Oauth-Scopes: repo
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: deny
    < X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
    < X-Github-Request-Id: E6C3:2D8CF9:163D0130:16735E4B:667990CC
    < X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
    < X-Oauth-Scopes: gist, read:org, repo, workflow
    < X-Ratelimit-Limit: 5000
    < X-Ratelimit-Remaining: 5000
    < X-Ratelimit-Reset: 1719243742
    < X-Ratelimit-Resource: graphql
    < X-Ratelimit-Used: 138
    < X-Xss-Protection: 0
    
    {
      "data": {
        "repository": {
          "pullRequestTemplates": [
            {
              "filename": "pull_request_template.md",
              "body": "FOOBAR\n"
            }
          ]
        }
      }
    }
    
    * Request took 312.929417ms
    

    I think we then use the --template arg to match the filename here. The templates can exist in different locations in the git repo. I'm not exactly sure what happens if they are not unique.

  2. added
    more-info-neededMore info needed from user/contributor
    and removed on Jun 24, 2024
  3. PhilippFeO commented on Jul 17, 2024

    @PhilippFeO

    I have the same issue with gh issue create --template FILE

  4. williammartin commented on Jul 23, 2024

    @williammartin
    Member

    With @PhilippFeO being addressed in #9327 and this issue most likely being a result of misunderstood flag values, I've updated the examples for issue create and pr create to demonstrate that we only expect the filename, not the full file path in #9354 . Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

more-info-neededMore info needed from user/contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions