Skip to content

Commit 5d48ceb

Browse files
author
Ilya Radchenko
committed
Add [skip ci] feature for commits
1 parent 05b0dbb commit 5d48ceb

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lib/webhooks.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,23 @@ function makeJob(project, config) {
4040
}
4141

4242
function startFromCommit(project, payload, send) {
43-
var config = pushJob(payload)
44-
, branch = project.branch(config.branch)
45-
, job
43+
var config = pushJob(payload);
44+
var lastCommit = payload.commits[payload.commits.length - 1];
45+
46+
if (lastCommit.message.indexOf('[skip ci]') > -1) {
47+
return { skipCi: true };
48+
}
49+
50+
var branch = project.branch(config.branch);
51+
var job;
4652

4753
if (branch) {
48-
job = makeJob(project, config)
49-
if (job) return send(job)
54+
job = makeJob(project, config);
55+
56+
if (job) return send(job);
5057
}
51-
return false
58+
59+
return false;
5260
}
5361

5462
// post a comment to the pull request asking for confirmation by a
@@ -212,20 +220,30 @@ function receiveWebhook(emitter, req, res) {
212220

213221
res.send(204)
214222
// a new pull request was created
215-
var getConfig
223+
var getConfig;
224+
216225
if (payload.pull_request) {
217226
if (config.pull_requests === 'none') {
218227
return console.log('Got pull request, but testing pull requests is disabled')
219228
}
220229
return startFromPullRequest(account, config, req.project, payload, sendJob)
221230
}
231+
222232
// issue comment
223233
if (payload.comment) {
224234
if (config.pull_requests !== 'whitelist') return
225235
return startFromComment(account, config, req.project, payload, sendJob)
226236
}
237+
227238
// otherwise, this is a commit
228-
startFromCommit(req.project, payload, sendJob)
239+
var result = startFromCommit(req.project, payload, sendJob);
240+
241+
if (result && result.skipCi) {
242+
console.log('Skipping commit due to [skip ci] tag');
243+
}
244+
else {
245+
console.log('webhook received, but no branched matched or branch is not active');
246+
}
229247

230248
function sendJob(job) {
231249
emitter.emit('job.prepare', job)

0 commit comments

Comments
 (0)