Sub topic 9
Structured input with issue forms
This chapter assumes you know how to write an issue template as a Markdown file and how labels work. You should also be comfortable reading YAML, the indentation-based format used for configuration. Issue forms replace free-form Markdown templates with a web form that has typed fields and validation.
Why forms instead of Markdown templates
A Markdown template pre-fills a text box. The reporter can delete any part of it, so a bug report may still arrive with no steps to reproduce. An issue form is a YAML file that GitHub renders as a set of fields. You can mark fields as required, and the form will not submit until the reporter fills them in.
| Feature | Markdown template | Issue form |
|---|---|---|
| File type | `.md` | `.yml` |
| Input | One text box, pre-filled | Separate typed fields |
| Required fields | No | Yes |
| Reporter can remove structure | Yes | No |
Both kinds live in .github/ISSUE_TEMPLATE/ on the default branch. Forms appear in the "New issue" chooser only after the file is merged there.
A first form
This file is saved as .github/ISSUE_TEMPLATE/bug_report.yml.
name: Bug report
description: Report a problem
title: "[Bug]: "
labels: ["bug"]
body:
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Describe the problem and what you expected instead.
validations:
required: true
- type: input
id: version
attributes:
label: Version
validations:
required: falseThe top-level keys describe the form as a whole:
nameis the title shown in the template chooser. It is required.descriptionis the line of text shown under the name. It is required.titlepre-fills the issue title.labelsare applied to every issue created from the form.bodyis the list of fields.
Field types
Each item in body has a type. The common types are:
markdownshows static text to the reporter. It is not part of the submitted issue.inputis a single-line text field.textareais a multi-line field. It can render its content as code if you setrender.dropdownoffers a list ofoptions.checkboxesshows one or more boxes, often used for a confirmation such as "I searched existing issues".
Every field except markdown takes an attributes block with a label. Most also take an optional id, which must be unique within the form. Fields that collect input accept a validations block with required: true or required: false.
Adding a dropdown and a checklist
The next fragment extends the body list from the first form. It shows a dropdown and a checkbox group.
- type: dropdown
id: severity
attributes:
label: Severity
options:
- Low
- Medium
- High
validations:
required: true
- type: checkboxes
id: checks
attributes:
label: Before you submit
options:
- label: I searched existing issues
required: truePlace these items after the version field, at the same indentation as the other items under body. The required setting for checkboxes goes on each option, not in a validations block.
How the submission appears
GitHub turns each field into a Markdown section. The field's label becomes a heading and the answer appears below it. The result is a consistent issue body that is easy to scan and easy to search.
Common errors
- The form does not appear. The file must be on the default branch, in
.github/ISSUE_TEMPLATE/, and have a.ymlor.yamlextension. - The form shows a syntax error. YAML is sensitive to indentation, so use spaces and not tabs. A missing
name,description, orbodyalso invalidates the file. - Duplicate
idvalues. Eachidmust be unique within the form. - A label is not applied. The label named in
labelsmust exist in the repository. Create it first if it does not.
Exercise
Exercise
You want every bug report to include a severity chosen from Low, Medium, or High, and you want the form to refuse submission without one. Which field type and setting do you use?
Show answer
Use a dropdown field with options listing Low, Medium, and High, and add validations with required: true.