Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
npm-debug.log
gith_working.js
node_modules
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gith

Version: 1.0.4
Version: 1.0.5

gith[ooks] - a simple node server that responds to github post-receive events with meaningful data

Expand Down
32 changes: 27 additions & 5 deletions lib/gith.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,31 @@ Gith.prototype.simplifyPayload = function( payload ) {
}
}

// if branch wasn't found, use base_ref if available
if ( !branch && payload.base_ref ) {
branch = payload.base_ref.replace( rRef, '$2' );
if ( !branch ) {
// if branch wasn't found, use base_ref if available
if (payload.base_ref) {
branch = payload.base_ref.replace(rRef, '$2');
} else if (payload.pull_request && payload.pull_request.head.ref) {
branch = payload.pull_request.head.ref;
}
}

// find repo
var repo = null;
if (payload.repository) {
if (payload.repository.full_name) {
repo = payload.repository.full_name;
} else {
repo = payload.repository.owner.name + '/' + payload.repository.name;
}
}

// find sha
var sha = null;
if (payload.pull_request) {
sha = payload.pull_request.head.sha;
} else {
sha = payload.after;
}

var simpler = {
Expand All @@ -183,8 +205,8 @@ Gith.prototype.simplifyPayload = function( payload ) {
},
tag: tag,
branch: branch,
repo: payload.repository ? (payload.repository.owner.name + '/' + payload.repository.name) : null,
sha: payload.after,
repo: repo,
sha: sha,
time: payload.repository ? payload.repository.pushed_at : null,
urls: {
head: payload.head_commit ? payload.head_commit.url : '',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gith",
"description": "gith[ooks] - a simple node server that responds to github post-receive events with meaningful data",
"version": "1.0.4",
"version": "1.0.5",
"homepage": "https://github.com/danheberden/gith",
"author": {
"name": "Dan Heberden",
Expand Down
23 changes: 21 additions & 2 deletions test/gith_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,33 @@ exports['other hook types'] = {
done();
},
'pull-request.json': function( test ) {
test.expect(1);
test.expect(4);
var json = require( './payloads/pull-request.json' );
var gith = githFactory.create();
var g = gith();

g.on( 'all', function( payload ) {
// No particular expectation except it must not crash and present original payload
// it must not crash and present original payload with key fields mapped
test.equal(payload.original, json);
test.equal(payload.repo, "naholyr/gith");
test.equal(payload.branch, "test3");
test.equal(payload.sha, "abd633ff2744039e4bda1c697cea3d03152df3fc");
test.done();
});
gith.payload( json );
},
'pull-request-new.json': function( test ) {
test.expect(4);
var json = require( './payloads/pull-request-new.json' );
var gith = githFactory.create();
var g = gith();

g.on( 'all', function( payload ) {
// it must not crash and present original payload with key fields mapped
test.equal(payload.original, json);
test.equal(payload.repo, "someOwner/someRepo");
test.equal(payload.branch, "someBranch");
test.equal(payload.sha, "5b57e09043a285291ab7fae1fff9d499dbffe40c");
test.done();
});
gith.payload( json );
Expand Down
Loading