@@ -34,19 +34,27 @@ function cmdGet (msg, done) {
34
34
35
35
context . log . debug ( `Processing module: ${ moduleName } ` )
36
36
cache . load$ ( moduleName , ( err , github ) => {
37
- if ( err ) return done ( err )
37
+ if ( err ) {
38
+ context . log . debug ( `Cannot load from cache module ${ moduleName } , try now to get it remotely` )
39
+ }
38
40
39
41
if ( github && ! msg . update ) {
40
- return done ( null , github . data$ ( github ) )
42
+ return done ( null , { ok : true , data : github . data$ ( github ) } )
41
43
}
42
44
43
45
Request . get ( { url : registry , gzip : true } , ( err , res , body ) => {
44
- if ( err ) return done ( err )
46
+ if ( err ) {
47
+ return done ( err )
48
+ }
45
49
46
50
var data = null
47
51
48
- try { data = JSON . parse ( body ) }
49
- catch ( e ) { return done ( e ) }
52
+ try {
53
+ data = JSON . parse ( body )
54
+ }
55
+ catch ( e ) {
56
+ return done ( e )
57
+ }
50
58
51
59
var distTags = data [ 'dist-tags' ] || { }
52
60
var latest = ( ( data . versions || { } ) [ distTags . latest ] ) || { }
@@ -66,17 +74,17 @@ function cmdGet (msg, done) {
66
74
}
67
75
68
76
if ( ! params . user || ! params . repo ) {
69
- return done ( new Error ( `module ${ moduleName } not found on github` ) )
77
+ return done ( null , { ok : false , err : new Error ( `module ${ moduleName } not found on github` ) } )
70
78
}
71
79
72
80
queryGithub ( params , done )
73
81
}
74
82
else {
75
- return done ( new Error ( `invalid github url: ${ url } , for module: ${ moduleName } ` ) )
83
+ return done ( null , { ok : false , err : new Error ( `invalid github url: ${ url } , for module: ${ moduleName } ` ) } )
76
84
}
77
85
}
78
86
else {
79
- return done ( new Error ( `module ${ moduleName } not found on github` ) )
87
+ return done ( null , { ok : false , err : new Error ( `module ${ moduleName } not found on github` ) } )
80
88
}
81
89
} )
82
90
} )
@@ -104,7 +112,8 @@ function cmdGet (msg, done) {
104
112
github . repos . getReadme ( { user : params . user , repo : params . repo } , ( err , readme ) => {
105
113
if ( err ) {
106
114
context . log . debug ( `Read readme for ${ moduleName } get error: ${ err } ` )
107
- return cb ( err )
115
+ // don't report error, as we want to search for other information, even if Readme is not loaded
116
+ return cb ( null , false )
108
117
}
109
118
110
119
if ( ! readme || ! readme . content ) {
@@ -117,7 +126,8 @@ function cmdGet (msg, done) {
117
126
} , ( err , response ) => {
118
127
if ( err && ! response ) {
119
128
context . log . debug ( `Render readme for ${ moduleName } error: ${ err } ` )
120
- return cb ( err )
129
+ // don't report error, as we want to search for other information, even if Readme is not loaded
130
+ return cb ( null , false )
121
131
} // API fails expecting a JSON object
122
132
123
133
cb ( null , response . data )
@@ -131,22 +141,23 @@ function cmdGet (msg, done) {
131
141
context . log . debug ( `Read Github pull requests for ${ moduleName } get error: ${ err } ` )
132
142
}
133
143
134
- cb ( err , data )
144
+ // don't report error, as we might have useful data
145
+ return cb ( )
135
146
} )
136
147
}
137
148
} , ( err , results ) => {
138
149
if ( err ) {
139
150
context . log . debug ( `Read pull requests for ${ moduleName } got error: ${ err } ` )
140
- return complete ( err )
151
+ return done ( null , { ok : false , err : err } )
141
152
}
142
153
var data = {
143
154
name : params . repo || '' ,
144
155
user : params . user || '' ,
145
156
repo : params . repo || '' ,
146
- stars : results . getRepository . stargazers_count || 0 ,
147
- watches : results . getRepository . subscribers_count || 0 ,
148
- forks : results . getRepository . forks_count || 0 ,
149
- last : results . getRepository . pushed_at || '' ,
157
+ stars : results . getRepository ? results . getRepository . stargazers_count || 0 : 0 ,
158
+ watches : results . getRepository ? results . getRepository . subscribers_count || 0 : 0 ,
159
+ forks : results . getRepository ? results . getRepository . forks_count || 0 : 0 ,
160
+ last : results . getRepository ? results . getRepository . pushed_at || '' : '' ,
150
161
urlRepo : 'https://github.com/' + params . user + '/' + params . repo ,
151
162
urlClone : 'git+https://github.com/' + params . user + '/' + params . repo + '.git' ,
152
163
urlSsh :
'[email protected] :' + params . user + '/' + params . repo + '.git' ,
@@ -174,7 +185,7 @@ function cmdGet (msg, done) {
174
185
context . log . debug ( `Save Github data for ${ moduleName } got error: ${ err } ` )
175
186
return done ( err )
176
187
}
177
- else done ( null , data ? data . data$ ( data ) : data )
188
+ else done ( null , { ok : true , data : data ? data . data$ ( data ) : data } )
178
189
}
179
190
} )
180
191
}
@@ -184,11 +195,16 @@ function aliasGet (msg, done) {
184
195
var seneca = this
185
196
var payload = { name : msg . name }
186
197
187
- seneca . act ( 'role:github,cmd:get' , payload , ( err , data ) => {
188
- if ( err ) return done ( err )
198
+ seneca . act ( 'role:github,cmd:get' , payload , ( err , res ) => {
199
+ if ( err ) {
200
+ return done ( null , { ok : false , err : err } )
201
+ }
202
+
203
+ if ( res && res . ok ) {
204
+ payload . data = res . data
205
+ seneca . act ( 'role:info,res:part,part:github' , payload )
206
+ }
189
207
190
- payload . data = data
191
- seneca . act ( 'role:info,res:part,part:github' , payload )
192
208
done ( null , { ok : true } )
193
209
} )
194
210
}
0 commit comments