diff --git a/scripts/github/config.example.json b/scripts/github/config.example.json new file mode 100644 index 0000000..aa1b9c9 --- /dev/null +++ b/scripts/github/config.example.json @@ -0,0 +1,3 @@ +{ + "token": "" +} diff --git a/scripts/github/package-lock.json b/scripts/github/package-lock.json new file mode 100644 index 0000000..168b7b7 --- /dev/null +++ b/scripts/github/package-lock.json @@ -0,0 +1,30 @@ +{ + "name": "github", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "node-fetch": "^2.6.1" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + } + }, + "dependencies": { + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + } + } +} diff --git a/scripts/github/package.json b/scripts/github/package.json new file mode 100644 index 0000000..b83e007 --- /dev/null +++ b/scripts/github/package.json @@ -0,0 +1,15 @@ +{ + "name": "github", + "version": "1.0.0", + "description": "", + "main": "rename_issues.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "node-fetch": "^2.6.1" + } +} diff --git a/scripts/github/rename_issues.js b/scripts/github/rename_issues.js new file mode 100644 index 0000000..bf1d5e4 --- /dev/null +++ b/scripts/github/rename_issues.js @@ -0,0 +1,57 @@ +const { token } = require("./config.json"); +const fetch = require("node-fetch"); +const base = "https://api.github.com"; +const organization = "fosscord"; + +const request = async (path, opts = {}) => + await fetch(`${base}${path}`, { + ...opts, + headers: { + ...opts.headers, + Authorization: `token ${token}`, + }, + }).then((response) => response.json()); + +async function getRepos() { + return (await request(`/orgs/${organization}/repos`)).map((repo) => repo.name); +} + +async function main() { + const repos = await getRepos(); + for (const repo of repos) { + var page = 1; + do { + var issues = await request(`/repos/${organization}/${repo}/issues?state=all&per_page=100&page=${page}`); + for (const issue of issues) { + const replacer = [ + "[Feature]", + "[BUG]", + "[Bug]", + "[Security]", + "[Route]", + "[Voice]", + "[Page]", + "[Media]", + "[Gateway]", + "[Fix]", + "[Plugin]", + ]; + const newTitle = replacer.reduce((acc, curr) => acc.replace(curr, ""), issue.title).trim(); + + if (newTitle !== issue.title) { + console.log(`old: ${issue.title}, new: ${newTitle}`, issue.number); + // continue; + await request(`/repos/${organization}/${repo}/issues/${issue.number}`, { + method: "PATCH", + body: JSON.stringify({ title: newTitle }), + }); + } + } + page++; + } while (issues.length); + } +} + +main() + .then(() => console.log("done")) + .catch(console.error);