-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetRepos.js
55 lines (42 loc) · 1.57 KB
/
getRepos.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
// Simple app to clone all repositories belonging to a github user
const fetch = require('node-fetch');
const fs = require('fs');
const clone = require('git-clone');
const prompts = require('prompts');
const prompter = async () => {
const response = await prompts([
{
type: 'text',
name: 'username',
message: 'Please enter a Github username:',
},
{
type: 'text',
name: 'dir',
message: 'Please enter a local absolute path to clone the repositories into:'
}
]);
return response;
};
const fetcher = async (user) => {
return fetch(`https://api.github.com/users/${user}/repos`)
.then(data => data.json())
.catch(err => {console.log('There was an error ', err)});
};
const cloneURL_arr = (data) => data.map((val => val.clone_url));
const names_arr = (data) => data.map((val => val.name));
const main = async () => {
let userObj = await prompter();
let response = await fetcher(userObj.username);
// Loop through the response array and create an array of just the urls to clone each repository
const urls = cloneURL_arr(response);
// Loop through the response array and create an array of repository names to be used for creating directories
const names = names_arr(response);
// Loop through array of repository urls, mkdir for each associated reposotory name, then clone repo into new dir
urls.map((url, index) => {
let path = `${userObj.dir}/${names[index]}`
fs.mkdirSync(path);
clone(url, path);
});
};
main();