-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathutilities.js
74 lines (69 loc) · 2.42 KB
/
utilities.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const glob = require('glob');
const { GetInfoForRepo } = require('./github');
module.exports = {
concatJsonFiles: (dir) => {
return new Promise((resolve, reject) => {
const fileData = [];
const globPath = `./${dir}/**/*.json`;
glob(globPath, (err, files) => {
if (err) {
reject(err);
} else {
if (!files) {
reject(`No files found in ${dir}`);
} else {
files.forEach((file) => {
const data = require(`${file}`);
fileData.push(data);
});
resolve(fileData);
}
}
});
});
},
resolveRepos: async (configs) => {
console.log(`Resolving ${configs.length} repos`);
const repoData = [];
for (const config of configs) {
let data;
try {
data = await GetInfoForRepo(config.owner, config.repo);
} catch (err) {
if (err.headers && err.headers['x-ratelimit-remaining'] === '0') {
console.log('Rate Limit Exceeded...now exiting');
process.exit();
} else {
console.log('Unknown error', err);
}
} finally {
if (data && data.message && data.message === 'Moved Permanently') {
console.log('Repo has moved permanently', { config, data });
} else if (data) {
const remote = {
name: data.name,
updated_at: new Date(data.pushed_at),
star_count: data.stargazers_count,
description: data.description,
owner: data.owner.login,
license: data.license,
url: data.html_url
};
repoData.push({
config,
remote
});
} else {
console.log('No repo found for', { config });
}
}
}
return repoData;
}
}
const arrayIncludes = (array, item) => {
if (!array) {
return false;
}
return array.indexOf(item) > -1;
};