Skip to content

Commit 43520d1

Browse files
committed
Revert "Revert "Merge pull request #16 from Fishrock123/no-comment""
This reverts commit 9d9069a.
1 parent 566ce4c commit 43520d1

File tree

1 file changed

+2
-87
lines changed

1 file changed

+2
-87
lines changed

lib/pollTravis.js

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -22,77 +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-
const hasAnyPrBuilds = res.builds.some((build) => build.pull_request)
38-
39-
if (hasAnyPrBuilds) {
40-
pollByPrThenComment(owner, repoName, prId)
41-
} else {
42-
pollByCommitThenStatus(owner, repoName, prId)
43-
}
44-
})
45-
}
25+
exports.pollThenStatus = pollByCommitThenStatus
4626

4727
/**
48-
* When Travis CI picks up our PR's, we can poll and match builds
49-
* by their related PR #id.
50-
*
51-
* That's the case for nodejs.org.
52-
*/
53-
function pollByPrThenComment (owner, repoName, prId, checkNumber) {
54-
checkNumber = checkNumber || 1
55-
56-
const prInfo = prInfoStr({ owner, repoName, prId })
57-
const createGhComment = createGhCommentFn({ owner, repoName, prId })
58-
59-
if (checkNumber > 100) {
60-
console.warn(`* ${prInfo} Was not able to find matching build for PR, stopping poll now :(`)
61-
return
62-
}
63-
64-
travisClient.repos(owner, repoName).builds.get((err, res) => {
65-
if (err) {
66-
return console.error(`! ${prInfo} Error while retrieving builds`, err.stack)
67-
}
68-
69-
const lastBuildForPr = res.builds.find((build) => build.pull_request_number === prId)
70-
71-
if (lastBuildForPr) {
72-
const lastState = lastBuildForPr.state
73-
74-
if (lastState === 'passed') {
75-
return createGhComment(`[Travis build passed](https://travis-ci.org/${owner}/${repoName}/builds/${lastBuildForPr.id}) :+1:`)
76-
} else if (lastState === 'failed') {
77-
return createGhComment(`[Travis build failed](https://travis-ci.org/${owner}/${repoName}/builds/${lastBuildForPr.id}) :-1:`)
78-
} else if (~['created', 'started'].indexOf(lastState)) {
79-
console.log(`* ${prInfo} "${lastState}" build found, will do check #${checkNumber + 1} in 30 seconds`)
80-
} else {
81-
return console.log(`* ${prInfo} Unknown build state: "${lastState}", stopping polling`)
82-
}
83-
} else {
84-
console.warn(`! ${prInfo} Was not able to find matching build, will do check #${checkNumber + 1} in 30 seconds`)
85-
}
86-
87-
setTimeout(pollByPrThenComment, 30 * 1000, owner, repoName, prId, checkNumber + 1)
88-
})
89-
}
90-
91-
/**
92-
* When Travis CI *doesn't* pick up our PR's, we have to poll and match builds
93-
* by the last commit SHA of the related PR.
94-
*
95-
* This is the case for readable-stream.
28+
* Poll and match builds by the last commit SHA of the related PR.
9629
*/
9730
function pollByCommitThenStatus (owner, repoName, prId) {
9831
const prInfo = prInfoStr({ owner, repoName, prId })
@@ -157,24 +90,6 @@ function pollTravisBuildBySha (options, checkNumber) {
15790
})
15891
}
15992

160-
function createGhCommentFn (options) {
161-
const prInfo = prInfoStr(options)
162-
163-
return (message) => {
164-
githubClient.issues.createComment({
165-
user: options.owner,
166-
repo: options.repoName,
167-
number: options.prId,
168-
body: message
169-
}, (err, res) => {
170-
if (err) {
171-
return console.error(`! ${prInfo} Error while creating GitHub comment`, err.stack)
172-
}
173-
console.log(`* ${prInfo} Github comment created`)
174-
})
175-
}
176-
}
177-
17893
function createGhStatusFn (options) {
17994
const prInfo = prInfoStr(options)
18095

0 commit comments

Comments
 (0)