@@ -99,15 +99,15 @@ module.exports = app => {
9999
100100 routes . get ( '/check/:owner/:repo' , ( req , res ) => {
101101 app . log . info ( `[${ req . params . owner } /${ req . params . repo } ] Checking ${ app . CONFIG_FILENAME } ` )
102- getJSON ( `https://api.github.com/repos/${ req . params . owner } /${ req . params . repo } /contents/.github/${ app . CONFIG_FILENAME } ` )
102+ getJSON ( `https://api.github.com/repos/${ req . params . owner } /${ req . params . repo } /contents/.github/${ app . CONFIG_FILENAME } ?client_id= ${ process . env . CLIENT_ID || '' } &client_secret= ${ process . env . CLIENT_SECRET || '' } ` )
103103 . then ( json => Buffer . from ( json . content , 'base64' ) . toString ( ) )
104104 . then ( yml => yaml . safeLoad ( yml ) )
105105 . then ( ( config ) => {
106106 const { error, value } = schema . validate ( config )
107107 if ( error ) throw error
108108 console . log ( value )
109109 const reqs = value . rules . map ( r => new Promise ( ( resolve , reject ) => {
110- getJSON ( `https://api.github.com/repos/${ req . params . owner } /${ req . params . repo } /compare/${ r . base } ...${ r . upstream } ` )
110+ getJSON ( `https://api.github.com/repos/${ req . params . owner } /${ req . params . repo } /compare/${ r . base } ...${ r . upstream } ?client_id= ${ process . env . CLIENT_ID || '' } &client_secret= ${ process . env . CLIENT_SECRET || '' } ` )
111111 . then ( githubRes => resolve ( ) )
112112 . catch ( e => reject ( e ) )
113113 } ) )
@@ -116,6 +116,13 @@ module.exports = app => {
116116 . then ( ( ) => res . end ( JSON . stringify ( value , null , 2 ) ) )
117117 . catch ( e => res . status ( 400 ) . end ( `Cannot compare ${ e . message } ` ) )
118118 } )
119- . catch ( e => res . status ( 400 ) . end ( `.github/${ app . CONFIG_FILENAME } file was either not found or failed validation` ) )
119+ . catch ( e => {
120+ console . log ( e . message )
121+ if ( e . message . indexOf ( 'API rate limit exceeded' ) > - 1 ) {
122+ res . status ( 400 ) . end ( `Github API rate limit exceeded` )
123+ } else {
124+ res . status ( 400 ) . end ( `.github/${ app . CONFIG_FILENAME } file was either not found or failed validation` )
125+ }
126+ } )
120127 } )
121128}
0 commit comments