Skip to content

Instantly share code, notes, and snippets.

@lionello
Created July 30, 2025 22:48
Show Gist options
  • Select an option

  • Save lionello/474ba24ecd4a4b2d668b6f9910df2de6 to your computer and use it in GitHub Desktop.

Select an option

Save lionello/474ba24ecd4a4b2d668b6f9910df2de6 to your computer and use it in GitHub Desktop.
Convert GitHub Issue label to Issue type
import { components } from "@octokit/openapi-types";
import { Octokit } from "@octokit/rest";
const dryrun = false;
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
type Issue = components["schemas"]["issue"];
async function fetchAndMarkBugIssues(owner: string, repo: string) {
// Fetch all issues (paginated)
let issues: Issue[] = [];
let page = 1;
let per_page = 100;
let fetched: Issue[];
do {
const response = await octokit.issues.listForRepo({
owner,
repo,
state: "all",
per_page,
page,
});
fetched = response.data;
issues = issues.concat(fetched);
page++;
} while (fetched.length === per_page);
for (const issue of issues) {
const issueLabels = issue.labels.map((l) =>
typeof l === "string" ? l : l.name
);
let type;
if (issueLabels.includes("bug")) {
type = "Bug";
} else if (issueLabels.includes("enhancement")) {
type = "Feature";
} else {
continue; // Skip issues that are neither bugs nor features
}
if (!dryrun) {
await octokit.issues.update({
type,
owner,
repo,
issue_number: issue.number,
});
}
console.log(`Marked ${repo} issue #${issue.number} as "${type}"`);
}
}
fetchAndMarkBugIssues("ownerx", "repox").catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment