Skip to content

Commit

Permalink
chore: fix tests and bump to 3.x (#401)
Browse files Browse the repository at this point in the history
* add getContributorStats
* add labels methods
* add updateStatus and updateRepository method
* add project api and fix tests
* improve release script
* remove prepublish script
* request all pages for cards
* add getEmails
* remove polyfill
* drop support for node < 4 / test on node 4-6
* add coverage
* remove clearRepo
  • Loading branch information
mathieudutour authored and clayreimann committed Nov 30, 2016
1 parent 78a98b1 commit 6ec1d0b
Show file tree
Hide file tree
Showing 29 changed files with 1,079 additions and 237 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ docs/
dist/
coverage/
node_modules/

.nyc_output/
/out/
.DS_Store
npm-debug.log
sauce.json
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
docs/
coverage/
node_modules/

lib/
.nyc_output/
.DS_Store
sauce.json
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ node_js:
- '6'
- '5'
- '4'
- '0.12'


cache:
directories:
- node_modules
Expand All @@ -14,10 +13,10 @@ before_script:
- npm run lint
# - npm run build # will need this when we do sauce testing of compiled files
script:
- npm test
- npm run test-coverage
# - npm run test-dist # test the compiled files
# after_success:
# - npm run codecov # disabled temporarialy while I work out how to generate accurate coverage of ES2015 code
after_success:
- npm run codecov
before_deploy:
- npm run build
deploy:
Expand Down
116 changes: 47 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,19 @@

[![Downloads per month](https://img.shields.io/npm/dm/github-api.svg?maxAge=2592000)][npm-package]
[![Latest version](https://img.shields.io/npm/v/github-api.svg?maxAge=3600)][npm-package]
[![Gitter](https://img.shields.io/gitter/room/michael/github.js.svg?maxAge=2592000)][gitter]
[![Travis](https://img.shields.io/travis/michael/github.svg?maxAge=60)][travis-ci]
<!-- [![Codecov](https://img.shields.io/codecov/c/github/michael/github.svg?maxAge=2592000)][codecov] -->
[![Gitter](https://img.shields.io/gitter/room/github-tools/github.js.svg?maxAge=2592000)][gitter]
[![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. It was concieved in the context of
[Prose][prose], a content editor for GitHub.
Github.js provides a minimal higher-level wrapper around Github's API.

## [Read the docs][docs]

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

```shell
npm install github-api
```

```html
<!-- just github-api source (5.3kb) -->
<script src="https://unpkg.com/github-api/dist/GitHub.min.js"></script>

<!-- standalone (20.3kb) -->
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script>
```

## Compatibility
Github.js is tested on Node:
* 6.x
* 5.x
* 4.x
* 0.12

## GitHub Tools

The team behind Github.js has created a whole organization, called [GitHub Tools](https://github.com/github-tools),
dedicated to GitHub and its API. In the near future this repository could be moved under the GitHub Tools organization
as well. In the meantime, we recommend you to take a look at other projects of the organization.

## Samples
## Usage

```javascript
/*
Data can be retrieved from the API either using callbacks (as in versions < 1.0)
or using a new promise-based API. For now the promise-based API just returns the
raw HTTP request promise; this might change in the next version.
or using a new promise-based API. The promise-based API returns the raw Axios
request promise.
*/
import GitHub from 'github-api';

Expand All @@ -62,57 +31,66 @@ gist.create({
}
}).then(function({data}) {
// Promises!
let gistJson = data;
gist.read(function(err, gist, xhr) {
// if no error occurred then err == null

// gistJson === httpResponse.data

// xhr === httpResponse
});
let createdGist = data;
return gist.read();
}).then(function({data}) {
let retrievedGist = data;
// do interesting things
});
```

```javascript
import GitHub from 'github-api';
var GitHub = require('github-api');

// basic auth
const gh = new GitHub({
var gh = new GitHub({
username: 'FOO',
password: 'NotFoo'
/* also acceptable:
token: 'MY_OAUTH_TOKEN'
*/
});

const me = gh.getUser();
var me = gh.getUser(); // no user specified defaults to the user for whom credentials were provided
me.listNotifications(function(err, notifications) {
// do some stuff
});

const clayreimann = gh.getUser('clayreimann');
clayreimann.listStarredRepos()
.then(function({data: reposJson}) {
// do stuff with reposJson
});
var clayreimann = gh.getUser('clayreimann');
clayreimann.listStarredRepos(function(err, repos) {
// look at all the starred repos!
});
```

```javascript
var GitHub = require('github-api');
## API Documentation

// token auth
var gh = new GitHub({
token: 'MY_OAUTH_TOKEN'
});
[API documentation][docs] is hosted on github pages, and is generated from JSDoc; any contributions
should include updated JSDoc.

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

var yahoo = gh.getOrganization('yahoo');
yahoo.listRepos(function(err, repos) {
// look at all the repos!
})
```shell
npm install github-api
```

[codecov]: https://codecov.io/github/michael/github?branch=master
```html
<!-- just github-api source (5.3kb) -->
<script src="https://unpkg.com/github-api/dist/GitHub.min.js"></script>

<!-- standalone (20.3kb) -->
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script>
```

## 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.

[codecov]: https://codecov.io/github/github-tools/github?branch=master
[docs]: http://github-tools.github.io/github/
[gitter]: https://gitter.im/michael/github
[gitter]: https://gitter.im/github-tools/github
[npm-package]: https://www.npmjs.com/package/github-api/
[unpkg]: https://unpkg.com/github-api/
[prose]: http://prose.io
[travis-ci]: https://travis-ci.org/michael/github
[xhr-link]: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
[travis-ci]: https://travis-ci.org/github-tools/github
12 changes: 6 additions & 6 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import uglify from 'gulp-uglify';
const ALL_SOURCES = [
'*.js',
'lib/*.js',
'test/*.js'
'test/*.js',
];

gulp.task('lint', function() {
Expand All @@ -33,13 +33,13 @@ gulp.task('build', [
'build:external:min',
'build:bundled:debug',
'build:external:debug',
'build:components'
'build:components',
]);

const bundledConfig = {
debug: true,
entries: 'lib/GitHub.js',
standalone: 'GitHub'
standalone: 'GitHub',
};
const externalConfig = {
debug: true,
Expand All @@ -50,9 +50,9 @@ const externalConfig = {
'js-base64',
'es6-promise',
'debug',
'utf8'
'utf8',
],
bundleExternal: false
bundleExternal: false,
};
gulp.task('build:bundled:min', function() {
return buildBundle(bundledConfig, '.bundle.min.js', true);
Expand Down Expand Up @@ -82,7 +82,7 @@ function buildBundle(options, extname, minify) {
.pipe(source('GitHub.js'))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
loadMaps: true,
}));

if (minify) {
Expand Down
10 changes: 10 additions & 0 deletions lib/GitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Repository from './Repository';
import Organization from './Organization';
import Team from './Team';
import Markdown from './Markdown';
import Project from './Project';

/**
* GitHub encapsulates the functionality to create various API wrapper objects.
Expand Down Expand Up @@ -113,6 +114,15 @@ class GitHub {
return new Markdown(this.__auth, this.__apiBase);
}

/**
* Create a new Project wrapper
* @param {string} id - the id of the project
* @return {Markdown}
*/
getProject(id) {
return new Project(id, this.__auth, this.__apiBase);
}

/**
* Computes the full repository name
* @param {string} user - the username (or the full name)
Expand Down
53 changes: 49 additions & 4 deletions lib/Issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Issue extends Requestable {
* Get a milestone
* @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
* @param {string} milestone - the id of the milestone to fetch
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the milestone
* @return {Promise} - the promise for the http request
*/
getMilestone(milestone, cb) {
Expand All @@ -161,7 +161,7 @@ class Issue extends Requestable {
* Create a new milestone
* @see https://developer.github.com/v3/issues/milestones/#create-a-milestone
* @param {Object} milestoneData - the milestone definition
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the milestone
* @return {Promise} - the promise for the http request
*/
createMilestone(milestoneData, cb) {
Expand All @@ -173,7 +173,7 @@ class Issue extends Requestable {
* @see https://developer.github.com/v3/issues/milestones/#update-a-milestone
* @param {string} milestone - the id of the milestone to edit
* @param {Object} milestoneData - the updates to make to the milestone
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the updated milestone
* @return {Promise} - the promise for the http request
*/
editMilestone(milestone, milestoneData, cb) {
Expand All @@ -184,7 +184,7 @@ class Issue extends Requestable {
* Delete a milestone (this is distinct from closing a milestone)
* @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone
* @param {string} milestone - the id of the milestone to delete
* @param {Requestable.callback} [cb] - will receive the array of milestones
* @param {Requestable.callback} [cb] - will receive the status
* @return {Promise} - the promise for the http request
*/
deleteMilestone(milestone, cb) {
Expand All @@ -201,6 +201,51 @@ class Issue extends Requestable {
createLabel(labelData, cb) {
return this._request('POST', `/repos/${this.__repository}/labels`, labelData, cb);
}

/**
* List the labels for the repository
* @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
* @param {Object} options - filtering options
* @param {Requestable.callback} [cb] - will receive the array of labels
* @return {Promise} - the promise for the http request
*/
listLabels(options, cb) {
return this._request('GET', `/repos/${this.__repository}/labels`, options, cb);
}

/**
* Get a label
* @see https://developer.github.com/v3/issues/labels/#get-a-single-label
* @param {string} label - the name of the label to fetch
* @param {Requestable.callback} [cb] - will receive the label
* @return {Promise} - the promise for the http request
*/
getLabel(label, cb) {
return this._request('GET', `/repos/${this.__repository}/labels/${label}`, null, cb);
}

/**
* Edit a label
* @see https://developer.github.com/v3/issues/labels/#update-a-label
* @param {string} label - the name of the label to edit
* @param {Object} labelData - the updates to make to the label
* @param {Requestable.callback} [cb] - will receive the updated label
* @return {Promise} - the promise for the http request
*/
editLabel(label, labelData, cb) {
return this._request('PATCH', `/repos/${this.__repository}/labels/${label}`, labelData, cb);
}

/**
* Delete a label
* @see https://developer.github.com/v3/issues/labels/#delete-a-label
* @param {string} label - the name of the label to delete
* @param {Requestable.callback} [cb] - will receive the status
* @return {Promise} - the promise for the http request
*/
deleteLabel(label, cb) {
return this._request('DELETE', `/repos/${this.__repository}/labels/${label}`, null, cb);
}
}

module.exports = Issue;
4 changes: 2 additions & 2 deletions lib/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Requestable from './Requestable';

/**
* RateLimit allows users to query their rate-limit status
* Renders html from Markdown text
*/
class Markdown extends Requestable {
/**
* construct a RateLimit
* construct a Markdown
* @param {Requestable.auth} auth - the credentials to authenticate to GitHub
* @param {string} [apiBase] - the base Github API URL
* @return {Promise} - the promise for the http request
Expand Down
Loading

0 comments on commit 6ec1d0b

Please sign in to comment.