Skip to content

Commit cba2baa

Browse files
clayreimannClay Reimann
authored andcommitted
Add release events api
1 parent 9335b8c commit cba2baa

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

src/github.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,34 @@
927927
this.unstar = function(owner, repository, cb) {
928928
_request('DELETE', '/user/starred/' + owner + '/' + repository, null, cb);
929929
};
930+
931+
// Create a new release
932+
// --------
933+
934+
this.createRelease = function(options, cb) {
935+
_request('POST', repoPath + '/releases', options, cb);
936+
};
937+
938+
// Edit a release
939+
// --------
940+
941+
this.editRelease = function(id, options, cb) {
942+
_request('PATCH', repoPath + '/releases/' + id, options, cb);
943+
};
944+
945+
// Get a single release
946+
// --------
947+
948+
this.getRelease = function(id, cb) {
949+
_request('GET', repoPath + '/releases/' + id, null, cb);
950+
};
951+
952+
// Remove a release
953+
// --------
954+
955+
this.deleteRelease = function(id, cb) {
956+
_request('DELETE', repoPath + '/releases/' + id, null, cb);
957+
};
930958
};
931959

932960
// Gists API
@@ -1115,4 +1143,4 @@
11151143
};
11161144

11171145
return Github;
1118-
}));
1146+
}));

test/test.repo.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
var Github = require('../src/github.js');
44
var testUser = require('./user.json');
5-
var github, repo, user, imageB64, imageBlob;
5+
var RELEASE_TAG = 'foo';
6+
var RELEASE_NAME = 'My awesome release';
7+
var RELEASE_BODY = 'Foo bar bazzy baz';
8+
var STATUS_URL = 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
9+
10+
var github, repo, user, imageB64, imageBlob, sha, releaseId;
611

712
if (typeof window === 'undefined') { // We're in NodeJS
813
var fs = require('fs');
@@ -33,6 +38,7 @@ if (typeof window === 'undefined') { // We're in NodeJS
3338
// jscs:disable
3439
imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC';
3540
imageBlob = new Blob();
41+
3642
// jscs:enable
3743
}
3844
}
@@ -207,7 +213,7 @@ describe('Github.Repository', function() {
207213
xhr.should.be.instanceof(XMLHttpRequest);
208214
statuses.length.should.equal(6);
209215
statuses.every(function(status) {
210-
return status.url === 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
216+
return status.url === STATUS_URL;
211217
}).should.equal(true);
212218

213219
done();
@@ -534,6 +540,7 @@ describe('Creating new Github.Repository', function() {
534540
}, function(err, res, xhr) {
535541
should.not.exist(err);
536542
xhr.should.be.instanceof(XMLHttpRequest);
543+
sha = res.commit.sha;
537544

538545
done();
539546
});
@@ -578,6 +585,54 @@ describe('Creating new Github.Repository', function() {
578585
});
579586
});
580587
});
588+
589+
it('should create a release', function(done) {
590+
var options = {
591+
tag_name: RELEASE_TAG,
592+
target_commitish: sha
593+
};
594+
595+
repo.createRelease(options, function(err, res, xhr) {
596+
should.not.exist(err);
597+
xhr.should.be.instanceof(XMLHttpRequest);
598+
599+
releaseId = res.id;
600+
done();
601+
});
602+
});
603+
604+
it('should edit a release', function(done) {
605+
var options = {
606+
name: RELEASE_NAME,
607+
body: RELEASE_BODY
608+
};
609+
610+
repo.editRelease(releaseId, options, function(err, res, xhr) {
611+
should.not.exist(err);
612+
res.name.should.equal(RELEASE_NAME);
613+
res.body.should.equal(RELEASE_BODY);
614+
xhr.should.be.instanceof(XMLHttpRequest);
615+
616+
done();
617+
});
618+
});
619+
620+
it('should read a release', function(done) {
621+
repo.getRelease(releaseId, function(err, res, xhr) {
622+
should.not.exist(err);
623+
res.name.should.equal(RELEASE_NAME);
624+
xhr.should.be.instanceof(XMLHttpRequest);
625+
done();
626+
});
627+
});
628+
629+
it('should delete a release', function(done) {
630+
repo.deleteRelease(releaseId, function(err, res, xhr) {
631+
should.not.exist(err);
632+
xhr.should.be.instanceof(XMLHttpRequest);
633+
done();
634+
});
635+
});
581636
});
582637

583638
describe('deleting a Github.Repository', function() {

0 commit comments

Comments
 (0)