Skip to content

feature(repository): add updateStatus and updateRepository method #390

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
wants to merge 3 commits into from
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
37 changes: 36 additions & 1 deletion lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,41 @@ class Repository extends Requestable {
}, cb);
}

/**
* Update commit status
* @see https://developer.github.com/v3/repos/statuses/
* @param {string} commitSHA - the SHA of the commit that should be updated
* @param {object} options - Commit status parameters
* @param {string} options.state - The state of the status. Can be one of: pending, success, error, or failure.
* @param {string} [options.target_url] - The target URL to associate with this status.
* @param {string} [options.description] - A short description of the status.
* @param {string} [options.context] - A string label to differentiate this status among CI systems.
* @param {Requestable.callback} cb - will receive the updated commit back
* @return {Promise} - the promise for the http request
*/
updateStatus(commitSHA, options, cb) {
return this._request('POST', `/repos/${this.__fullname}/statuses/${commitSHA}`, options, cb);
}

/**
* Update repository information
* @see https://developer.github.com/v3/repos/#edit
* @param {object} options - New parameters that will be set to the repository
* @param {string} options.name - Name of the repository
* @param {string} [options.description] - A short description of the repository
* @param {string} [options.homepage] - A URL with more information about the repository
* @param {boolean} [options.private] - Either true to make the repository private, or false to make it public.
* @param {boolean} [options.has_issues] - Either true to enable issues for this repository, false to disable them.
* @param {boolean} [options.has_wiki] - Either true to enable the wiki for this repository, false to disable it.
* @param {boolean} [options.has_downloads] - Either true to enable downloads, false to disable them.
* @param {string} [options.default_branch] - Updates the default branch for this repository.
* @param {Requestable.callback} cb - will receive the updated repository back
* @return {Promise} - the promise for the http request
*/
updateRepository(options, cb) {
return this._request('PATCH', `/repos/${this.__fullname}`, options, cb);
}

/**
* Get information about the repository
* @see https://developer.github.com/v3/repos/#get
Expand Down Expand Up @@ -504,7 +539,7 @@ class Repository extends Requestable {
* @return {Promise} - the promise for the http request
*/
updatePullRequst(number, options, cb) {
log('Deprecated: This method contains a typo and it has been deprecated. It will be removed in next major version. Use updatePullRequest() instead.');
log('Deprecated: This method will be removed in next major version. Use updatePullRequest() instead.');

return this.updatePullRequest(number, options, cb);
}
Expand Down
34 changes: 34 additions & 0 deletions test/repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ describe('Repository', function() {
}));
});

it('should be able to edit repository information', function(done) {
const options = {
name: testRepoName,
description: 'New short description',
homepage: 'http://example.com'
};

remoteRepo.updateRepository(options, assertSuccessful(done,
function(err, repository) {
expect(repository).to.have.own('homepage', options.homepage);
expect(repository).to.have.own('description', options.description);
expect(repository).to.have.own('name', testRepoName);
done();
}));
});

it('should show repo collaborators', function(done) {
remoteRepo.getCollaborators(assertSuccessful(done, function(err, collaborators) {
if (!(collaborators instanceof Array)) {
Expand Down Expand Up @@ -398,6 +414,24 @@ describe('Repository', function() {
}));
});

it('should update commit status', function(done) {
const status = {
state: 'success',
target_url: 'http://example.com', // eslint-disable-line camelcase
description: 'Build was successful!'
};
remoteRepo.getRef('heads/master', assertSuccessful(done, function(err, refSpec) {
remoteRepo.updateStatus(refSpec.object.sha, status, assertSuccessful(done,
function(err, updated) {
expect(updated).to.have.own('state', status.state);
expect(updated).to.have.own('target_url', status.target_url);
expect(updated).to.have.own('description', status.description);
expect(updated).to.have.own('context', 'default');
done();
}));
}));
});

it('should delete ref on repo', function(done) {
remoteRepo.deleteRef('heads/new-test-branch', assertSuccessful(done));
});
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy