-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
58 lines (52 loc) · 1.15 KB
/
index.js
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
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
/*
* Author: Tej
* GitHub: tpkahlon
* name: unstar
* version: 0.0.1
*/
"use-strict";
const inquirer = require("inquirer");
const { Octokit } = require("@octokit/core");
async function logic(pat) {
try {
const octokit = new Octokit({ auth: pat });
const { data } = await octokit.request(`GET /user/starred`);
if (Array.isArray(data) && data.length !== 0) {
data.forEach(async (item) => {
await octokit.request("DELETE /user/starred/{owner}/{repo}", {
owner: item.owner.login,
repo: item.name,
});
});
return true;
}
return false;
} catch (err) {
console.log(err);
return null;
}
}
async function unstarPlease(pat) {
let ran = await logic(pat);
while (ran) {
if (!ran) return;
ran = await logic(pat);
}
}
inquirer
.prompt([
{
type: "input",
name: "pat",
message: "Please enter your Personal access token:",
default: "",
},
])
.then(function ({ pat }) {
unstarPlease(pat);
})
.catch(function (error) {
if (error.isTtyError) console.error(error.isTtyError, error);
console.error(error);
});