Skip to content

Commit 4fb7f3d

Browse files
committed
Bug fix for GitHub-X-Event rejection
1 parent c161f87 commit 4fb7f3d

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

3-
## [Latest](https://github.com/cortex-lab/matlab-ci/commits/master) [2.2.0]
3+
## [Latest](https://github.com/cortex-lab/matlab-ci/commits/master) [2.2.1]
4+
5+
## Modified
6+
7+
- fix error where github even incorrectly rejected
8+
- fix bug incorrect log name when endpoint called with branch name
9+
10+
## [2.2.0]
411

512
## Added
613
- nyc dependency for manual coverage of matlab-ci

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MATLAB-ci
22
[![Build Status](https://travis-ci.com/cortex-lab/matlab-ci.svg?branch=master)](https://travis-ci.com/cortex-lab/matlab-ci)
3-
[![Coverage](https://img.shields.io/badge/coverage-81.07-green)](https://img.shields.io/badge/coverage-72.35-yellowgreen)
3+
[![Coverage](https://img.shields.io/badge/coverage-81.58-green)](https://img.shields.io/badge/coverage-72.35-yellowgreen)
44

55
A small set of modules written in Node.js for running automated tests of MATLAB code in response to GitHub events. Also submits code coverage to the Coveralls API.
66

main.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ handler.on('*', evt => eventCallback(evt));
3232
queue.on('error', _ => {});
3333

3434

35-
// Log handler errors
36-
handler.on('error', function (err) {
37-
console.error('Error:', err.message);
38-
})
39-
4035
// Log any unhandled errors
4136
process.on('unhandledRejection', (reason, p) => {
4237
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);

serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ srv.post('/github', async (req, res, next) => {
105105
console.log('Post received')
106106
let id = req.header('x-github-hook-installation-target-id');
107107
if (id != process.env.GITHUB_APP_IDENTIFIER) { next(); return; } // Not for us; move on
108-
if (req.header('X-GitHub-Event') in supportedEvents) {
108+
if (supportedEvents.includes(req.header('X-GitHub-Event'))) {
109109
await setAccessToken();
110110
handler(req, res, () => res.end('ok'));
111111
} else {

test/serve.test.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ describe("Github event handler callback", () => {
253253
},
254254
});
255255
await setAccessToken();
256-
scope.done();
256+
nock.cleanAll()
257257
}
258258

259-
before(function (done) {
260-
setToken().then(() => done());
259+
before(async function () {
260+
await setToken();
261261
scope = nock('https://api.github.com', {
262262
reqheaders: {
263263
accept: 'application/vnd.github.machine-man-preview+json',
@@ -839,6 +839,23 @@ describe('srv github/', () => {
839839
});
840840
});
841841

842+
it('expect token set', (done) => {
843+
// Although the blob signature won't match, we can at least test that setAccessToken was called
844+
request(srv)
845+
.post(`/github`) // trailing slash essential
846+
.set({
847+
'X-GitHub-Event': 'push',
848+
'x-github-hook-installation-target-id': process.env.GITHUB_APP_IDENTIFIER,
849+
'X-Hub-Signature': {'sha': SHA},
850+
'X-GitHub-Delivery': '72d3162e-cc78-11e3-81ab-4c9367dc0958'
851+
})
852+
.end(function (err) {
853+
expect(scope.pendingMocks().length).lt(2); // setAccessToken was called
854+
err ? done(err) : done();
855+
});
856+
});
857+
858+
842859
after(function () {
843860
clock.restore();
844861
});

0 commit comments

Comments
 (0)