This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·75 lines (64 loc) · 1.76 KB
/
index.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
75
#!/usr/bin/env node
(async () => {
'use strict';
const GitHubApi = require('github');
// Configuration
const origamiCoreTeamId = 1959619;
// Check that a GitHub token is available
const githubAuthToken = process.env.GITHUB_AUTH_TOKEN;
if (!githubAuthToken) {
process.exitCode = 1;
return console.error('Please provide a GITHUB_AUTH_TOKEN environment variable');
}
// Create a GitHub API client
const github = new GitHubApi();
github.authenticate({
type: 'oauth',
token: githubAuthToken
});
// Get the Origami team repos and topics
let origamiTeamRepos;
try {
origamiTeamRepos = await getOrigamiTeamRepos();
await Promise.all(origamiTeamRepos.map(async repo => {
const response = await github.repos.getTopics({
owner: repo.owner.login,
repo: repo.name,
per_page: 100 // TODO only gets the first page at the moment
});
repo.topics = response.data.names;
}));
} catch (error) {
process.exitCode = 1;
return console.error(error);
}
// Output
const repoJson = JSON.stringify(origamiTeamRepos.map(simplifyRepoObject), null, '\t');
console.log(repoJson);
// Function to fetch all of the repositories owned by the Origami team
async function getOrigamiTeamRepos(page = 1, repos = []) {
const response = await github.orgs.getTeamRepos({
id: origamiCoreTeamId,
page,
per_page: 100
});
repos = repos.concat(response.data);
if (github.hasNextPage(response)) {
return getOrigamiTeamRepos(page + 1, repos);
}
return repos;
}
// Simplify a repo object returned by the GitHub API
function simplifyRepoObject(repo) {
return {
name: repo.name,
admin: repo.permissions.admin,
topics: repo.topics,
urls: {
web: repo.html_url,
cloneGit: repo.git_url,
cloneHttps: repo.clone_url
}
};
}
})();