Skip to content

Commit b29e1f4

Browse files
clayreimannAurelioDeRosa
authored andcommitted
Add release events API
Ref gh-162 Closes gh-297
1 parent 3dc854a commit b29e1f4

File tree

6 files changed

+89
-7
lines changed

6 files changed

+89
-7
lines changed

dist/github.bundle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.bundle.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.js

Lines changed: 28 additions & 0 deletions
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

test/test.repo.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
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+
var github, repo, user, imageB64, imageBlob, sha, releaseId;
610

711
if (typeof window === 'undefined') { // We're in NodeJS
812
var fs = require('fs');
@@ -33,6 +37,7 @@ if (typeof window === 'undefined') { // We're in NodeJS
3337
// jscs:disable
3438
imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC';
3539
imageBlob = new Blob();
40+
3641
// jscs:enable
3742
}
3843
}
@@ -207,7 +212,7 @@ describe('Github.Repository', function() {
207212
xhr.should.be.instanceof(XMLHttpRequest);
208213
statuses.length.should.equal(6);
209214
statuses.every(function(status) {
210-
return status.url === 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
215+
return status.url === STATUS_URL;
211216
}).should.equal(true);
212217

213218
done();
@@ -534,6 +539,7 @@ describe('Creating new Github.Repository', function() {
534539
}, function(err, res, xhr) {
535540
should.not.exist(err);
536541
xhr.should.be.instanceof(XMLHttpRequest);
542+
sha = res.commit.sha;
537543

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

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

0 commit comments

Comments
 (0)