1
0
mirror of https://github.com/spacebarchat/spacebarchat.git synced 2024-09-19 17:01:47 +02:00

rename issues script

This commit is contained in:
Flam3rboy 2021-08-10 03:34:50 +02:00
parent 2a198aabbf
commit 215f5d5196
4 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"token": ""
}

30
scripts/github/package-lock.json generated Normal file
View File

@ -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=="
}
}
}

View File

@ -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"
}
}

View File

@ -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);