Sub topic 5
Issue forms: the YAML structure
Issue forms replace a free-text Markdown template with a structured web form. This chapter covers the file that defines one: its top-level keys, the shape of the body list, and the mistakes that stop a form from loading. It assumes you can read basic YAML (mappings, lists, indentation) and that you know where template files live, as covered earlier.
One form is one YAML file
Each form is a single file in .github/ISSUE_TEMPLATE/ with a .yml or .yaml extension. As with other templates, GitHub reads it from the default branch. A change on a feature branch does not show up in the chooser until it is merged.
The file is a mapping with a few top-level keys.
| Key | Required | Purpose |
|---|---|---|
| `name` | Yes | Template name shown in the chooser. Must be unique among templates. |
| `description` | Yes | One-line explanation shown under the name. |
| `body` | Yes | List of form elements, in display order. |
| `title` | No | Default text for the issue title. |
| `labels` | No | Labels added to new issues. A label that does not exist in the repository is not applied. |
| `assignees` | No | Users assigned to new issues. |
A minimal form
This form has the three required keys and one input field.
name: Question
description: Ask a usage question
title: "[Question]: "
labels: ["question"]
body:
- type: input
id: topic
attributes:
label: Topic
description: What are you trying to do?
validations:
required: trueThe shape of a body element
Every item in body is a mapping with the same layout. Only the contents of attributes change from one element type to the next.
typeselects the element:markdown,input,textarea,dropdown, orcheckboxes.idis an optional identifier. It must be unique within the form and may contain only letters, numbers,-, and_. Later chapters use it to prefill fields from a URL.attributesholds the settings, such aslabel,description, andplaceholder.validationsholds rules such asrequired: true. It is not available onmarkdownelements.
How the form turns into an issue
When someone submits the form, GitHub builds the issue body in Markdown. Each submitted element becomes a section headed by its label, followed by the user's answer. Elements of type markdown are display-only. They show text in the form but do not appear in the issue. Because of this, a form needs at least one element that is not markdown.
If a user leaves an optional field empty, GitHub fills the section with a "No response" placeholder. This keeps the issue layout consistent for people and scripts that read it.
Common errors
A form that is invalid does not fall back to a partial version. It is usually left out of the chooser or fails to load. Check these first:
- Tabs for indentation. YAML allows only spaces.
- A missing required key.
name,description, andbodymust all be present. - Duplicate
idvalues or duplicatelabelvalues in the same form. - A
bodymade up only ofmarkdownelements. - Unquoted special characters. A title such as
[Bug]:starts with[, so quote it, as the example above does. Quote values containing:followed by a space as well. - The wrong location. A file in
.github/instead of.github/ISSUE_TEMPLATE/is ignored.
Exercise
A teammate adds .github/ISSUE_TEMPLATE/idea.yml to a feature branch. The file has name and body keys, and body contains two markdown elements. The form does not appear in the chooser after the branch is merged. Name two problems in the file.
Show answer
The file has no description key, which is required. Its body has only markdown elements, and a form needs at least one input, textarea, dropdown, or checkboxes element. Either problem can keep the form from loading. (Before the merge, the branch alone would also have hidden it, because templates are read from the default branch.)