Skip to content

Commit

Permalink
Resolve merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyGramlich committed Jun 17, 2019
2 parents 4d3f075 + edf3270 commit 92455bb
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 30 deletions.
21 changes: 9 additions & 12 deletions .travis.yml
@@ -1,29 +1,26 @@
sudo: false
language: node_js
node_js:
- '6'
- '5'
- '4'

- '11'
- '10'
- '8'
cache:
directories:
- node_modules
- node_modules
before_install: npm install -g npm@latest
before_script:
- npm run lint
# - npm run build # will need this when we do sauce testing of compiled files
- npm run lint
script:
- npm run test-coverage
# - npm run test-dist # test the compiled files
- npm run test-coverage
after_success:
- npm run codecov
- npm run codecov
before_deploy:
- npm run build
- npm run build
deploy:
provider: npm
skip_cleanup: true
on:
tags: true
email: clayreimann@gmail.com
api_key:
secure: TZHqJ9Kh2Qf0GAVDjEOQ01Ez6rGMYHKwVLOKTbnb7nSzF7iiGNT4UwzvYawm0T9p1k7X1WOqW3l7OEbIwoKl7/9azT4BBJm7qUMRfB9Zio5cL3rKubJVz7+LEEIW4iBeDWLanhUDgy9BO2JKCt8bfp/U2tltgXtu9Fm/UFPALI8=
secure: WnLh1m02aF7NvFNILCZ8KsjPuDeSddQI87y8dwAixStr2FhQyz8FIKZN2Qj1N1Q9ZJvBETe5HWs1c9yOjTKBkD0d/eU2hlpnB9WXEFRJVDjiUuMnpAMMvuqTZwYg6kXq5N+of95PX58AYiBiV/qwsdUr/MgjEEYLt5UZgRYQRvE=
9 changes: 3 additions & 6 deletions README.md
Expand Up @@ -9,7 +9,7 @@
[![Travis](https://img.shields.io/travis/github-tools/github.svg?maxAge=60)][travis-ci]
[![Codecov](https://img.shields.io/codecov/c/github/github-tools/github.svg?maxAge=2592000)][codecov]

Github.js provides a minimal higher-level wrapper around Github's API.
`Github.js` provides a minimal higher-level wrapper around Github's API.

## Usage

Expand Down Expand Up @@ -71,7 +71,7 @@ clayreimann.listStarredRepos(function(err, repos) {
should include updated JSDoc.

## Installation
Github.js is available from `npm` or [unpkg][unpkg].
`Github.js` is available from `npm` or [unpkg][unpkg].

```shell
npm install github-api
Expand All @@ -86,10 +86,7 @@ npm install github-api
```

## Compatibility
`Github.js` is tested on Node.js:
* 6.x

Note: `Github.js` uses Promise, hence it will not work in Node.js < 4 without polyfill.
`Github.js` is tested on node's LTS and current versions.

[codecov]: https://codecov.io/github/github-tools/github?branch=master
[docs]: http://github-tools.github.io/github/
Expand Down
2 changes: 1 addition & 1 deletion lib/GitHub.js
Expand Up @@ -34,7 +34,7 @@ class GitHub {

/**
* Create a new Gist wrapper
* @param {number} [id] - the id for the gist, leave undefined when creating a new gist
* @param {string} [id] - the id for the gist, leave undefined when creating a new gist
* @return {Gist}
*/
getGist(id) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Markdown.js
Expand Up @@ -32,7 +32,7 @@ class Markdown extends Requestable {
* @return {Promise} - the promise for the http request
*/
render(options, cb) {
return this._request('POST', '/markdown', options, cb);
return this._request('POST', '/markdown', options, cb, true);
}
}

Expand Down
31 changes: 28 additions & 3 deletions lib/Repository.js
Expand Up @@ -14,7 +14,7 @@ import debug from 'debug';
const log = debug('github:repository');

/**
* Respository encapsulates the functionality to create, query, and modify files.
* Repository encapsulates the functionality to create, query, and modify files.
*/
class Repository extends Requestable {
/**
Expand Down Expand Up @@ -188,7 +188,10 @@ class Repository extends Requestable {
*/
listCommits(options, cb) {
options = options || {};

if (typeof options === 'function') {
cb = options;
options = {};
}
options.since = this._dateToISO(options.since);
options.until = this._dateToISO(options.until);

Expand Down Expand Up @@ -334,16 +337,26 @@ class Repository extends Requestable {
* @param {string} parent - the SHA of the parent commit
* @param {string} tree - the SHA of the tree for this commit
* @param {string} message - the commit message
* @param {Object} [options] - commit options
* @param {Object} [options.author] - the author of the commit
* @param {Object} [options.commiter] - the committer
* @param {Requestable.callback} cb - will receive the commit that is created
* @return {Promise} - the promise for the http request
*/
commit(parent, tree, message, cb) {
commit(parent, tree, message, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}

let data = {
message,
tree,
parents: [parent],
};

data = Object.assign({}, options, data);

return this._request('POST', `/repos/${this.__fullname}/git/commits`, data, cb)
.then((response) => {
this.__currentTree.sha = response.data.sha; // Update latest commit
Expand Down Expand Up @@ -494,6 +507,18 @@ class Repository extends Requestable {
return this._request('POST', `/repos/${this.__fullname}/forks`, null, cb);
}

/**
* Fork a repository to an organization
* @see https://developer.github.com/v3/repos/forks/#create-a-fork
* @param {String} org - organization where you'd like to create the fork.
* @param {Requestable.callback} cb - will receive the information about the newly created fork
* @return {Promise} - the promise for the http request
*
*/
forkToOrg(org, cb) {
return this._request('POST', `/repos/${this.__fullname}/forks?organization=${org}`, null, cb);
}

/**
* List a repository's forks
* @see https://developer.github.com/v3/repos/forks/#list-forks
Expand Down
4 changes: 2 additions & 2 deletions lib/Requestable.js
Expand Up @@ -124,7 +124,7 @@ class Requestable {

/**
* if a `Date` is passed to this function it will be converted to an ISO string
* @param {*} date - the object to attempt to cooerce into an ISO date string
* @param {*} date - the object to attempt to coerce into an ISO date string
* @return {string} - the ISO representation of `date` or whatever was passed in if it was not a date
*/
_dateToISO(date) {
Expand Down Expand Up @@ -235,7 +235,7 @@ class Requestable {
* @param {string} path - the path to request
* @param {Object} options - the query parameters to include
* @param {Requestable.callback} [cb] - the function to receive the data. The returned data will always be an array.
* @param {Object[]} results - the partial results. This argument is intended for interal use only.
* @param {Object[]} results - the partial results. This argument is intended for internal use only.
* @return {Promise} - a promise which will resolve when all pages have been fetched
* @deprecated This will be folded into {@link Requestable#_request} in the 2.0 release.
*/
Expand Down
37 changes: 37 additions & 0 deletions lib/User.js
Expand Up @@ -81,6 +81,26 @@ class User extends Requestable {
return this._request('GET', this.__getScopedUrl('orgs'), null, cb);
}

/**
* List followers of a user
* @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
* @param {Requestable.callback} [cb] - will receive the list of followers
* @return {Promise} - the promise for the http request
*/
listFollowers(cb) {
return this._request('GET', this.__getScopedUrl('followers'), null, cb);
}

/**
* List users followed by another user
* @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
* @param {Requestable.callback} [cb] - will receive the list of who a user is following
* @return {Promise} - the promise for the http request
*/
listFollowing(cb) {
return this._request('GET', this.__getScopedUrl('following'), null, cb);
}

/**
* List the user's gists
* @see https://developer.github.com/v3/gists/#list-a-users-gists
Expand Down Expand Up @@ -132,6 +152,23 @@ class User extends Requestable {
return this._requestAllPages(this.__getScopedUrl('starred'), requestOptions, cb);
}

/**
* Gets the list of starred gists for the user
* @see https://developer.github.com/v3/gists/#list-starred-gists
* @param {Object} [options={}] - any options to refine the search
* @param {Requestable.callback} [cb] - will receive the list of gists
* @return {Promise} - the promise for the http request
*/
listStarredGists(options, cb) {
options = options || {};
if (typeof options === 'function') {
cb = options;
options = {};
}
options.since = this._dateToISO(options.since);
return this._request('GET', '/gists/starred', options, cb);
}

/**
* List email addresses for a user
* @see https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "github-api",
"version": "3.1.0",
"version": "3.2.1",
"license": "BSD-3-Clause-Clear",
"description": "A higher-level wrapper around the Github API.",
"main": "dist/components/GitHub.js",
Expand Down Expand Up @@ -52,7 +52,7 @@
"dist/*"
],
"dependencies": {
"axios": "^0.15.2",
"axios": "^0.19.0",
"debug": "^2.2.0",
"js-base64": "^2.1.9",
"utf8": "^2.1.1"
Expand Down
20 changes: 19 additions & 1 deletion test/dist.spec/index.html
Expand Up @@ -12,7 +12,7 @@
<script>mocha.setup('bdd')</script>
<script>
describe('the dist file', function() {
it('should work', function(done) {
it('should load a Gist', function(done) {
var github = new GitHub();
var gist = github.getGist('e265df71e7532f3a4bdd');
gist.read()
Expand All @@ -21,6 +21,24 @@
done();
});
});

it('should render markdown', function(done) {
var shouldBe = '<p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>\n';
var github = new GitHub();
var markdown = github.getMarkdown();
const options = {
text: 'Hello world github/linguist#1 **cool**, and #1!',
};

markdown.render(options)
.then(function({data: html}) {
console.log(html);
if (html !== shouldBe) {
throw new Error(html + ' should be ' + shouldBe)
}
done();
}).catch(done);
});
});
</script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion test/markdown.spec.js
Expand Up @@ -37,7 +37,7 @@ describe('Markdown', function() {
};
markdown.render(options)
.then(function({data: html}) {
expect(html).to.be('<p>Hello world <a href="https://github.com/github/linguist/issues/1" class="issue-link js-issue-link" data-url="https://github.com/github/linguist/issues/1" data-id="1012654" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">github/linguist#1</a> <strong>cool</strong>, and <a href="https://github.com/gollum/gollum/issues/1" class="issue-link js-issue-link" data-url="https://github.com/gollum/gollum/issues/1" data-id="183433" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#1</a>!</p>'); // eslint-disable-line
expect(html).to.be('<p>Hello world <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="1012654" data-permission-text="Issue title is private" data-url="https://github.com/github/linguist/issues/1" data-hovercard-type="issue" data-hovercard-url="/github/linguist/issues/1/hovercard" href="https://github.com/github/linguist/issues/1">github/linguist#1</a> <strong>cool</strong>, and <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="183433" data-permission-text="Issue title is private" data-url="https://github.com/gollum/gollum/issues/1" data-hovercard-type="issue" data-hovercard-url="/gollum/gollum/issues/1/hovercard" href="https://github.com/gollum/gollum/issues/1">gollum#1</a>!</p>'); // eslint-disable-line
done();
}).catch(done);
});
Expand Down
57 changes: 56 additions & 1 deletion test/repository.spec.js
Expand Up @@ -112,6 +112,10 @@ describe('Repository', function() {
remoteRepo.fork(assertSuccessful(done));
});

it('should fork repo to org', function(done) {
remoteRepo.forkToOrg(testUser.ORGANIZATION, assertSuccessful(done));
});

it('should list forks of repo', function(done) {
remoteRepo.listForks(assertSuccessful(done, function(err, forks) {
expect(forks).to.be.an.array();
Expand All @@ -121,6 +125,18 @@ describe('Repository', function() {
});

it('should list commits with no options', function(done) {
remoteRepo.listCommits(assertSuccessful(done, function(err, commits) {
expect(commits).to.be.an.array();
expect(commits.length).to.be.above(0);

expect(commits[0]).to.have.own('commit');
expect(commits[0]).to.have.own('author');

done();
}));
});

it('should list commits with null options', function(done) {
remoteRepo.listCommits(null, assertSuccessful(done, function(err, commits) {
expect(commits).to.be.an.array();
expect(commits.length).to.be.above(0);
Expand Down Expand Up @@ -169,7 +185,7 @@ describe('Repository', function() {

it('should fail when null ref is passed', function(done) {
remoteRepo.getSingleCommit(null, assertFailure(done, function(err) {
expect(err.response.status).to.be(404);
expect(err.response.status).to.be(422);
done();
}));
});
Expand Down Expand Up @@ -600,6 +616,45 @@ describe('Repository', function() {
}));
});

it('should succeed on proper commit', function(done) {
let parentSHA = '';
let treeSHA = '';
remoteRepo.getRef('heads/master').then((ref) => {
parentSHA = ref.data.object.sha;
return remoteRepo.getCommit(parentSHA);
}).then((commit) => {
treeSHA = commit.data.tree.sha;
return remoteRepo.commit(parentSHA, treeSHA, 'is this thing on?');
}).then((commit) => {
expect(commit.data.author).to.have.own('name', 'Mike de Boer');
expect(commit.data.author).to.have.own('email', 'mike@c9.io');
done();
});
});

it('should allow commit to change author', function(done) {
let parentSHA = '';
let treeSHA = '';
remoteRepo.getRef('heads/master').then((ref) => {
parentSHA = ref.data.object.sha;
return remoteRepo.getCommit(parentSHA);
}).then((commit) => {
treeSHA = commit.data.tree.sha;
return remoteRepo.commit(parentSHA, treeSHA, 'Who made this commit?', {
author: {
name: 'Jimothy Halpert',
email: 'jim@dundermifflin.com',
},
});
}).then((commit) => {
expect(commit.data.author).to.have.own('name', 'Jimothy Halpert');
expect(commit.data.author).to.have.own('email', 'jim@dundermifflin.com');
done();
}).catch((err) => {
throw err;
});
});

it('should create a release', function(done) {
const releaseDef = {
name: releaseName,
Expand Down
15 changes: 15 additions & 0 deletions test/user.spec.js
Expand Up @@ -36,6 +36,14 @@ describe('User', function() {
user.listOrgs(assertArray(done));
});

it('should get user followers', function(done) {
user.listFollowers(assertArray(done));
});

it('should get user following list', function(done) {
user.listFollowing(assertArray(done));
});

it('should get user gists', function(done) {
user.listGists(assertArray(done));
});
Expand Down Expand Up @@ -63,6 +71,13 @@ describe('User', function() {
user.listStarredRepos(assertArray(done));
});

it('should show user\'s starred gists', function(done) {
const option = {
since: '2015-01-01T00:00:00Z',
};
user.listStarredGists(option, assertArray(done));
});

describe('following a user', function() {
const userToFollow = 'ingalls';

Expand Down

0 comments on commit 92455bb

Please sign in to comment.