Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aca0185

Browse files
committed
Update github plugin.
* add dependencies. * tuning output. Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent e744eb4 commit aca0185

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

github.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
var path = require('path');
22
var url = require('url');
33

4-
var GitHubApi = require('github');
5-
64
var h = require('../helper');
75
var log = require('../log');
86
var Plugin = require('../plugin');
97

108
// [prerequisite]
119
//
12-
// 1. create a new access token on your github repo setting. (TBD)
10+
// - create a new access token on your github repo setting. (TBD)
1311
//
1412
// [config]
1513
//
@@ -19,12 +17,9 @@ var Plugin = require('../plugin');
1917
// "token": "<token created above>"
2018
// }
2119
// }
22-
var plugin = new Plugin(100, 'github', '2017.08.09',
23-
'Plugin to commit accepted code to your own github repo.');
24-
25-
var github = new GitHubApi({
26-
host: 'api.github.com'
27-
});
20+
var plugin = new Plugin(100, 'github', '2017.08.10',
21+
'Plugin to commit accepted code to your own github repo.',
22+
['github']);
2823

2924
var ctx = {};
3025

@@ -38,32 +33,31 @@ plugin.submitProblem = function(problem, cb) {
3833
ctx.repo = parts.shift();
3934
ctx.path = parts.join('/');
4035

36+
var GitHubApi = require('github');
37+
var github = new GitHubApi({host: 'api.github.com'});
4138
github.authenticate({type: 'token', token: this.config.token});
39+
4240
plugin.next.submitProblem(problem, function(_e, results) {
43-
if (_e || !results[0].ok) return cb(_e, results);
41+
cb(_e, results);
42+
if (_e || !results[0].ok) return;
4443

4544
log.debug('running github.getContent: ' + filename);
4645
github.repos.getContent(ctx, function(e, res) {
4746
if (e && e.code !== 404) {
48-
log.error('[github] failed: ' + e.message);
49-
return cb(_e, results);
47+
return log.info(' ' + h.prettyText(' ' + e.message, false));
5048
}
5149

5250
ctx.message = 'update ' + filename;
5351
ctx.content = new Buffer(h.getFileData(problem.file)).toString('base64');
5452

5553
var onFileDone = function(e, res) {
56-
if (e) {
57-
log.error('[github] failed: ' + e.message);
58-
return cb(_e, results);
59-
}
54+
if (e)
55+
return log.info(' ' + h.prettyText(' ' + e.message, false));
6056

6157
log.debug(res.meta.status);
6258
log.debug('updated current file version = ' + res.data.content.sha);
6359
log.debug('updated current commit = ' + res.data.commit.sha);
64-
65-
log.info('[github] successfully committed to ' + plugin.config.repo);
66-
return cb(_e, results);
60+
log.info(' ' + h.prettyText(' Committed to ' + plugin.config.repo, true));
6761
};
6862

6963
if (e) {

0 commit comments

Comments
 (0)