-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (50 loc) · 1.49 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
'use strict';
const GitHubApi = require("github");
const fs = require("fs");
const nconf = require("nconf");
const HexoHelper = require("./lib/hexoHelper");
const Util = require("./lib/utils");
nconf.env().argv({
u: {
alias: 'username',
describe: 'GitHub username',
demand: true,
type: 'string'
},
p: {
alias: 'password',
describe: 'GitHub password',
demand: true,
type: 'string'
},
o: {
alias: 'org',
describe: 'GitHub Organisation',
demand: true,
type: 'string'
}
});
const USERNAME = nconf.get('username');
const PASSWORD = nconf.get('password');
const ORG = nconf.get('org');
const github = new Util(USERNAME, PASSWORD, ORG);
const gitHubConnection = github.getConnection();
const r = gitHubConnection.repos.getForOrg({org: ORG})
.then(repositories => {
const reposNames = repositories.map(repository => repository.name);
createPostForEachRepository(reposNames);
});
function createPostForEachRepository(names) {
const name = names.pop();
console.log("create post for: ", name);
return github.getServiceInfo(name)
.then(r => fs.writeFileSync(`./source/_posts/${name}.md`, HexoHelper.createPost(r), 'utf8'))
.then(() => {
if (names.length === 0) {
console.log("finished");
} else {
createPostForEachRepository(names);
}
})
.catch(err => console.error(err));
}