@@ -22,71 +22,10 @@ githubClient.authenticate({
2222 token : process . env . GITHUB_TOKEN
2323} )
2424
25- exports . pollThenStatus = pollThenStatus
26-
27- function pollThenStatus ( owner , repoName , prId ) {
28- const prInfo = prInfoStr ( { owner, repoName, prId } )
29-
30- // we have to figure out what type of Travis polling we should perform,
31- // either by PR #id (as for nodejs.org) or commit sha (for readable-stream)
32- travisClient . repos ( owner , repoName ) . builds . get ( ( err , res ) => {
33- if ( err ) {
34- return console . error ( `! ${ prInfo } Error while retrieving initial builds` , err . stack )
35- }
36-
37- pollByCommitThenStatus ( owner , repoName , prId )
38- } )
39- }
40-
41- /**
42- * When Travis CI picks up our PR's, we can poll and match builds
43- * by their related PR #id.
44- *
45- * That's the case for nodejs.org.
46- */
47- function pollByPrThenComment ( owner , repoName , prId , checkNumber ) {
48- checkNumber = checkNumber || 1
49-
50- const prInfo = prInfoStr ( { owner, repoName, prId } )
51- const createGhComment = createGhCommentFn ( { owner, repoName, prId } )
52-
53- if ( checkNumber > 100 ) {
54- console . warn ( `* ${ prInfo } Was not able to find matching build for PR, stopping poll now :(` )
55- return
56- }
57-
58- travisClient . repos ( owner , repoName ) . builds . get ( ( err , res ) => {
59- if ( err ) {
60- return console . error ( `! ${ prInfo } Error while retrieving builds` , err . stack )
61- }
62-
63- const lastBuildForPr = res . builds . find ( ( build ) => build . pull_request_number === prId )
64-
65- if ( lastBuildForPr ) {
66- const lastState = lastBuildForPr . state
67-
68- if ( lastState === 'passed' ) {
69- return createGhComment ( `[Travis build passed](https://travis-ci.org/${ owner } /${ repoName } /builds/${ lastBuildForPr . id } ) :+1:` )
70- } else if ( lastState === 'failed' ) {
71- return createGhComment ( `[Travis build failed](https://travis-ci.org/${ owner } /${ repoName } /builds/${ lastBuildForPr . id } ) :-1:` )
72- } else if ( ~ [ 'created' , 'started' ] . indexOf ( lastState ) ) {
73- console . log ( `* ${ prInfo } "${ lastState } " build found, will do check #${ checkNumber + 1 } in 30 seconds` )
74- } else {
75- return console . log ( `* ${ prInfo } Unknown build state: "${ lastState } ", stopping polling` )
76- }
77- } else {
78- console . warn ( `! ${ prInfo } Was not able to find matching build, will do check #${ checkNumber + 1 } in 30 seconds` )
79- }
80-
81- setTimeout ( pollByPrThenComment , 30 * 1000 , owner , repoName , prId , checkNumber + 1 )
82- } )
83- }
25+ exports . pollThenStatus = pollByCommitThenStatus
8426
8527/**
86- * When Travis CI *doesn't* pick up our PR's, we have to poll and match builds
87- * by the last commit SHA of the related PR.
88- *
89- * This is the case for readable-stream.
28+ * Poll and match builds by the last commit SHA of the related PR.
9029 */
9130function pollByCommitThenStatus ( owner , repoName , prId ) {
9231 const prInfo = prInfoStr ( { owner, repoName, prId } )
@@ -151,24 +90,6 @@ function pollTravisBuildBySha (options, checkNumber) {
15190 } )
15291}
15392
154- function createGhCommentFn ( options ) {
155- const prInfo = prInfoStr ( options )
156-
157- return ( message ) => {
158- githubClient . issues . createComment ( {
159- user : options . owner ,
160- repo : options . repoName ,
161- number : options . prId ,
162- body : message
163- } , ( err , res ) => {
164- if ( err ) {
165- return console . error ( `! ${ prInfo } Error while creating GitHub comment` , err . stack )
166- }
167- console . log ( `* ${ prInfo } Github comment created` )
168- } )
169- }
170- }
171-
17293function createGhStatusFn ( options ) {
17394 const prInfo = prInfoStr ( options )
17495
0 commit comments