@@ -22,7 +22,9 @@ githubClient.authenticate({
22
22
token : process . env . GITHUB_TOKEN
23
23
} )
24
24
25
- function pollThenComment ( owner , repoName , prId ) {
25
+ exports . pollThenStatus = pollThenStatus
26
+
27
+ function pollThenStatus ( owner , repoName , prId ) {
26
28
const prInfo = prInfoStr ( { owner, repoName, prId } )
27
29
28
30
// we have to figure out what type of Travis polling we should perform,
@@ -37,7 +39,7 @@ function pollThenComment (owner, repoName, prId) {
37
39
if ( hasAnyPrBuilds ) {
38
40
pollByPrThenComment ( owner , repoName , prId )
39
41
} else {
40
- pollByCommitThenComment ( owner , repoName , prId )
42
+ pollByCommitThenStatus ( owner , repoName , prId )
41
43
}
42
44
} )
43
45
}
@@ -92,7 +94,7 @@ function pollByPrThenComment (owner, repoName, prId, checkNumber) {
92
94
*
93
95
* This is the case for readable-stream.
94
96
*/
95
- function pollByCommitThenComment ( owner , repoName , prId ) {
97
+ function pollByCommitThenStatus ( owner , repoName , prId ) {
96
98
const prInfo = prInfoStr ( { owner, repoName, prId } )
97
99
98
100
githubClient . pullRequests . getCommits ( {
@@ -111,7 +113,7 @@ function pollByCommitThenComment (owner, repoName, prId) {
111
113
}
112
114
113
115
function pollTravisBuildBySha ( options , checkNumber ) {
114
- const createGhComment = createGhCommentFn ( options )
116
+ const createGhStatus = createGhStatusFn ( options )
115
117
const prInfo = prInfoStr ( options )
116
118
const shaToMatch = options . lastSha
117
119
@@ -138,11 +140,12 @@ function pollTravisBuildBySha (options, checkNumber) {
138
140
const lastState = lastBuildForCommit . state
139
141
140
142
if ( lastState === 'passed' ) {
141
- return createGhComment ( `[Travis build passed](https://travis-ci.org/ ${ options . owner } / ${ options . repoName } /builds/ ${ lastBuildForCommit . id } ) :+1:` )
143
+ return createGhStatus ( 'success' , lastBuildForCommit . id , 'all tests passed' )
142
144
} else if ( lastState === 'failed' ) {
143
- return createGhComment ( `[Travis build failed](https://travis-ci.org/ ${ options . owner } / ${ options . repoName } /builds/ ${ lastBuildForCommit . id } ) :-1:` )
145
+ return createGhStatus ( 'failure' , lastBuildForCommit . id , 'build failure' )
144
146
} else if ( ~ [ 'created' , 'started' ] . indexOf ( lastState ) ) {
145
147
console . log ( `* ${ prInfo } "${ lastState } " build found, will do check #${ checkNumber + 1 } in 30 seconds` )
148
+ createGhStatus ( 'pending' , lastBuildForCommit . id , 'build in progress' )
146
149
} else {
147
150
return console . log ( `* ${ prInfo } Unknown build state: "${ lastState } ", stopping polling` )
148
151
}
@@ -157,7 +160,7 @@ function pollTravisBuildBySha (options, checkNumber) {
157
160
function createGhCommentFn ( options ) {
158
161
const prInfo = prInfoStr ( options )
159
162
160
- return ( message , cb ) => {
163
+ return ( message ) => {
161
164
githubClient . issues . createComment ( {
162
165
user : options . owner ,
163
166
repo : options . repoName ,
@@ -172,8 +175,27 @@ function createGhCommentFn (options) {
172
175
}
173
176
}
174
177
178
+ function createGhStatusFn ( options ) {
179
+ const prInfo = prInfoStr ( options )
180
+
181
+ return ( state , travisId , message ) => {
182
+ githubClient . statuses . create ( {
183
+ user : options . owner ,
184
+ repo : options . repoName ,
185
+ sha : options . lastSha ,
186
+ target_url : `https://travis-ci.org/${ options . owner } /${ options . repoName } /builds/${ travisId } ` ,
187
+ context : 'Travis CI via nodejs-github-bot' ,
188
+ state : state ,
189
+ description : message
190
+ } , ( err , res ) => {
191
+ if ( err ) {
192
+ return console . error ( `! ${ prInfo } Error while updating GitHub PR status` , err . stack )
193
+ }
194
+ console . log ( `* ${ prInfo } Github PR status updated` )
195
+ } )
196
+ }
197
+ }
198
+
175
199
function prInfoStr ( options ) {
176
200
return `${ options . owner } /${ options . repoName } /#${ options . prId } `
177
201
}
178
-
179
- exports . pollThenComment = pollThenComment
0 commit comments