1
1
var path = require ( 'path' ) ;
2
2
var url = require ( 'url' ) ;
3
3
4
- var GitHubApi = require ( 'github' ) ;
5
-
6
4
var h = require ( '../helper' ) ;
7
5
var log = require ( '../log' ) ;
8
6
var Plugin = require ( '../plugin' ) ;
9
7
10
8
// [prerequisite]
11
9
//
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)
13
11
//
14
12
// [config]
15
13
//
@@ -19,12 +17,9 @@ var Plugin = require('../plugin');
19
17
// "token": "<token created above>"
20
18
// }
21
19
// }
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' ] ) ;
28
23
29
24
var ctx = { } ;
30
25
@@ -38,32 +33,31 @@ plugin.submitProblem = function(problem, cb) {
38
33
ctx . repo = parts . shift ( ) ;
39
34
ctx . path = parts . join ( '/' ) ;
40
35
36
+ var GitHubApi = require ( 'github' ) ;
37
+ var github = new GitHubApi ( { host : 'api.github.com' } ) ;
41
38
github . authenticate ( { type : 'token' , token : this . config . token } ) ;
39
+
42
40
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 ;
44
43
45
44
log . debug ( 'running github.getContent: ' + filename ) ;
46
45
github . repos . getContent ( ctx , function ( e , res ) {
47
46
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 ) ) ;
50
48
}
51
49
52
50
ctx . message = 'update ' + filename ;
53
51
ctx . content = new Buffer ( h . getFileData ( problem . file ) ) . toString ( 'base64' ) ;
54
52
55
53
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 ) ) ;
60
56
61
57
log . debug ( res . meta . status ) ;
62
58
log . debug ( 'updated current file version = ' + res . data . content . sha ) ;
63
59
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 ) ) ;
67
61
} ;
68
62
69
63
if ( e ) {
0 commit comments