Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions owner/rename-labels.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Octokit } from '@octokit/rest';

const octokit = new Octokit({
auth: 'token', // should have repo and repo:public_repo scope
});

// Set the organization name, label name, color, and description
const label = {
name: 'doc',
new_name: 'docs',
color: 'ff0000',
description: 'Documentations issues',
}
const orgName = 'expressjs';

export async function createLabelInRepo(label, owner, repo) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export async function updateLabelInRepo(label, owner, repo) {

try {
await octokit.issues.updateLabel({
owner,
repo,
...label
});
console.log(`Label '${label.name}' was updated to '${label.new_name}' to ${repo}`);
} catch (error) {
console.log(error)
if (error.status === 422) {
console.log(`Label '${label.new_name}' already exists in ${repo}`);
} else {
console.error(
`Failed to create label in ${repo}: ${error.message}`
);
}
}
}

async function createLabelInAllRepos() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async function updateLabelInAllRepos() {

try {
const repos = await octokit.paginate(octokit.repos.listForOrg, {
org: orgName,
});

for (const repo of repos) {
await createLabelInRepo(label, orgName, repo.name);
}

console.log('Label creation completed.');
} catch (error) {
console.error(
`Error fetching repositories or creating labels: ${error.message}`
);
process.exit(1);
}
}

createLabelInAllRepos();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateLabelInAllRepos();