Skip to content

Commit 19d08d3

Browse files
committed
📦NEW: get stars
1 parent f81daef commit 19d08d3

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

utils/getStargazer.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Author: Muhammad Saad
4+
* GitHub: msaaddev
5+
* Twitter: https://twitter.com/msaaddev
6+
*/
7+
8+
const io = require("console-read-write");
9+
const { cyan } = require("chalk");
10+
const box = require("./box");
11+
const axios = require("axios");
12+
const headers = require("./auth");
13+
14+
module.exports = async () => {
15+
console.log("------------------------------------------");
16+
// getting data from terminal
17+
io.write(cyan("> Enter GitHub Username"));
18+
const username = await io.read();
19+
console.log("");
20+
io.write(cyan("> Enter GitHub Repo Name"));
21+
const repo = await io.read();
22+
23+
24+
await axios
25+
.get(
26+
`https://api.github.com/repos/${username}/${repo}?access_token=${headers.Authorization}`,
27+
{
28+
headers: headers,
29+
}
30+
)
31+
.then((res) => {
32+
const name = "⭐️ Stars";
33+
const data = res.data.stargazers_count;
34+
box(name, data);
35+
})
36+
.catch((err) => {
37+
const name = "⚠️ WARNING";
38+
const msg = "Cannot Access Stars!!";
39+
box(name, msg);
40+
});
41+
};

0 commit comments

Comments
 (0)