Skip to content

Commit c35cdbf

Browse files
committed
feature(organization): add api to list organization members
Closes github-tools#265
1 parent 25b95a6 commit c35cdbf

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lib/Organization.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ class Organization extends Requestable {
4444

4545
return this._requestAllPages(`/orgs/${this.__name}/repos`, requestOptions, cb);
4646
}
47+
48+
/**
49+
* List the users who are members of the company
50+
* @see https://developer.github.com/v3/orgs/members/#members-list
51+
* @param {object} options
52+
* @param {string} [options.filter=all] - can be either `2fa_disabled` or `all`
53+
* @param {string} [options.role=all] - can be one of: `all`, `admin`, or `member`
54+
* @param {Requestable.callback} [cb] - will receive the list of users
55+
* @return {Promise} - the promise for the http request
56+
*/
57+
listMembers(options, cb) {
58+
return this._request('GET', `/orgs/${this.__name}/members`, options, cb);
59+
}
4760
}
4861

4962
module.exports = Organization;

test/organization.spec.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import testUser from './fixtures/user.json';
55
import {assertSuccessful, assertArray} from './helpers/callbacks';
66
import getTestRepoName from './helpers/getTestRepoName';
77

8-
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
98
describe('Organization', function() {
109
let github;
10+
const ORG_NAME = 'github-tools';
1111

1212
before(function() {
1313
github = new Github({
@@ -22,12 +22,24 @@ describe('Organization', function() {
2222
let organization;
2323

2424
before(function() {
25-
organization = github.getOrganization('openaddresses');
25+
organization = github.getOrganization(ORG_NAME);
2626
});
2727

2828
it('should show user\'s organisation repos', function(done) {
2929
organization.getRepos(assertArray(done));
3030
});
31+
32+
it('should list the users in the organization', function(done) {
33+
organization.listMembers()
34+
.then(function({data: members}) {
35+
expect(members).to.be.an.array();
36+
37+
let hasClayReimann = members.reduce((found, member) => member.login === 'clayreimann' || found, false);
38+
expect(hasClayReimann).to.be.true();
39+
40+
done();
41+
}).catch(done);
42+
});
3143
});
3244

3345
describe('creating/updating', function() {
@@ -44,14 +56,14 @@ describe('Organization', function() {
4456
description: 'test create organization repo',
4557
homepage: 'https://github.com/',
4658
private: false,
47-
has_issues: true,
48-
has_wiki: true,
49-
has_downloads: true
59+
has_issues: true, // jscs:ignore
60+
has_wiki: true, // jscs:ignore
61+
has_downloads: true // jscs:ignore
5062
};
5163

5264
organization.createRepo(options, assertSuccessful(done, function(err, repo) {
5365
expect(repo.name).to.equal(testRepoName);
54-
expect(repo.full_name).to.equal(`${testUser.ORGANIZATION}/${testRepoName}`);
66+
expect(repo.full_name).to.equal(`${testUser.ORGANIZATION}/${testRepoName}`); // jscs:ignore
5567
done();
5668
}));
5769
});

0 commit comments

Comments
 (0)