Skip to content

feat: Issue get/delete/edit/list for labels #391

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 4 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## next - ???

### Features
* add `Issue.editLabel`
* add `Issue.deleteLabel`
* add `Issue.getLabel`
* add `Issue.listLabels`

## 2.4.0 - 2016/09/16
### Features
* add `Issue.createLabel`
Expand Down
53 changes: 49 additions & 4 deletions lib/Issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Issue extends Requestable {
* Get a milestone
* @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
* @param {string} milestone - the id of the milestone to fetch
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the milestone
* @return {Promise} - the promise for the http request
*/
getMilestone(milestone, cb) {
Expand All @@ -161,7 +161,7 @@ class Issue extends Requestable {
* Create a new milestone
* @see https://developer.github.com/v3/issues/milestones/#create-a-milestone
* @param {Object} milestoneData - the milestone definition
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the milestone
* @return {Promise} - the promise for the http request
*/
createMilestone(milestoneData, cb) {
Expand All @@ -173,7 +173,7 @@ class Issue extends Requestable {
* @see https://developer.github.com/v3/issues/milestones/#update-a-milestone
* @param {string} milestone - the id of the milestone to edit
* @param {Object} milestoneData - the updates to make to the milestone
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the updated milestone
* @return {Promise} - the promise for the http request
*/
editMilestone(milestone, milestoneData, cb) {
Expand All @@ -184,7 +184,7 @@ class Issue extends Requestable {
* Delete a milestone (this is distinct from closing a milestone)
* @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone
* @param {string} milestone - the id of the milestone to delete
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the status
* @return {Promise} - the promise for the http request
*/
deleteMilestone(milestone, cb) {
Expand All @@ -201,6 +201,51 @@ class Issue extends Requestable {
createLabel(labelData, cb) {
return this._request('POST', `/repos/${this.__repository}/labels`, labelData, cb);
}

/**
* List the labels for the repository
* @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
* @param {Object} options - filtering options
* @param {Requestable.callback} [cb] - will receive the array of labels
* @return {Promise} - the promise for the http request
*/
listLabels(options, cb) {
return this._request('GET', `/repos/${this.__repository}/labels`, options, cb);
}

/**
* Get a label
* @see https://developer.github.com/v3/issues/labels/#get-a-single-label
* @param {string} label - the name of the label to fetch
* @param {Requestable.callback} [cb] - will receive the label
* @return {Promise} - the promise for the http request
*/
getLabel(label, cb) {
return this._request('GET', `/repos/${this.__repository}/labels/${label}`, null, cb);
}

/**
* Edit a label
* @see https://developer.github.com/v3/issues/labels/#update-a-label
* @param {string} label - the id of the label to edit
* @param {Object} labelData - the updates to make to the label
* @param {Requestable.callback} [cb] - will receive the updated label
* @return {Promise} - the promise for the http request
*/
editLabel(label, labelData, cb) {
return this._request('PATCH', `/repos/${this.__repository}/labels/${label}`, labelData, cb);
}

/**
* Delete a label
* @see https://developer.github.com/v3/issues/labels/#delete-a-label
* @param {string} label - the name of the label to delete
* @param {Requestable.callback} [cb] - will receive the status
* @return {Promise} - the promise for the http request
*/
deleteLabel(label, cb) {
return this._request('DELETE', `/repos/${this.__repository}/labels/${label}`, null, cb);
}
}

module.exports = Issue;
4 changes: 2 additions & 2 deletions lib/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Requestable from './Requestable';

/**
* RateLimit allows users to query their rate-limit status
* Renders html from Markdown text
*/
class Markdown extends Requestable {
/**
* construct a RateLimit
* construct a Markdown
* @param {Requestable.auth} auth - the credentials to authenticate to GitHub
* @param {string} [apiBase] - the base Github API URL
* @return {Promise} - the promise for the http request
Expand Down
3 changes: 2 additions & 1 deletion lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ 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 contains a typo and it has been deprecated.' +
'It will be removed in next major version. Use updatePullRequest() instead.');

return this.updatePullRequest(number, options, cb);
}
Expand Down
70 changes: 70 additions & 0 deletions test/issue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('Issue', function() {
let createdIssueId;
let issueCommentId;
let createdMilestoneId;
let createdLabel;

// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
Expand Down Expand Up @@ -160,6 +161,7 @@ describe('Issue', function() {
done();
}).catch(done);
});

it('should update a milestone', function(done) {
let milestone = {
description: 'Version 6 * 7'
Expand All @@ -174,6 +176,7 @@ describe('Issue', function() {
done();
}).catch(done);
});

it('should delete a milestone', function(done) {
expect(createdMilestoneId).to.be.a.number();
remoteIssues.deleteMilestone(createdMilestoneId)
Expand All @@ -182,5 +185,72 @@ describe('Issue', function() {
done();
}).catch(done);
});

it('should create a label', (done) => {
let label = {
name: 'test',
color: '123456'
};

remoteIssues.createLabel(label)
.then(({data: createdLabel}) => {
expect(createdLabel).to.have.own('name', label.name);
expect(createdLabel).to.have.own('color', label.color);

createdLabel = label.name;
done();
}).catch(done);
});

it('should retrieve a single label', (done) => {
let label = {
name: 'test',
color: '123456'
};

remoteIssues.getLabel(label.name)
.then(({data: retrievedLabel}) => {
expect(retrievedLabel).to.have.own('name', label.name);
expect(retrievedLabel).to.have.own('color', label.color);

done();
}).catch(done);
});

it('should update a label', (done) => {
let label = {
color: '789abc'
};

expect(createdLabel).to.be.a.string();
remoteIssues.editLabel(createdLabel, label)
.then(({data: updatedLabel}) => {
expect(updatedLabel).to.have.own('name', createdLabel);
expect(updatedLabel).to.have.own('color', label.color);

done();
}).catch(done);
});

it('should list labels', (done) => {
expect(createdLabel).to.be.a.string();

remoteIssues.listLabels({}, assertSuccessful(done, function(err, labels) {
expect(labels).to.be.an.array();
const hasLabel = labels.some((label) => label.name === createdLabel);
expect(hasLabel).to.be.true();
done();
}));
});

it('should delete a label', (done) => {
expect(createdLabel).to.be.a.string();
remoteIssues.deleteLabel(createdLabel)
.then(({status}) => {
expect(status).to.equal(204);
done();
}).catch(done);
});

});
});
6 changes: 2 additions & 4 deletions test/organization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Organization', function() {
.then(function({data: members}) {
expect(members).to.be.an.array();

let hasClayReimann = members.reduce((found, member) => member.login === MEMBER_NAME || found, false);
const hasClayReimann = members.some((member) => member.login === MEMBER_NAME);
expect(hasClayReimann).to.be.true();

done();
Expand Down Expand Up @@ -80,9 +80,7 @@ describe('Organization', function() {
it('should list the teams in the organization', function() {
return organization.getTeams()
.then(({data}) => {
const hasTeam = data.reduce(
(found, member) => member.slug === 'fixed-test-team-1' || found,
false);
const hasTeam = data.some((member) => member.slug === 'fixed-test-team-1');

expect(hasTeam).to.be.true();
});
Expand Down
10 changes: 2 additions & 8 deletions test/team.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ describe('Team', function() { // Isolate tests that are based on a fixed team
.then(function({data: members}) {
expect(members).to.be.an.array();

let hasTestUser = members.reduce(
(found, member) => member.login === testUser.USERNAME || found,
false
);
let hasTestUser = members.some((member) => member.login === testUser.USERNAME);

expect(hasTestUser).to.be.true();
});
Expand All @@ -68,10 +65,7 @@ describe('Team', function() { // Isolate tests that are based on a fixed team
it('should get team repos', function() {
return team.listRepos()
.then(({data}) => {
const hasRepo = data.reduce(
(found, repo) => repo.name === 'fixed-test-repo-1' || found,
false
);
const hasRepo = data.some((repo) => repo.name === 'fixed-test-repo-1');

expect(hasRepo).to.be.true();
});
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