Skip to content

Commit e1cb6ef

Browse files
committed
📦 NEW: get all repos
1 parent 709ca3e commit e1cb6ef

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

utils/getRepo.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
*
3+
* Author: Muhammad Saad
4+
* GitHub: msaaddev
5+
* Twitter: https://twitter.com/msaaddev
6+
*/
7+
8+
const pwd = process.cwd();
9+
const io = require("console-read-write");
10+
const { cyan } = require("chalk");
11+
const axios = require("axios");
12+
const box = require("./box.js");
13+
const table = require("./repoOutput.js");
14+
const clear = require("clear");
15+
const exit = require("./exit");
16+
17+
let headers;
18+
try {
19+
headers = require(`${pwd}/auth.js`);
20+
} catch (error) {}
21+
22+
module.exports = async () => {
23+
io.write("------------------------------------------");
24+
// getting data from terminal
25+
26+
io.write(cyan("> Enter Username"));
27+
const username = await io.read();
28+
29+
const options = {
30+
method: "GET",
31+
headers: headers,
32+
url: `https://api.github.com/users/${username}/repos?page=1&per_page=1000`,
33+
};
34+
35+
await axios(options)
36+
.then((res) => {
37+
// console.log(res.data[1].description);
38+
clear();
39+
for (let i = 0; i < res.data.length; i++) {
40+
table(
41+
i + 1,
42+
res.data[i].name,
43+
res.data[i].fork,
44+
res.data[i].html_url,
45+
res.data[i].description
46+
);
47+
}
48+
49+
io.write("");
50+
io.write(cyan(`Total Repos: ${res.data.length}`));
51+
exit();
52+
})
53+
.catch((err) => {
54+
console.log(err);
55+
56+
const name = "⚠️ WARNING";
57+
const msg = "Couldn't Get Repos!!";
58+
box(name, msg);
59+
});
60+
};

utils/options.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const stars = require("./getStargazer.js");
55
const exit = require("./exit.js");
66
const issue = require("./createIssue.js");
77
const repo = require("./createRepo.js");
8+
const listrepo = require("./getRepo");
89

910
module.exports = async () => {
1011
io.write(
1112
chalk.green("\nEnter any option: \n") +
1213
chalk.yellow(
13-
"1. Create a GitHub Repo \n2. Open an Issue in any GitHub Repo \n3. Get Email of any GitHub User\n4. Get Stargazers of any GitHub Repo\n5. Exit\n\n"
14+
"1. Create a GitHub Repo \n2. List Public Repos of any GitHub User\n3. Open an Issue in any GitHub Repo \n4. Get Email of any GitHub User\n5. Get Stargazers of any GitHub Repo\n6. Exit\n\n"
1415
)
1516
);
1617
io.write(chalk.green("> Enter the option number: "));
@@ -21,15 +22,18 @@ module.exports = async () => {
2122
repo();
2223
break;
2324
case "2":
24-
issue();
25+
listrepo();
2526
break;
2627
case "3":
27-
email();
28+
issue();
2829
break;
2930
case "4":
30-
stars();
31+
email();
3132
break;
3233
case "5":
34+
stars();
35+
break;
36+
case "6":
3337
exit();
3438
default:
3539
break;

utils/repoOutput.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { yellow, green, red } = require("chalk");
2+
const io = require("console-read-write");
3+
4+
module.exports = (no, name, original, url, description) => {
5+
io.write(
6+
` ${yellow("NO: ")}${green(`${no}`)}\n ${yellow("NAME: ")}${green(
7+
`${name}`
8+
)}\n ${yellow("FORKED: ")}${green(`${original}`)}\n ${yellow("URL: ")}${green(
9+
`${url}`
10+
)}\n ${yellow("DESCRIPTION: ")}${green(`${description}`)}`
11+
);
12+
io.write(
13+
red(
14+
"-------------------------------------------------------------------------------------------------------------"
15+
)
16+
);
17+
};

0 commit comments

Comments
 (0)