22
33const debug = require ( 'debug' ) ( 'display_travis_status' )
44const pollTravis = require ( '../lib/pollTravis' )
5- const enabledRepos = [
6- 'citgm' , 'readable-stream' , 'nodejs.org' , 'docker-node' ,
7- 'llnode' , 'nan' , 'node-core-utils' , 'core-validate-commit'
8- ]
5+
6+ // Default is 20 retries, 30 seconds per retry, which is reasonable for
7+ // smaller projects that finish testing within 10 minutes.
8+ const DEFAULT_POLL_RETRY = process . env . TRAVIS_POLL_RETRY || 20
9+ const DEFAULT_POLL_INTERVAL = process . env . TRAVIS_POLL_INTERVAL || 30
10+
11+ // For projects that take longer to build e.g. projects that actually use
12+ // Travis to build, increase the interval so there will be fewer useless
13+ // polls
14+ const enabledRepos = {
15+ 'citgm' : { retry : 40 } ,
16+ 'readable-stream' : { retry : 60 , interval : 60 } ,
17+ 'nodejs.org' : { } ,
18+ 'docker-node' : { retry : 70 , interval : 120 } ,
19+ 'llnode' : { retry : 60 , interval : 60 } ,
20+ 'nan' : { retry : 60 , interval : 60 } ,
21+ 'node-core-utils' : { } ,
22+ 'core-validate-commit' : { }
23+ }
924
1025module . exports = function ( app ) {
1126 app . on ( 'pull_request.opened' , handlePrUpdate )
1227 // Pull Request updates
1328 app . on ( 'pull_request.synchronize' , handlePrUpdate )
1429
1530 function handlePrUpdate ( event , owner , repo ) {
16- if ( ! ~ enabledRepos . indexOf ( repo ) ) return
31+ const config = enabledRepos [ repo ]
32+ if ( ! config ) return
1733
1834 const pr = event . number
19- const options = { owner, repo, pr, logger : event . logger }
35+ const retry = config . retry || DEFAULT_POLL_RETRY
36+ const interval = config . interval || DEFAULT_POLL_INTERVAL
37+ const options = { owner, repo, pr, retry, interval, logger : event . logger }
2038
2139 debug ( `/${ owner } /${ repo } /pull/${ pr } opened` )
2240 pollTravis . pollThenStatus ( options )
@@ -27,10 +45,15 @@ module.exports = function (app) {
2745 const owner = req . params . owner
2846 const repo = req . params . repo
2947 const pr = parseInt ( req . params . id , 10 )
30- const options = { owner, repo, pr, logger : req . log }
31-
32- if ( ~ enabledRepos . indexOf ( repo ) ) {
48+ const config = enabledRepos [ repo ]
49+ if ( config ) {
50+ const retry = config . retry || DEFAULT_POLL_RETRY
51+ const interval = config . interval || DEFAULT_POLL_INTERVAL
52+ const options = { owner, repo, pr, retry, interval, logger : req . log }
53+ res . writeHead ( 201 )
3354 pollTravis . pollThenStatus ( options )
55+ } else {
56+ res . writeHead ( 404 , 'Repo not enabled' )
3457 }
3558 res . end ( )
3659 } )
0 commit comments