Skip to content

Commit 7658784

Browse files
committed
skip pushed without commits
1 parent bf1ef15 commit 7658784

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

lib/routes/actions/github.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,22 @@ app.post('/actions/github/',
6060
mw.res.status(202),
6161
mw.res.send('Deleted the branch; no work to be done.')),
6262
parseGitHubPushData,
63-
instances.findInstancesLinkedToBranch('githubPushInfo.repo', 'githubPushInfo.branch'),
64-
// check if there are instances that follow specific branch
65-
mw.req('instances.length').validate(validations.equals(0))
63+
mw.req('githubPushInfo.commitLog.length').validate(validations.equals(0))
6664
.then(
67-
// no instances found. This can be push to the new branch
68-
newBranch()
69-
)
65+
mw.res.status(202),
66+
mw.res.send('No commits pushed; no work to be done.'))
7067
.else(
71-
// instances following particular branch were found. Redeploy them with the new code
72-
followBranch('instances')
73-
)
68+
instances.findInstancesLinkedToBranch('githubPushInfo.repo', 'githubPushInfo.branch'),
69+
// check if there are instances that follow specific branch
70+
mw.req('instances.length').validate(validations.equals(0))
71+
.then(
72+
// no instances found. This can be push to the new branch
73+
newBranch()
74+
)
75+
.else(
76+
// instances following particular branch were found. Redeploy them with the new code
77+
followBranch('instances')
78+
))
7479
),
7580
mw.res.status(501),
7681
mw.res.send('No action set up for that payload.'));
@@ -88,7 +93,7 @@ function parseGitHubPushData (req, res, next) {
8893
branch : req.body.ref.replace('refs/heads/', ''),
8994
commit : req.body.head_commit.id,
9095
headCommit: req.body.head_commit,
91-
commitLog : req.body.commits,
96+
commitLog : req.body.commits || [],
9297
user: req.body.sender
9398
};
9499
next();

test/actions-github.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
var Lab = require('lab');
23
var describe = Lab.experiment;
34
var it = Lab.test;
@@ -76,10 +77,10 @@ describe('Github - /actions/github', function () {
7677
process.env.ENABLE_BUILDS_ON_GIT_PUSH = ctx.originalBuildsOnPushSetting;
7778
done();
7879
});
79-
it('should just say hi if hooks are disabled', function (done) {
80+
it('should send response immediately if hooks are disabled', function (done) {
8081
var options = hooks(ctx.contextVersion.json()).push;
8182
options.json.ref = 'refs/heads/someotherbranch';
82-
// require('./fixtures/mocks/github/users-username')(101, 'bkendall');
83+
require('./fixtures/mocks/github/users-username')(101, 'bkendall');
8384
request.post(options, function (err, res) {
8485
if (err) {
8586
done(err);
@@ -93,6 +94,55 @@ describe('Github - /actions/github', function () {
9394
});
9495
});
9596

97+
describe('ignore hooks without commits data', function () {
98+
var ctx = {};
99+
beforeEach(function (done) {
100+
process.env.ENABLE_BUILDS_ON_GIT_PUSH = 'true';
101+
multi.createInstance(function (err, instance, build, user, modelsArr) {
102+
ctx.contextVersion = modelsArr[0];
103+
ctx.context = modelsArr[1];
104+
ctx.build = build;
105+
ctx.user = user;
106+
done(err);
107+
});
108+
});
109+
110+
it('should send response immediately there are no commits data ([]) in the payload ', function (done) {
111+
var options = hooks(ctx.contextVersion.json()).push;
112+
options.json.ref = 'refs/heads/someotherbranch';
113+
options.json.commits = [];
114+
require('./fixtures/mocks/github/users-username')(101, 'bkendall');
115+
request.post(options, function (err, res) {
116+
if (err) {
117+
done(err);
118+
}
119+
else {
120+
expect(res.statusCode).to.equal(202);
121+
expect(res.body).to.equal('No commits pushed; no work to be done.');
122+
done();
123+
}
124+
});
125+
});
126+
127+
it('should send response immediately there are no commits data (null) in the payload ', function (done) {
128+
var options = hooks(ctx.contextVersion.json()).push;
129+
options.json.ref = 'refs/heads/someotherbranch';
130+
options.json.commits = null;
131+
require('./fixtures/mocks/github/users-username')(101, 'bkendall');
132+
request.post(options, function (err, res) {
133+
if (err) {
134+
done(err);
135+
}
136+
else {
137+
expect(res.statusCode).to.equal(202);
138+
expect(res.body).to.equal('No commits pushed; no work to be done.');
139+
done();
140+
}
141+
});
142+
});
143+
});
144+
145+
96146
// describe('push', function () {
97147
// var ctx = {};
98148
// beforeEach(function (done) {

0 commit comments

Comments
 (0)