You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--template does not work with --web when creating pull request #9325
I expect the template query parameter to be added to the URL. Even if the template does not exist in the repository because you may want to select an org-wide central pull request template. For example, swiftlang has such a template for pull requests to compiler-aligned release branches.
Yeh this also looks like it is a problem for issue create --template <template> --web.
Do you think we should validate the value provided here and error if it doesn't exist, or just pass it on regardless? I think for the most part looking at the code right now we generally just say "ok if you say so" when opening via --web.
It would be helpful to not error unless it can be verified that the template does not exist on both the repository and org levels. We at swiftlang share an org-wide template for pull requests to release branches across many compiler-aligned repositories, and a lot of these repositories in turn have their own custom default templates. gh pr create behaves such that any repository-level templates shadow org-wide ones (e.g. they are not shown in the interactive dropdown), so --template release.md --web would be a convenient way for us to tap into the org-wide template without having to manually insert the query parameter. Thanks!
Hmmmm, is there any chance that one of the repositories with shadowed templates is public. That doesn't seem like desirable behaviour, I'd like to look into it!
Sure, we’re open source. https://github.com/swiftlang/swift is an example. To be clear, it is the org-wide template that is shadowed or supplanted by repository templates.
That doesn't seem like desirable behaviour
This behavior is apparently analogous to the one explicitly specified for issue templates. I can see how this could’ve been an informed decision, though: A shared template is one use case for org-wide templates. Another one is a default template that only kicks in when a repo doesn’t have any of its own.
You have repositories that have their own PR templates that shadow the org level ones e.g. for the swift repo.
When you run gh pr create you are only offered the template from the repository, similar to what the docs say about issues[1]
It's possible to use an org level template via the browser ?template= query param, which is why you want this feature
If a repository has any files in its own .github/ISSUE_TEMPLATE folder, including issue templates or a config.yml file, none of the contents of the default .github/ISSUE_TEMPLATE folder will be used.
Is my understanding correct?
Looking at the queries for gh pr create via GH_DEBUG=api I don't believe we could do a verification step because we would not be given information about the org templates which seems to be what you want.
What I think "isn't desirable" behaviour is that you can create PRs from templates via the browser that you can't do via the API, or at least not via the information the API gives you for templates (since the template is just used to create a PR body that you can edit).
Yes. But I’m only really asking for --template <template> --web to work. The part about offering org templates in the CLI sounds like a larger topic that would benefit from more feedback because there are reasonable use cases for both hiding and not hiding them.
I don't believe we could do a verification step
Totally fine with me. My point in this regard was that if exhaustive verification is an option, it would probably make sense to do so to guard against typos in template names and such.
because we would not be given information about the org templates
Hm. Then how come gh pr create offers org templates when there are no repo templates?
Hm. Then how come gh pr create offers org templates when there are no repo templates?
The API reflects the rules as written in the docs, serving the repo templates when they exist and otherwise falling back to the org templates.
You can see in the two GH_DEBUG=api gh pr create snippets below that in the first case there are two repo templates and in the second case just one org template. Well, you can't tell from the API where they come from but you can see the org template here and the commit where I removed the repo templates here.
When I create a PR with gh pr create --template filename.md --web Then my browser is opened with the PR creation URL containing the query param template=filename.md
Issues
When I create a PR with gh issue create --template filename.md --web Then my browser is opened with the Issue creation URL containing the query param template=filename.md
Note that since the web flow can allow for templates that are shadowed to be referenced, we cannot validate the value of the template flag.
Note that gh pr create --template filename.md without the --web flag will validate the value of the flag, because it is used for the contents of the body which are provided in the URL. However, since the template is used locally to form the body, it's not expected that if you select Continue in browser that it would contain the template=filename.md query param.
Note you cannot currently provide --body and --template, so it's correctly not possible to end up with both body and template in the URL as query params.
Activity
williammartin commentedon Jul 18, 2024
Yeh this also looks like it is a problem for
issue create --template <template> --web.Do you think we should validate the value provided here and error if it doesn't exist, or just pass it on regardless? I think for the most part looking at the code right now we generally just say "ok if you say so" when opening via
--web.AnthonyLatsis commentedon Jul 18, 2024
Hi William!
It would be helpful to not error unless it can be verified that the template does not exist on both the repository and org levels. We at swiftlang share an org-wide template for pull requests to release branches across many compiler-aligned repositories, and a lot of these repositories in turn have their own custom default templates.
gh pr createbehaves such that any repository-level templates shadow org-wide ones (e.g. they are not shown in the interactive dropdown), so--template release.md --webwould be a convenient way for us to tap into the org-wide template without having to manually insert the query parameter. Thanks!williammartin commentedon Jul 18, 2024
Hmmmm, is there any chance that one of the repositories with shadowed templates is public. That doesn't seem like desirable behaviour, I'd like to look into it!
AnthonyLatsis commentedon Jul 18, 2024
Sure, we’re open source. https://github.com/swiftlang/swift is an example. To be clear, it is the org-wide template that is shadowed or supplanted by repository templates.
This behavior is apparently analogous to the one explicitly specified for issue templates. I can see how this could’ve been an informed decision, though: A shared template is one use case for org-wide templates. Another one is a default template that only kicks in when a repo doesn’t have any of its own.
williammartin commentedon Jul 18, 2024
I'm sorry @AnthonyLatsis, maybe it's late in a hot day in my office but I'm finding myself confused, sorry for being a bit dense.
Here's my understanding of your situation:
gh pr createyou are only offered the template from the repository, similar to what the docs say about issues[1]?template=query param, which is why you want this featureIs my understanding correct?
Looking at the queries for
gh pr createviaGH_DEBUG=apiI don't believe we could do a verification step because we would not be given information about the org templates which seems to be what you want.What I think "isn't desirable" behaviour is that you can create PRs from templates via the browser that you can't do via the API, or at least not via the information the API gives you for templates (since the template is just used to create a PR body that you can edit).
AnthonyLatsis commentedon Jul 18, 2024
All good, I appreciate your mindfulness.
Yes. But I’m only really asking for
--template <template> --webto work. The part about offering org templates in the CLI sounds like a larger topic that would benefit from more feedback because there are reasonable use cases for both hiding and not hiding them.Totally fine with me. My point in this regard was that if exhaustive verification is an option, it would probably make sense to do so to guard against typos in template names and such.
Hm. Then how come
gh pr createoffers org templates when there are no repo templates?williammartin commentedon Jul 18, 2024
The API reflects the rules as written in the docs, serving the repo templates when they exist and otherwise falling back to the org templates.
You can see in the two
GH_DEBUG=api gh pr createsnippets below that in the first case there are two repo templates and in the second case just one org template. Well, you can't tell from the API where they come from but you can see the org template here and the commit where I removed the repo templates here.AnthonyLatsis commentedon Jul 19, 2024
Ah, I see. Thanks for clarifying!
williammartin commentedon Jul 23, 2024
Acceptance Criteria
PRs
When I create a PR with
gh pr create --template filename.md --webThen my browser is opened with the PR creation URL containing the query param
template=filename.mdIssues
When I create a PR with
gh issue create --template filename.md --webThen my browser is opened with the Issue creation URL containing the query param
template=filename.mdNote that since the web flow can allow for templates that are shadowed to be referenced, we cannot validate the value of the template flag.
Note that
gh pr create --template filename.mdwithout the--webflag will validate the value of the flag, because it is used for the contents of the body which are provided in the URL. However, since the template is used locally to form the body, it's not expected that if you selectContinue in browserthat it would contain thetemplate=filename.mdquery param.Note you cannot currently provide
--bodyand--template, so it's correctly not possible to end up with both body and template in the URL as query params.AnthonyLatsis commentedon Sep 12, 2024
Hi William, sorry for this delay. No objections from me here, thanks.
cc @Kyle-Ye