Sub topic 8
Standardizing reports with issue templates
This chapter assumes you can create issues, apply labels, and use a terminal and Git. It also assumes you know how to commit a file to a repository's default branch.
Why templates help
Reporters often leave out the details a maintainer needs: the steps to reproduce, the version, or the expected result. A maintainer then has to ask for them in comments, and each round trip delays the fix. An issue template is a file in your repository that pre-fills the title, labels, and body of a new issue. The reporter sees a prompt for each missing detail and replaces it with an answer.
Templates build on two earlier ideas. Good issues state the problem and context clearly, and labels let you sort reports. A template applies both rules to every new issue.
Where template files live
GitHub reads templates from the .github/ISSUE_TEMPLATE/ directory on the default branch. Each Markdown file in that directory becomes one choice on the New issue page. A template that exists only on a feature branch does not appear.
Write a bug report template
Save the following as .github/ISSUE_TEMPLATE/bug_report.md:
---
name: Bug report
about: Report something that is not working
title: "[Bug]: "
labels: bug
assignees: ''
---
**What happened?**
**Steps to reproduce**
1.
2.
**Expected behavior**The block between the --- lines is called front matter. It configures how the template appears and what it sets:
| Field | Purpose |
|---|---|
| `name` | The template's name on the chooser page |
| `about` | A one-line description shown beneath the name |
| `title` | Text placed in the title field. The reporter completes it. |
| `labels` | Labels applied when the issue is created |
| `assignees` | Users assigned automatically. An empty value assigns no one. |
Everything below the front matter becomes the starting body. Keep the prompts short. A long list of questions discourages people from answering any of them.
Add more than one template
Add a second file for a different kind of request, such as feature_request.md, with its own name, labels: enhancement, and prompts such as the problem to solve and a proposed approach. Separate templates let you attach different labels and ask different questions for each kind of work.
Common errors
- The template does not show up. Check that the file is in
.github/ISSUE_TEMPLATE/(the name is case-sensitive) and that it was merged into the default branch. - The chooser shows no title or description. The front matter is missing
nameorabout, or its---delimiters are malformed. - The label is not applied. The label does not exist, or its spelling differs from the repository's label.
- Prompts get deleted and ignored. Markdown templates are only suggestions, and reporters can erase any part of the text. If you need required fields, use issue forms, which the next chapter covers.
Try it
- Create
.github/ISSUE_TEMPLATE/bug_report.mdwith the content above. - Commit it to the default branch and push.
- Open the repository's Issues tab and select New issue.
- Confirm that "Bug report" appears and that choosing it fills in the title, the
buglabel, and the body prompts.
Exercise
A teammate added a template on a branch called add-templates and says it does not appear on the New issue page. What is the most likely cause, and how do you fix it?
Show answer
GitHub only reads templates from the default branch. Merge the branch into the default branch (for example through a pull request), and the template then appears on the New issue page.
Exercise
Your bug template has labels: bug, but new issues from it have no label. Name two things to check.
Show answer
Check that a label named exactly bug exists in the repository, and check that the front matter is valid (correct --- delimiters and labels: spelling). A missing label or malformed front matter prevents the label from being applied.