Github pull request template detect YAML front matter using config.yml and apply to fields

Viewed 1066

I am looking to create a pull request template in GitHub where Github is able to take the YAML front matter similar to Issue_templates and parse it into the correct fields. In Github docs under Supported file types => config.yml it claims to allow pull request template configuration.

GitHub Docs to Example below:


---
name: Name of pull request template 
about: "Use this template for setting up your PR description"
title: "Add support for the new feature"
labels: bug, enhancement, customer-request
assignees: self
---

The only relevant information was to pass the keys as query parameters to display one of the multiple templates, see link below.

Docs:

2 Answers

Having tested this personally, it appears that GitHub doesn't parse YAML front matter for Pull Request templates at present. You can have a single default template pull_request_template.md, and custom ones in PULL_REQUEST_TEMPLATE/ accessible with the GET query template=. In both cases however, a front matter block will be displayed as part of the body, not parsed.

The documentation isn't very clear about this, but a config.yml can only be used to configure the issue template chooser. At present, there is no pull request template chooser to configure.

You can submit a feature request for this using the contact support form, and selecting Pull requests and code review for the What part of GitHub is your feedback about? option. That is according to this answer on the community forum.

One way around this, in the meantime, might be to leave a message in your default (pull_request_template.md), pointing to for example, your CONTRIBUTING.md. Then, in that file, you could include links for each type of pull request with custom GET queries. For example, with PULL_REQUEST_TEMPLATE/custom.md the link might be (url broken up for convenience):

https://github.com/<user>/<repo>/compare/<base>...<compare>?
template=custom.md
&title=Add+support+for+the+new+feature
&labels=bug%2Cenhancement%2Ccustomer-request
&assignees=self

As per the supported query params.

After much trial and error you're not able to use a YAML front matter at this time. The only way is to use the query parameters in the URL.

https://github.com/url/to/pr?
template=custom_template_pr.md
&title=Add+support+for+the+new+feature
&labels=bug%2Cenhancement%2Ccustomer-request
&assignees=self
Related