Sub topic 10
Prefilling Fields with Query Parameters
You can link to a new issue or pull request with some fields already filled in. GitHub reads these values from the URL query string, which is the part after the ?. This chapter assumes you know how issue templates, issue forms, and multiple pull request templates are set up. It also assumes you know what a URL query string is.
Why prefill
A prefilled link saves the reader typing and keeps reports consistent. Common uses include:
- A "Report a bug" link in your documentation that opens the bug form with a title and label already set.
- An error message in your app that links to an issue with the version number filled in.
- A hotfix workflow that always opens the pull request with the hotfix template.
The basic URL shape
The two examples below come from the plan for this tutorial. The first opens a new issue and the second opens a new pull request.
https://github.com/OWNER/REPO/issues/new?template=bug_report.yml&title=Crash+on+startup&labels=bug
https://github.com/OWNER/REPO/compare/main...my-branch?quick_pull=1&template=hotfix.mdEach parameter does one job:
| Parameter | Applies to | Effect |
|---|---|---|
| `template` | Issues, pull requests | Picks a template by its file name, including the extension |
| `title` | Issues, pull requests | Sets the title |
| `body` | Markdown templates, pull requests | Sets the description text |
| `labels` | Issues, pull requests | Applies labels, separated by commas |
| `assignees` | Issues, pull requests | Assigns users, separated by commas |
| `milestone` | Issues, pull requests | Sets the milestone by name |
| `quick_pull=1` | Pull requests | Opens the pull request form directly, skipping the compare page |
Values must be URL-encoded. A space becomes + or %20, and a # becomes %23. A mistake here is the most common reason a prefilled value looks cut off.
Prefilling issue forms by field id
A YAML issue form has no free-text body. Instead, each field you gave an id can be filled by using that id as a parameter name. With the bug_report.yml form from earlier in this tutorial, this link sets three fields:
https://github.com/OWNER/REPO/issues/new?template=bug_report.yml&version=1.4.2&os=Linux&steps=Open+the+appHere version fills the input, steps fills the textarea, and os selects a dropdown option. For a dropdown, the value must match one of the option labels exactly, including capitalization. If it does not match, the field stays empty.
Elements of type markdown have no id and nothing to fill, so they cannot be prefilled.
Prefilling Markdown templates and pull requests
For a Markdown issue template or a pull request, use body. This link opens the hotfix pull request template and replaces the description with your own text:
https://github.com/OWNER/REPO/compare/main...my-branch?quick_pull=1&template=hotfix.md&title=Fix+login+timeout&body=Closes+%23123If you set both template and body, the body value wins. Leave body out when you want the template text to appear.
Pull request templates chosen with template= must live in the PULL_REQUEST_TEMPLATE directory covered in the previous chapter. A single pull_request_template.md file needs no template parameter.
Common errors
- Label or milestone is ignored. The label or milestone must already exist in the repository. The person opening the link also needs permission to set it, normally triage access or higher.
- Template does not load. The
templatevalue is a file name, not the template's display name. Usebug_report.yml, notBug report. - Field stays empty. The parameter name must match the field
idexactly. Check the spelling and that the field has anid. - Very long links break. Browsers and servers limit URL length. Prefill short values and let the user write the long parts.
Exercise
Write the URL path and query for a new issue in OWNER/REPO that uses feature_request.md, sets the title to "Add dark mode", and applies the label enhancement.
Show answer
https://github.com/OWNER/REPO/issues/new?template=feature_request.md&title=Add+dark+mode&labels=enhancement
Exercise
Your form bug_report.yml has a dropdown with id os and options Windows, macOS, and Linux. Which query parameter preselects macOS, and what happens if you write os=mac?
Show answer
Use os=macOS. The value must match an option label exactly, so os=mac selects nothing and the dropdown stays empty.