+
Skip to content

Add release events api #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
28 changes: 28 additions & 0 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 57 additions & 2 deletions test/test.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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() {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载