From a169a55663e3b39b72aba50365103306b2dfc74c Mon Sep 17 00:00:00 2001 From: Clay Reimann Date: Mon, 29 Feb 2016 08:33:48 -0600 Subject: [PATCH] Add release events api --- src/github.js | 28 ++++++++++++++++++++++ test/test.repo.js | 59 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/github.js b/src/github.js index cb6546a5..dd4da081 100644 --- a/src/github.js +++ b/src/github.js @@ -927,6 +927,34 @@ this.unstar = function(owner, repository, cb) { _request('DELETE', '/user/starred/' + owner + '/' + repository, null, cb); }; + + // Create a new release + // -------- + + this.createRelease = function(options, cb) { + _request('POST', repoPath + '/releases', options, cb); + }; + + // Edit a release + // -------- + + this.editRelease = function(id, options, cb) { + _request('PATCH', repoPath + '/releases/' + id, options, cb); + }; + + // Get a single release + // -------- + + this.getRelease = function(id, cb) { + _request('GET', repoPath + '/releases/' + id, null, cb); + }; + + // Remove a release + // -------- + + this.deleteRelease = function(id, cb) { + _request('DELETE', repoPath + '/releases/' + id, null, cb); + }; }; // Gists API diff --git a/test/test.repo.js b/test/test.repo.js index bb405cdc..fe9e73d5 100644 --- a/test/test.repo.js +++ b/test/test.repo.js @@ -2,7 +2,12 @@ var Github = require('../src/github.js'); var testUser = require('./user.json'); -var github, repo, user, imageB64, imageBlob; +var RELEASE_TAG = 'foo'; +var RELEASE_NAME = 'My awesome release'; +var RELEASE_BODY = 'Foo bar bazzy baz'; +var STATUS_URL = 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b'; + +var github, repo, user, imageB64, imageBlob, sha, releaseId; if (typeof window === 'undefined') { // We're in NodeJS var fs = require('fs'); @@ -33,6 +38,7 @@ if (typeof window === 'undefined') { // We're in NodeJS // jscs:disable imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC'; imageBlob = new Blob(); + // jscs:enable } } @@ -207,7 +213,7 @@ describe('Github.Repository', function() { xhr.should.be.instanceof(XMLHttpRequest); statuses.length.should.equal(6); statuses.every(function(status) { - return status.url === 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b'; + return status.url === STATUS_URL; }).should.equal(true); done(); @@ -534,6 +540,7 @@ describe('Creating new Github.Repository', function() { }, function(err, res, xhr) { should.not.exist(err); xhr.should.be.instanceof(XMLHttpRequest); + sha = res.commit.sha; done(); }); @@ -578,6 +585,54 @@ describe('Creating new Github.Repository', function() { }); }); }); + + it('should create a release', function(done) { + var options = { + tag_name: RELEASE_TAG, + target_commitish: sha + }; + + repo.createRelease(options, function(err, res, xhr) { + should.not.exist(err); + xhr.should.be.instanceof(XMLHttpRequest); + + releaseId = res.id; + done(); + }); + }); + + it('should edit a release', function(done) { + var options = { + name: RELEASE_NAME, + body: RELEASE_BODY + }; + + repo.editRelease(releaseId, options, function(err, res, xhr) { + should.not.exist(err); + res.name.should.equal(RELEASE_NAME); + res.body.should.equal(RELEASE_BODY); + xhr.should.be.instanceof(XMLHttpRequest); + + done(); + }); + }); + + it('should read a release', function(done) { + repo.getRelease(releaseId, function(err, res, xhr) { + should.not.exist(err); + res.name.should.equal(RELEASE_NAME); + xhr.should.be.instanceof(XMLHttpRequest); + done(); + }); + }); + + it('should delete a release', function(done) { + repo.deleteRelease(releaseId, function(err, res, xhr) { + should.not.exist(err); + xhr.should.be.instanceof(XMLHttpRequest); + done(); + }); + }); }); describe('deleting a Github.Repository', function() {