(https://github.com/mathieudutour)"
],
"readmeFilename": "README.md",
"scripts": {
"clean": "gulp clean",
"build": "gulp build",
"test": "mocha --opts ./mocha.opts test/*.spec.js",
+ "test-coverage": "NODE_ENV=test nyc mocha --opts ./mocha.opts test/*.spec.js",
"test-verbose": "DEBUG=github* npm test",
"lint": "gulp lint",
"make-docs": "node_modules/.bin/jsdoc -c .jsdoc.json --verbose",
- "release": "./release.sh"
+ "release": "./release.sh",
+ "codecov": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
},
"babel": {
"presets": [
@@ -26,33 +29,38 @@
],
"plugins": [
[
- "transform-es2015-modules-umd",
- {
- "globals": {
- "es6-promise": "Promise"
- }
- }
+ "add-module-exports",
+ "transform-es2015-modules-umd"
]
],
"env": {
"development": {
"sourceMaps": "inline"
+ },
+ "test": {
+ "plugins": [
+ "istanbul"
+ ]
}
}
},
+ "nyc": {
+ "sourceMap": false,
+ "instrument": false
+ },
"files": [
- "dist/*",
- "lib/*"
+ "dist/*"
],
"dependencies": {
- "axios": "^0.10.0",
+ "axios": "^0.15.2",
"debug": "^2.2.0",
- "es6-promise": "^3.0.2",
"js-base64": "^2.1.9",
"utf8": "^2.1.1"
},
"devDependencies": {
"babel-core": "^6.7.7",
+ "babel-plugin-add-module-exports": "^0.2.1",
+ "babel-plugin-istanbul": "3.0.0",
"babel-plugin-transform-es2015-modules-umd": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.7.2",
@@ -60,33 +68,34 @@
"browserify": "^13.0.0",
"codecov": "^1.0.1",
"del": "^2.2.0",
- "eslint-config-google": "^0.5.0",
- "eslint-plugin-mocha": "^2.2.0",
+ "eslint-config-google": "^0.7.0",
+ "eslint-plugin-mocha": "^4.7.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.2",
- "gulp-eslint": "^2.0.0",
- "gulp-jscs": "^3.0.2",
+ "gulp-eslint": "^3.0.1",
+ "gulp-jscs": "^4.0.0",
"gulp-jscs-stylish": "^1.3.0",
"gulp-rename": "^1.2.2",
- "gulp-sourcemaps": "^1.6.0",
- "gulp-uglify": "^1.5.1",
+ "gulp-sourcemaps": "^2.2.0",
+ "gulp-uglify": "^2.0.0",
"jsdoc": "^3.4.0",
"minami": "^1.1.1",
- "mocha": "^2.3.4",
+ "mocha": "^3.1.2",
"must": "^0.13.1",
- "nock": "^8.0.0",
+ "nock": "^9.0.2",
+ "nyc": "9.0.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"repository": {
"type": "git",
- "url": "git://github.com/michael/github.git"
+ "url": "git://github.com/github-tools/github.git"
},
"keywords": [
"github",
"api"
],
"bugs": {
- "url": "https://github.com/michael/github/issues"
+ "url": "https://github.com/github-tools/github/issues"
}
}
diff --git a/release.sh b/release.sh
index 0b3a3c37..63853dae 100755
--- a/release.sh
+++ b/release.sh
@@ -1,15 +1,18 @@
#!/bin/bash
# This is the automated release script
-# make sure all our dependencies are installed so we can publish docs
-npm install
-
# guard against stupid
if [ -z "$1" ]; then
echo "You must specify a new version level: [patch, minor, major]";
exit 1;
fi
+# make sure all our dependencies are installed so we can publish docs
+npm install
+
+# try to build to make sure we don't publish something really broken
+npm run build
+
# bump the version
echo "npm version $1"
npm version $1
@@ -32,5 +35,5 @@ git checkout gh-pages
mv out/* docs/
echo $VERSION >> _data/versions.csv
git add .
-git co -m "adding docs for v$VERSION"
+git commit -m "adding docs for v$VERSION"
git push
diff --git a/test/auth.spec.js b/test/auth.spec.js
index 2c03d766..bd0d8205 100644
--- a/test/auth.spec.js
+++ b/test/auth.spec.js
@@ -13,7 +13,7 @@ describe('Github', function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
user = github.getUser();
@@ -70,7 +70,7 @@ describe('Github', function() {
github = new Github({
username: testUser.USERNAME,
password: 'fake124',
- auth: 'basic'
+ auth: 'basic',
});
user = github.getUser();
@@ -83,7 +83,7 @@ describe('Github', function() {
it('should fail authentication and return err', function(done) {
user.listNotifications(assertFailure(done, function(err) {
- expect(err.status).to.be.equal(401, 'Return 401 status for bad auth');
+ expect(err.response.status).to.be.equal(401, 'Return 401 status for bad auth');
expect(err.response.data.message).to.equal('Bad credentials');
done();
diff --git a/test/gist.spec.js b/test/gist.spec.js
index 0fa476bd..c9c2e393 100644
--- a/test/gist.spec.js
+++ b/test/gist.spec.js
@@ -15,7 +15,7 @@ describe('Gist', function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
});
diff --git a/test/helpers/callbacks.js b/test/helpers/callbacks.js
index 112464ac..9c80ad98 100644
--- a/test/helpers/callbacks.js
+++ b/test/helpers/callbacks.js
@@ -7,7 +7,6 @@ export function assertSuccessful(done, cb) {
try {
expect(err).not.to.exist(err ? (err.response ? err.response.data : err) : 'No error');
expect(res).to.exist();
- expect(xhr).to.be.an.object();
if (cb) {
setTimeout(function delay() {
diff --git a/test/helpers/helperFunctions.js b/test/helpers/helperFunctions.js
new file mode 100644
index 00000000..c35ed64f
--- /dev/null
+++ b/test/helpers/helperFunctions.js
@@ -0,0 +1,43 @@
+export function getNextPage(linksHeader = '') {
+ const links = linksHeader.split(/\s*,\s*/); // splits and strips the urls
+ return links.reduce(function(nextUrl, link) {
+ if (link.search(/rel="next"/) !== -1) {
+ return (link.match(/<(.*)>/) || [])[1];
+ }
+
+ return nextUrl;
+ }, undefined);
+}
+
+export function deleteRepo(repo, github) {
+ return github
+ .getRepo(repo.owner.login, repo.name)
+ .deleteRepo()
+ .then((removed) => {
+ if (removed) {
+ console.log(repo.full_name, 'deleted'); // eslint-disable-line
+ }
+ });
+}
+
+export function deleteTeam(team, github) {
+ return github
+ .getTeam(team.id)
+ .deleteTeam()
+ .then((removed) => {
+ if (removed) {
+ console.log('team', team.name, 'deleted'); //eslint-disable-line
+ }
+ });
+}
+
+export function deleteProject(project, github) {
+ return github
+ .getProject(project.id)
+ .deleteProject()
+ .then((removed) => {
+ if (removed) {
+ console.log('project', project.name, 'deleted'); //eslint-disable-line
+ }
+ });
+}
diff --git a/test/helpers/wait.js b/test/helpers/wait.js
new file mode 100644
index 00000000..680ea360
--- /dev/null
+++ b/test/helpers/wait.js
@@ -0,0 +1,5 @@
+export default function(delay = 1000) {
+ return () => new Promise((resolve) => {
+ setTimeout(() => resolve(), delay);
+ });
+}
diff --git a/test/issue.spec.js b/test/issue.spec.js
index e3d0bb78..5064c556 100644
--- a/test/issue.spec.js
+++ b/test/issue.spec.js
@@ -2,20 +2,43 @@ import expect from 'must';
import Github from '../lib/GitHub';
import testUser from './fixtures/user.json';
+import wait from './helpers/wait';
import {assertSuccessful} from './helpers/callbacks';
+import getTestRepoName from './helpers/getTestRepoName';
describe('Issue', function() {
let github;
+ const testRepoName = getTestRepoName();
let remoteIssues;
before(function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
- remoteIssues = github.getIssues(testUser.USERNAME, 'TestRepo');
+ return github
+ .getUser()
+ .createRepo({name: testRepoName})
+ .then(wait(5000))
+ .then(function() {
+ remoteIssues = github.getIssues(testUser.USERNAME, testRepoName);
+ return remoteIssues.createIssue({
+ title: 'Test issue',
+ body: 'Test issue body',
+ });
+ })
+ .then(function() {
+ return remoteIssues.createMilestone({
+ title: 'Default Milestone',
+ description: 'Test',
+ });
+ });
+ });
+
+ after(function() {
+ return github.getRepo(testUser.USERNAME, testRepoName).deleteRepo();
});
describe('reading', function() {
@@ -69,6 +92,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) {
@@ -78,7 +102,7 @@ describe('Issue', function() {
it('should create issue', function(done) {
const newIssue = {
title: 'New issue',
- body: 'New issue body'
+ body: 'New issue body',
};
remoteIssues.createIssue(newIssue, assertSuccessful(done, function(err, issue) {
@@ -94,7 +118,7 @@ describe('Issue', function() {
it('should edit issue', function(done) {
const newProps = {
title: 'Edited title',
- state: 'closed'
+ state: 'closed',
};
remoteIssues.editIssue(createdIssueId, newProps, assertSuccessful(done, function(err, issue) {
@@ -148,7 +172,7 @@ describe('Issue', function() {
it('should create a milestone', function(done) {
let milestone = {
title: 'v42',
- description: 'The ultimate version'
+ description: 'The ultimate version',
};
remoteIssues.createMilestone(milestone)
@@ -162,7 +186,7 @@ describe('Issue', function() {
});
it('should update a milestone', function(done) {
let milestone = {
- description: 'Version 6 * 7'
+ description: 'Version 6 * 7',
};
expect(createdMilestoneId).to.be.a.number();
@@ -182,5 +206,71 @@ 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);
+ });
});
});
diff --git a/test/markdown.spec.js b/test/markdown.spec.js
index 22f5d982..eef9fe08 100644
--- a/test/markdown.spec.js
+++ b/test/markdown.spec.js
@@ -11,7 +11,7 @@ describe('Markdown', function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
markdown = github.getMarkdown();
@@ -19,7 +19,7 @@ describe('Markdown', function() {
it('should convert markdown to html as plain Markdown', function(done) {
const options = {
- text: 'Hello world github/linguist#1 **cool**, and #1!'
+ text: 'Hello world github/linguist#1 **cool**, and #1!',
};
markdown.render(options)
@@ -33,7 +33,7 @@ describe('Markdown', function() {
const options = {
text: 'Hello world github/linguist#1 **cool**, and #1!',
mode: 'gfm',
- context: 'github/gollum'
+ context: 'github/gollum',
};
markdown.render(options)
.then(function({data: html}) {
diff --git a/test/organization.spec.js b/test/organization.spec.js
index 9d5f75f6..26fd3607 100644
--- a/test/organization.spec.js
+++ b/test/organization.spec.js
@@ -9,14 +9,19 @@ describe('Organization', function() {
let github;
const ORG_NAME = 'github-tools';
const MEMBER_NAME = 'clayreimann';
+ let createdProject;
before(function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
+ return;
+ });
+ after(function() {
+ return github.getProject(createdProject.id).deleteProject();
});
describe('reading', function() {
@@ -35,7 +40,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();
@@ -76,28 +81,48 @@ describe('Organization', function() {
}));
});
- // TODO: The longer this is in place the slower it will get if we don't cleanup random test teams
+ it('should create an organization team', function(done) {
+ const options = {
+ name: testRepoName,
+ description: 'Created by unit tests',
+ privacy: 'secret',
+ };
+
+ organization.createTeam(options, assertSuccessful(done, function(err, team) {
+ expect(team.name).to.equal(testRepoName);
+ expect(team.organization.login).to.equal(testUser.ORGANIZATION); // jscs:ignore
+ done();
+ }));
+ });
+
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 === testRepoName);
expect(hasTeam).to.be.true();
});
});
- it('should create an organization team', function(done) {
- const options = {
+ it('should create a project', function(done) {
+ organization.createProject({
name: testRepoName,
- description: 'Created by unit tests',
- privacy: 'secret'
- };
+ body: 'body',
+ }, assertSuccessful(done, function(err, project) {
+ createdProject = project;
+ expect(project).to.own('name', testRepoName);
+ expect(project).to.own('body', 'body');
+ done();
+ }));
+ });
- organization.createTeam(options, assertSuccessful(done, function(err, team) {
- expect(team.name).to.equal(testRepoName);
- expect(team.organization.login).to.equal(testUser.ORGANIZATION); // jscs:ignore
+ it('should list repo projects', function(done) {
+ organization.listProjects(assertSuccessful(done, function(err, projects) {
+ expect(projects).to.be.an.array();
+
+ const hasProject = projects.some((project) => project.name === testRepoName);
+
+ expect(hasProject).to.be.true();
done();
}));
});
diff --git a/test/project.spec.js b/test/project.spec.js
new file mode 100644
index 00000000..cccf4e81
--- /dev/null
+++ b/test/project.spec.js
@@ -0,0 +1,171 @@
+import expect from 'must';
+
+import Github from '../lib/GitHub';
+import wait from './helpers/wait';
+import testUser from './fixtures/user.json';
+import {assertSuccessful} from './helpers/callbacks';
+import getTestRepoName from './helpers/getTestRepoName';
+
+describe('Project', function() {
+ let github;
+ const testRepoName = getTestRepoName();
+ let project;
+ let columnId;
+ let cardId;
+
+ before(function() {
+ github = new Github({
+ username: testUser.USERNAME,
+ password: testUser.PASSWORD,
+ auth: 'basic',
+ });
+
+ return github
+ .getUser()
+ .createRepo({name: testRepoName})
+ .then(wait(5000))
+ .then(function() {
+ const remoteRepo = github.getRepo(testUser.USERNAME, testRepoName);
+ return remoteRepo.createProject({
+ name: 'test-project',
+ body: 'body',
+ });
+ })
+ .then(function(_project) {
+ project = github.getProject(_project.data.id);
+ });
+ });
+
+ after(function() {
+ return github.getRepo(testUser.USERNAME, testRepoName).deleteRepo();
+ });
+
+ it('should get repo project', function(done) {
+ project.getProject(assertSuccessful(done, function(err, project) {
+ expect(project).to.own('name', 'test-project');
+ done();
+ }));
+ });
+
+ it('should update a project', function(done) {
+ project.updateProject({
+ name: 'another-test-project',
+ body: 'another-body',
+ }, assertSuccessful(done, function(err, project) {
+ expect(project).to.own('name', 'another-test-project');
+ expect(project).to.own('body', 'another-body');
+ done();
+ }));
+ });
+
+ it('should create a repo project column', function(done) {
+ project.createProjectColumn({
+ name: 'test-column',
+ }, assertSuccessful(done, function(err, column) {
+ expect(column).to.own('name', 'test-column');
+ columnId = column.id;
+ done();
+ }));
+ });
+
+ it('should list repo project columns', function(done) {
+ project.listProjectColumns(assertSuccessful(done, function(err, columns) {
+ expect(columns).to.be.an.array();
+ expect(columns.length).to.equal(1);
+ done();
+ }));
+ });
+
+ it('should get repo project column', function(done) {
+ project.getProjectColumn(columnId, assertSuccessful(done, function(err, project) {
+ expect(project).to.own('name', 'test-column');
+ done();
+ }));
+ });
+
+ it('should update a repo project column', function(done) {
+ project.updateProjectColumn(columnId, {
+ name: 'another-test-column',
+ }, assertSuccessful(done, function(err, column) {
+ expect(column).to.own('name', 'another-test-column');
+ done();
+ }));
+ });
+
+ it('should create repo project card', function(done) {
+ project.createProjectCard(columnId, {
+ note: 'test-card',
+ }, assertSuccessful(done, function(err, card) {
+ expect(card).to.own('note', 'test-card');
+ cardId = card.id;
+ done();
+ }));
+ });
+
+ it('should list cards of a project', function(done) {
+ project.listProjectCards(assertSuccessful(done, function(err, cards) {
+ expect(cards).to.be.an.array();
+ expect(cards.length).to.equal(1);
+ done();
+ }));
+ });
+
+ it('should list cards of a column', function(done) {
+ project.listColumnCards(columnId, assertSuccessful(done, function(err, cards) {
+ expect(cards).to.be.an.array();
+ expect(cards.length).to.equal(1);
+ done();
+ }));
+ });
+
+ it('should get repo project card', function(done) {
+ project.getProjectCard(cardId, assertSuccessful(done, function(err, card) {
+ expect(card).to.own('note', 'test-card');
+ done();
+ }));
+ });
+
+ it('should update repo project card', function(done) {
+ project.updateProjectCard(cardId, {
+ note: 'another-test-card',
+ }, assertSuccessful(done, function(err, card) {
+ expect(card).to.own('note', 'another-test-card');
+ done();
+ }));
+ });
+
+ it('should move repo project card', function(done) {
+ project.moveProjectCard(cardId, 'top', columnId, assertSuccessful(done, function(err, result) {
+ expect(result).to.be(true);
+ done();
+ }));
+ });
+
+ it('should move repo project column', function(done) {
+ project.moveProjectColumn(columnId, 'first', assertSuccessful(done, function(err, result) {
+ expect(result).to.be(true);
+ done();
+ }));
+ });
+
+ it('should delete repo project card', function(done) {
+ project.deleteProjectCard(cardId, assertSuccessful(done, function(err, result) {
+ expect(result).to.be(true);
+ done();
+ }));
+ });
+
+ it('should delete repo project column', function(done) {
+ project.deleteProjectColumn(columnId, assertSuccessful(done, function(err, result) {
+ expect(result).to.be(true);
+ done();
+ }));
+ });
+
+ it('should delete repo project', function(done) {
+ project.deleteProject(assertSuccessful(done, function(err, result) {
+ expect(result).to.be(true);
+ done();
+ }));
+ });
+});
diff --git a/test/rate-limit.spec.js b/test/rate-limit.spec.js
index 23e12d14..c3a5b858 100644
--- a/test/rate-limit.spec.js
+++ b/test/rate-limit.spec.js
@@ -12,7 +12,7 @@ describe('RateLimit', function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
rateLimit = github.getRateLimit();
diff --git a/test/repository.spec.js b/test/repository.spec.js
index f747878d..ef5101cf 100644
--- a/test/repository.spec.js
+++ b/test/repository.spec.js
@@ -1,6 +1,7 @@
import expect from 'must';
import Github from '../lib/GitHub';
+import wait from './helpers/wait';
import testUser from './fixtures/user.json';
import loadImage from './fixtures/imageBlob';
import {assertSuccessful, assertFailure} from './helpers/callbacks';
@@ -8,18 +9,18 @@ import getTestRepoName from './helpers/getTestRepoName';
describe('Repository', function() {
let github;
- let remoteRepo;
let user;
let imageB64;
let imageBlob;
const testRepoName = getTestRepoName();
const v10SHA = '20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
- const statusUrl = 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
+ const statusUrl =
+ 'https://api.github.com/repos/github-tools/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
before(function(done) {
github = new Github({
username: testUser.USERNAME,
- password: testUser.PASSWORD
+ password: testUser.PASSWORD,
});
loadImage(function(b64, blob) {
@@ -30,13 +31,15 @@ describe('Repository', function() {
});
describe('reading', function() {
+ let remoteRepo;
+
before(function() {
- remoteRepo = github.getRepo('michael', 'github');
+ remoteRepo = github.getRepo('github-tools', 'github');
});
it('should get repo details', function(done) {
remoteRepo.getDetails(assertSuccessful(done, function(err, repo) {
- expect(repo).to.have.own('full_name', 'michael/github');
+ expect(repo).to.have.own('full_name', 'github-tools/github');
done();
}));
@@ -137,7 +140,7 @@ describe('Repository', function() {
path: 'test',
author: 'AurelioDeRosa',
since,
- until
+ until,
};
remoteRepo.listCommits(options, assertSuccessful(done, function(err, commits) {
@@ -166,7 +169,7 @@ describe('Repository', function() {
it('should fail when null ref is passed', function(done) {
remoteRepo.getSingleCommit(null, assertFailure(done, function(err) {
- expect(err.status).to.be(404);
+ expect(err.response.status).to.be(404);
done();
}));
});
@@ -181,6 +184,23 @@ describe('Repository', function() {
const contributor = contributors[0];
+ expect(contributor).to.have.own('login');
+ expect(contributor).to.have.own('contributions');
+
+ done();
+ }));
+ });
+
+ it('should show repo contributor stats', function(done) {
+ remoteRepo.getContributorStats(assertSuccessful(done, function(err, contributors) {
+ if (!(contributors instanceof Array)) {
+ console.log(JSON.stringify(contributors, null, 2)); // eslint-disable-line
+ }
+ expect(contributors).to.be.an.array();
+ expect(contributors.length).to.be.above(1);
+
+ const contributor = contributors[0];
+
expect(contributor).to.have.own('author');
expect(contributor).to.have.own('total');
expect(contributor).to.have.own('weeks');
@@ -224,10 +244,10 @@ describe('Repository', function() {
});
it('should get a repo by fullname', function(done) {
- const repoByName = github.getRepo('michael/github');
+ const repoByName = github.getRepo('github-tools/github');
repoByName.getDetails(assertSuccessful(done, function(err, repo) {
- expect(repo).to.have.own('full_name', 'michael/github');
+ expect(repo).to.have.own('full_name', 'github-tools/github');
done();
}));
@@ -265,6 +285,7 @@ describe('Repository', function() {
const releaseBody = 'This is my 49 character long release description.';
let sha;
let releaseId;
+ let remoteRepo;
before(function() {
user = github.getUser();
@@ -278,7 +299,7 @@ describe('Repository', function() {
it('should create repo', function(done) {
const repoDef = {
- name: testRepoName
+ name: testRepoName,
};
user.createRepo(repoDef, assertSuccessful(done, function(err, repo) {
@@ -288,6 +309,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)) {
@@ -312,26 +349,27 @@ describe('Repository', function() {
it('should write to repo', function(done) {
remoteRepo.writeFile('master', fileName, initialText, initialMessage, assertSuccessful(done, function() {
- remoteRepo.getContents('master', fileName, 'raw', assertSuccessful(done, function(err, fileText) {
+ wait()().then(() => remoteRepo.getContents('master', fileName, 'raw',
+ assertSuccessful(done, function(err, fileText) {
expect(fileText).to.be(initialText);
done();
- }));
+ })));
}));
});
it('should rename files', function(done) {
remoteRepo.writeFile('master', fileName, initialText, initialMessage, assertSuccessful(done, function() {
- remoteRepo.move('master', fileName, 'new_name', assertSuccessful(done, function() {
- remoteRepo.getContents('master', fileName, 'raw', assertFailure(done, function(err) {
- expect(err.status).to.be(404);
+ wait()().then(() => remoteRepo.move('master', fileName, 'new_name', assertSuccessful(done, function() {
+ wait()().then(() => remoteRepo.getContents('master', fileName, 'raw', assertFailure(done, function(err) {
+ expect(err.response.status).to.be(404);
remoteRepo.getContents('master', 'new_name', 'raw', assertSuccessful(done, function(err, fileText) {
expect(fileText).to.be(initialText);
done();
}));
- }));
- }));
+ })));
+ })));
}));
});
@@ -392,12 +430,30 @@ describe('Repository', function() {
remoteRepo.getRef('heads/master', assertSuccessful(done, function(err, refSpec) {
let newRef = {
ref: 'refs/heads/new-test-branch',
- sha: refSpec.object.sha
+ sha: refSpec.object.sha,
};
remoteRepo.createRef(newRef, assertSuccessful(done));
}));
});
+ 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));
});
@@ -424,7 +480,7 @@ describe('Repository', function() {
});
it('should get pull requests on repo', function(done) {
- const repo = github.getRepo('michael', 'github');
+ const repo = github.getRepo('github-tools', 'github');
repo.getPullRequest(153, assertSuccessful(done, function(err, pr) {
expect(pr).to.have.own('title');
@@ -444,7 +500,7 @@ describe('Repository', function() {
it('should write author and committer to repo', function(done) {
const options = {
author: {name: 'Author Name', email: 'author@example.com'},
- committer: {name: 'Committer Name', email: 'committer@example.com'}
+ committer: {name: 'Committer Name', email: 'committer@example.com'},
};
remoteRepo.writeFile('dev',
@@ -482,7 +538,7 @@ describe('Repository', function() {
remoteRepo.getRef('heads/master', assertSuccessful(done, function(err, refSpec) {
let newRef = {
ref: 'refs/heads/testing-14',
- sha: refSpec.object.sha
+ sha: refSpec.object.sha,
};
remoteRepo.createRef(newRef, assertSuccessful(done, function() {
@@ -503,7 +559,7 @@ describe('Repository', function() {
it('should be able to write an image to the repo', function(done) {
const opts = {
- encode: false
+ encode: false,
};
remoteRepo.writeFile('master', imageFileName, imageB64, initialMessage, opts, assertSuccessful(done,
@@ -539,7 +595,7 @@ describe('Repository', function() {
it('should fail on broken commit', function(done) {
remoteRepo.commit('broken-parent-hash', 'broken-tree-hash', initialMessage, assertFailure(done, function(err) {
- expect(err.status).to.be(422);
+ expect(err.response.status).to.be(422);
done();
}));
});
@@ -560,7 +616,7 @@ describe('Repository', function() {
it('should edit a release', function(done) {
const releaseDef = {
name: releaseName,
- body: releaseBody
+ body: releaseBody,
};
remoteRepo.updateRelease(releaseId, releaseDef, assertSuccessful(done, function(err, release) {
@@ -589,9 +645,29 @@ describe('Repository', function() {
it('should delete a release', function(done) {
remoteRepo.deleteRelease(releaseId, assertSuccessful(done));
});
+
+ it('should create a project', function(done) {
+ remoteRepo.createProject({
+ name: 'test-project',
+ body: 'body',
+ }, assertSuccessful(done, function(err, project) {
+ expect(project).to.own('name', 'test-project');
+ expect(project).to.own('body', 'body');
+ done();
+ }));
+ });
+
+ it('should list repo projects', function(done) {
+ remoteRepo.listProjects(assertSuccessful(done, function(err, projects) {
+ expect(projects).to.be.an.array();
+ expect(projects.length).to.equal(1);
+ done();
+ }));
+ });
});
describe('deleting', function() {
+ let remoteRepo;
before(function() {
remoteRepo = github.getRepo(testUser.USERNAME, testRepoName);
});
diff --git a/test/search.spec.js b/test/search.spec.js
index 93d852da..21a32935 100644
--- a/test/search.spec.js
+++ b/test/search.spec.js
@@ -5,14 +5,14 @@ import Github from '../lib/GitHub';
import testUser from './fixtures/user.json';
describe('Search', function() {
- this.timeout(20 * 1000);
+ this.timeout(20 * 1000); // eslint-disable-line no-invalid-this
let github;
before(function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
nock.load('test/fixtures/search.json');
});
@@ -22,7 +22,7 @@ describe('Search', function() {
let search = github.search({
q: 'tetris language:assembly',
sort: 'stars',
- order: 'desc'
+ order: 'desc',
});
return search.forRepositories(options)
@@ -35,7 +35,7 @@ describe('Search', function() {
it('should search code', function() {
let options;
let search = github.search({
- q: 'addClass in:file language:js repo:jquery/jquery'
+ q: 'addClass in:file language:js repo:jquery/jquery',
});
return search.forCode(options)
@@ -50,7 +50,7 @@ describe('Search', function() {
let search = github.search({
q: 'windows pip label:bug language:python state:open ',
sort: 'created',
- order: 'asc'
+ order: 'asc',
});
return search.forIssues(options)
@@ -63,7 +63,7 @@ describe('Search', function() {
it('should search users', function() {
let options;
let search = github.search({
- q: 'tom repos:>42 followers:>1000'
+ q: 'tom repos:>42 followers:>1000',
});
return search.forUsers(options)
diff --git a/test/team.spec.js b/test/team.spec.js
index 1f712617..8a5ec8be 100644
--- a/test/team.spec.js
+++ b/test/team.spec.js
@@ -6,7 +6,7 @@ import {assertFailure} from './helpers/callbacks';
import getTestRepoName from './helpers/getTestRepoName';
const altUser = {
- USERNAME: 'mtscout6-test'
+ USERNAME: 'mtscout6-test',
};
function createTestTeam() {
@@ -15,14 +15,14 @@ function createTestTeam() {
const github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
const org = github.getOrganization(testUser.ORGANIZATION);
return org.createTeam({
name,
- privacy: 'closed'
+ privacy: 'closed',
}).then(({data: result}) => {
const team = github.getTeam(result.id);
return {team, name};
@@ -37,10 +37,59 @@ describe('Team', function() { // Isolate tests that are based on a fixed team
const github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
- team = github.getTeam(2027812); // github-api-tests/fixed-test-team-1
+ const org = github.getOrganization(testUser.ORGANIZATION);
+
+ /* eslint-disable no-console */
+ // The code below add a fixed-test-repo-1
+ let promiseRepo = new Promise((resolve) => {
+ org
+ .createRepo({name: 'fixed-test-repo-1'})
+ .then(resolve, () => {
+ console.log('skiped fixed-test-repo-1 creation');
+ resolve();
+ });
+ });
+
+ // The code below add a fixed-test-repo-1
+ let promiseTeam = org
+ .createTeam({
+ name: 'fixed-test-repo-1',
+ repo_names: [testUser.ORGANIZATION + '/fixed-test-repo-1'], // eslint-disable-line camelcase
+ })
+ .then(({data: team}) => team)
+ .catch(() => {
+ console.log('skiped fixed-test-repo-1 creation');
+ // Team already exists, fetch the team
+ return org.getTeams().then(({data: teams}) => {
+ let team = teams
+ .filter((team) => team.name === 'fixed-test-repo-1')
+ .pop();
+ if (!team) {
+ throw new Error('missing fixed-test-repo-1');
+ }
+ return team;
+ });
+ });
+ /* eslint-enable no-console */
+
+ return promiseRepo.then(() => {
+ return promiseTeam
+ .then((t) => {
+ team = github.getTeam(t.id);
+ return team;
+ })
+ .then((team) => {
+ let setupTeam = [
+ team.addMembership(altUser.USERNAME),
+ team.addMembership(testUser.USERNAME),
+ team.manageRepo(testUser.ORGANIZATION, 'fixed-test-repo-1'),
+ ];
+ return Promise.all(setupTeam);
+ });
+ });
});
it('should get membership for a given user', function() {
@@ -56,10 +105,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
- );
+ const hasTestUser = members.some((member) => member.login === testUser.USERNAME);
expect(hasTestUser).to.be.true();
});
@@ -68,10 +114,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();
});
@@ -80,7 +123,7 @@ describe('Team', function() { // Isolate tests that are based on a fixed team
it('should get team', function() {
return team.getTeam()
.then(({data}) => {
- expect(data.name).to.equal('Fixed Test Team 1');
+ expect(data.name).to.equal('fixed-test-repo-1');
});
});
diff --git a/test/user.spec.js b/test/user.spec.js
index 81181389..2296781c 100644
--- a/test/user.spec.js
+++ b/test/user.spec.js
@@ -10,7 +10,7 @@ describe('User', function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
- auth: 'basic'
+ auth: 'basic',
});
user = github.getUser();
});
@@ -24,7 +24,7 @@ describe('User', function() {
type: 'owner',
sort: 'updated',
per_page: 90, // eslint-disable-line
- page: 10
+ page: 10,
};
user.listRepos(filterOpts, assertArray(done));
@@ -47,7 +47,7 @@ describe('User', function() {
all: true,
participating: true,
since: '2015-01-01T00:00:00Z',
- before: '2015-02-01T00:00:00Z'
+ before: '2015-02-01T00:00:00Z',
};
user.listNotifications(filterOpts, assertArray(done));
@@ -68,4 +68,8 @@ describe('User', function() {
it('should unfollow user', function(done) {
user.unfollow('ingalls', assertSuccessful(done));
});
+
+ it('should list the email addresses of the user', function(done) {
+ user.getEmails(assertSuccessful(done));
+ });
});
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