As an open source project maintainer, one of the things that I often need to do, to the surprise of no one, is triage issues. When doing so, I try to rely as much as possible on automation; however, it’s not always available out-of-the-box for some edge cases.
One such edge case is setting issue types in GitHub. If you are not familiar with it, I am not talking about issue labels, but specifically types.
Typically, I’d use the GitHub CLI for this kind of toil, but as it turns out there is no argument available that allows me to set the type. So, I had to look for creative workarounds.
Under the issue type hood
Issue types are entirely owner-managed. For example, in the PowerToys repo (where I maintain Awake), a maintainer can flag something as a Bug, Feature, or Task.
Now, if I’d ask anyone how they can set types for a given issue, they’d probably guess that they can use gh issues edit, but alas that’s not something I can do. Luckily, the GitHub CLI allows me to also talk directly to the GitHub GraphQL API, which offers way more capabilities than the command line tool.
So, I’ll start by querying the available issue types for the aforementioned PowerToys repository:
gh api graphql -f query='
{
repository(owner: "microsoft", name: "powertoys") {
issueTypes(first: 20) {
nodes {
id
name
description
}
}
}
}'
This will yield a JSON blob like this:
{
"data": {
"repository": {
"issueTypes": {
"nodes": [
{
"id": "IT_kwDOAF3p4s4ACCgE",
"name": "Task",
"description": "A specific piece of work"
},
{
"id": "IT_kwDOAF3p4s4ACCgH",
"name": "Bug",
"description": "An unexpected problem or behavior"
},
{
"id": "IT_kwDOAF3p4s4ACCgK",
"name": "Feature",
"description": "A request, idea, or new functionality"
}
]
}
}
}
}
Not bad. I now have the unique id associated with each issue type. But I don’t just need to get the issue types. I need to be able to set them. To do that, I’m once again going to lean on the GitHub GraphQL API, with the help of mutations. The GitHub GraphQL API uses global node IDs and not the issue numbers (what you see in the web UI) for mutations, meaning I need to retrieve the issue’s node ID first.
Here is the GraphQL query that I need to execute from the GitHub CLI:
gh api graphql -f query='
{
repository(owner: "microsoft", name: "powertoys") {
issue(number: 44644) {
id
title
issueType {
name
}
}
}
}'
If all goes well, this is what I’ll get:
{
"data": {
"repository": {
"issue": {
"id": "I_kwDOCv6UO87iZtnQ",
"title": "Bug report run logs",
"issueType": {
"name": "Bug"
}
}
}
}
}
The id value is all I need. Now, I can use the updateIssue mutation to set the type.
gh api graphql -f query='
mutation {
updateIssue(input: {
id: "I_kwDOCv6UO87iZtnQ",
issueTypeId: "IT_kwDOAF3p4s4ACCgH"
}) {
issue {
number
title
issueType {
name
}
}
}
}'
Notice the issueTypeId - this is where I use the relevant issue type ID from the very first step to set the type.
A successful type assignment operation will result in this JSON output in your terminal:
{
"data": {
"updateIssue": {
"issue": {
"number": 44644,
"title": "Bug report run logs",
"issueType": {
"name": "Bug"
}
}
}
}
}
To remove an issue type from an issue, pass null as the issueTypeId in the GraphQL query above.
Conclusion
It’s a bit more work than I’d like for something this basic, but wrapping these queries in a shell script or a custom CLI extension (that’s for another blog post) makes it easy to integrate into your triage workflow. Hopefully native gh issue edit support comes soon.






