Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add ability to add collaborator
  • Loading branch information
mtscout6 committed Jul 16, 2017
commit 6e0b9ded14b18081bd9b0206b6c3c1c573e8d6b5
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules/
.DS_Store
npm-debug.log
sauce.json
package-lock.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib/
.nyc_output/
.DS_Store
sauce.json
package-lock.json
18 changes: 16 additions & 2 deletions lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,27 @@ class Repository extends Requestable {
* List the users who are collaborators on the repository. The currently authenticated user must have
* push access to use this method
* @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
* @param {Requestable.callback} cb - will receive the list of collaborators
* @param {Requestable.callback} cb - will receive the fetched data
* @return {Promise} - the promise for the http request
*/
getCollaborators(cb) {
return this._request('GET', `/repos/${this.__fullname}/collaborators`, null, cb);
}

/**
* Adds user as a collaborator on the repository. The currently authenticated user must have admin access for the
* repo to use this method
* @see https://developer.github.com/enterprise/2.10/v3/repos/collaborators/#add-user-as-a-collaborator
* @param {string} username - the user to add as a collaborator
* @param {Object} [options] - collaborator permissions, only applicable on repos in an org
* @param {Object} [options.permission=push] - can be one of: `pull`, `push`, or `admin`
* @param {Requestable.callback} cb - will receive the information about the newly added contributor
* @return {Promise} - the promise for the http request
*/
addCollaborator(username, options, cb) {
return this._request('PUT', `/repos/${this.__fullname}/collaborators/${username}`, options, cb);
}

/**
* Check if a user is a collaborator on the repository
* @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
Expand All @@ -451,7 +465,7 @@ class Repository extends Requestable {
* @return {Promise} - the promise for the http request {Boolean} [description]
*/
isCollaborator(username, cb) {
return this._request('GET', `/repos/${this.__fullname}/collaborators/${username}`, null, cb);
return this._request204or404(`/repos/${this.__fullname}/collaborators/${username}`, null, cb);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/alt-user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"USERNAME": "mtscout6-test"
}
17 changes: 14 additions & 3 deletions test/repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import expect from 'must';
import Github from '../lib/GitHub';
import wait from './helpers/wait';
import testUser from './fixtures/user.json';
import altUser from './fixtures/alt-user.json';
import loadImage from './fixtures/imageBlob';
import {assertSuccessful, assertFailure} from './helpers/callbacks';
import getTestRepoName from './helpers/getTestRepoName';
Expand Down Expand Up @@ -262,7 +263,7 @@ describe('Repository', function() {
});
});

describe('creating/modifiying', function() {
describe.only('creating/modifiying', function() {
const fileName = 'test.md';

const initialText = 'This is a test.';
Expand Down Expand Up @@ -343,8 +344,18 @@ describe('Repository', function() {
}));
});

it('should test whether user is collaborator', function(done) {
remoteRepo.isCollaborator(testUser.USERNAME, assertSuccessful(done));
it('should add repo collaborator', async function() {
expect(await remoteRepo.isCollaborator(altUser.USERNAME)).to.be.false;
await remoteRepo.addCollaborator(altUser.USERNAME);
expect(await remoteRepo.isCollaborator(altUser.USERNAME)).to.be.true;
});

it('should test whether user is collaborator', async function() {
expect(await remoteRepo.isCollaborator(testUser.USERNAME)).to.be.true;
});

it('should test whether user is not collaborator', async function() {
expect(await remoteRepo.isCollaborator(altUser.USERNAME)).to.be.false;
});

it('should write to repo', function(done) {
Expand Down
5 changes: 1 addition & 4 deletions test/team.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import Github from '../lib/GitHub';
import testUser from './fixtures/user.json';
import {assertFailure} from './helpers/callbacks';
import getTestRepoName from './helpers/getTestRepoName';

const altUser = {
USERNAME: 'mtscout6-test',
};
import altUser from './fixtures/alt-user.json';

function createTestTeam() {
const name = getTestRepoName();
Expand Down