Skip to content

Commit 34a350d

Browse files
committed
feature(organization): add isMember api
Closes #289
1 parent c35cdbf commit 34a350d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Organization.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class Organization extends Requestable {
4545
return this._requestAllPages(`/orgs/${this.__name}/repos`, requestOptions, cb);
4646
}
4747

48+
/**
49+
* Query if the user is a member or not
50+
* @param {string} username - the user in question
51+
* @param {Requestable.callback} [cb] - will receive true if the user is a member
52+
* @return {Promise} - the promise for the http request
53+
*/
54+
isMember(username, cb) {
55+
return this._request204or404(`/orgs/${this.__name}/members/${username}`, null, cb);
56+
}
57+
4858
/**
4959
* List the users who are members of the company
5060
* @see https://developer.github.com/v3/orgs/members/#members-list

test/organization.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import getTestRepoName from './helpers/getTestRepoName';
88
describe('Organization', function() {
99
let github;
1010
const ORG_NAME = 'github-tools';
11+
const MEMBER_NAME = 'clayreimann';
1112

1213
before(function() {
1314
github = new Github({
@@ -34,12 +35,20 @@ describe('Organization', function() {
3435
.then(function({data: members}) {
3536
expect(members).to.be.an.array();
3637

37-
let hasClayReimann = members.reduce((found, member) => member.login === 'clayreimann' || found, false);
38+
let hasClayReimann = members.reduce((found, member) => member.login === MEMBER_NAME || found, false);
3839
expect(hasClayReimann).to.be.true();
3940

4041
done();
4142
}).catch(done);
4243
});
44+
45+
it('should test for membership', function(done) {
46+
organization.isMember(MEMBER_NAME)
47+
.then(function(isMember) {
48+
expect(isMember).to.be.true();
49+
done();
50+
}).catch(done);
51+
});
4352
});
4453

4554
describe('creating/updating', function() {

0 commit comments

Comments
 (0)