This repository was archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappsody_stars_watchers_forks.js
More file actions
79 lines (69 loc) · 1.73 KB
/
appsody_stars_watchers_forks.js
File metadata and controls
79 lines (69 loc) · 1.73 KB
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
75
76
77
78
79
const { graphql } = require('@octokit/graphql')
const tools = require('../data_pulling_utils/data_pulling_tools');
const args = process.argv.slice(2)
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
const queryTotals = async (repo, org) => {
const graphqlWithAuth = graphql.defaults({
headers: {
authorization: `token ${process.env.GITHUB_API_KEY}`
}
})
let data
try {
data = await graphqlWithAuth(`
{
repository(name: "${repo}", owner: "${org}") {
forks {
totalCount
}
stargazers {
totalCount
}
watchers {
totalCount
}
}
}`)
} catch (err) {
if (err.name === 'HttpError') {
setTimeout(() => {
queryTotals(repo, org)
}, 10000)
} else {
throw (err)
}
} finally {
const single = {
"repo": repo,
"stars": data.repository.stargazers.totalCount,
"watchers": data.repository.watchers.totalCount,
"forks": data.repository.forks.totalCount,
}
return single;
}
}
var queries = [
['appsody', 'stacks'],
['appsody', 'appsody']
];
results = [];
const callQueries = async () => {
const start = async () => {
await asyncForEach(queries, async (q) => {
let res = await (queryTotals(q[1], q[0]));
results.push(res)
});
tools.createLogFile(`stars_watchers_forks.json`, results, function(err) {
console.log(err);
});
if(args[0] != undefined) {
tools.createComparisonFile("stars_watchers_forks", results, "repo", args[0]);
}
}
start();
}
callQueries();