-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove_remote_repositories.mjs
48 lines (42 loc) · 1.22 KB
/
remove_remote_repositories.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Octokit } from '@octokit/rest';
const reposPrefix = 'test_';
const token = process.env.GITDDB_PERSONAL_ACCESS_TOKEN;
const octokit = new Octokit({
auth: token,
});
const len = 0;
const promises = [];
const removeRemoteRepositories = async () => {
// eslint-disable-next-line no-await-in-loop
const reposArray = await octokit.paginate(
octokit.repos.listForAuthenticatedUser,
{ per_page: 100 },
response =>
response.data.filter(repos => {
if (repos) {
const urlArray = repos.full_name.split('/');
const repo = urlArray[1];
return repo.startsWith(reposPrefix);
}
return false;
})
);
// console.log(` - Got ${reposArray.length} repositories`);
reposArray.forEach(repos => {
const urlArray = repos.full_name.split('/');
const owner = urlArray[0];
const repo = urlArray[1];
promises.push(
octokit.repos.delete({ owner, repo }).catch(err => {
if (err.status !== 404) {
console.debug(err);
}
})
);
});
console.log(` - Start to remove repositories..`);
// eslint-disable-next-line no-await-in-loop
await Promise.all(promises);
console.log(` - Done.`);
};
removeRemoteRepositories();