Skip to content

Commit 6ec1d0b

Browse files
mathieudutourclayreimann
authored andcommitted
chore: fix tests and bump to 3.x (#401)
* 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
1 parent 78a98b1 commit 6ec1d0b

29 files changed

+1079
-237
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ docs/
44
dist/
55
coverage/
66
node_modules/
7-
7+
.nyc_output/
8+
/out/
89
.DS_Store
910
npm-debug.log
1011
sauce.json

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
docs/
22
coverage/
33
node_modules/
4-
4+
lib/
5+
.nyc_output/
56
.DS_Store
67
sauce.json

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ node_js:
44
- '6'
55
- '5'
66
- '4'
7-
- '0.12'
8-
7+
98
cache:
109
directories:
1110
- node_modules
@@ -14,10 +13,10 @@ before_script:
1413
- npm run lint
1514
# - npm run build # will need this when we do sauce testing of compiled files
1615
script:
17-
- npm test
16+
- npm run test-coverage
1817
# - npm run test-dist # test the compiled files
19-
# after_success:
20-
# - npm run codecov # disabled temporarialy while I work out how to generate accurate coverage of ES2015 code
18+
after_success:
19+
- npm run codecov
2120
before_deploy:
2221
- npm run build
2322
deploy:

README.md

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,19 @@
22

33
[![Downloads per month](https://img.shields.io/npm/dm/github-api.svg?maxAge=2592000)][npm-package]
44
[![Latest version](https://img.shields.io/npm/v/github-api.svg?maxAge=3600)][npm-package]
5-
[![Gitter](https://img.shields.io/gitter/room/michael/github.js.svg?maxAge=2592000)][gitter]
6-
[![Travis](https://img.shields.io/travis/michael/github.svg?maxAge=60)][travis-ci]
7-
<!-- [![Codecov](https://img.shields.io/codecov/c/github/michael/github.svg?maxAge=2592000)][codecov] -->
5+
[![Gitter](https://img.shields.io/gitter/room/github-tools/github.js.svg?maxAge=2592000)][gitter]
6+
[![Travis](https://img.shields.io/travis/github-tools/github.svg?maxAge=60)][travis-ci]
7+
[![Codecov](https://img.shields.io/codecov/c/github/github-tools/github.svg?maxAge=2592000)][codecov]
88

9-
Github.js provides a minimal higher-level wrapper around Github's API. It was concieved in the context of
10-
[Prose][prose], a content editor for GitHub.
9+
Github.js provides a minimal higher-level wrapper around Github's API.
1110

12-
## [Read the docs][docs]
13-
14-
## Installation
15-
Github.js is available from `npm` or [unpkg][unpkg].
16-
17-
```shell
18-
npm install github-api
19-
```
20-
21-
```html
22-
<!-- just github-api source (5.3kb) -->
23-
<script src="https://unpkg.com/github-api/dist/GitHub.min.js"></script>
24-
25-
<!-- standalone (20.3kb) -->
26-
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script>
27-
```
28-
29-
## Compatibility
30-
Github.js is tested on Node:
31-
* 6.x
32-
* 5.x
33-
* 4.x
34-
* 0.12
35-
36-
## GitHub Tools
37-
38-
The team behind Github.js has created a whole organization, called [GitHub Tools](https://github.com/github-tools),
39-
dedicated to GitHub and its API. In the near future this repository could be moved under the GitHub Tools organization
40-
as well. In the meantime, we recommend you to take a look at other projects of the organization.
41-
42-
## Samples
11+
## Usage
4312

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

@@ -62,57 +31,66 @@ gist.create({
6231
}
6332
}).then(function({data}) {
6433
// Promises!
65-
let gistJson = data;
66-
gist.read(function(err, gist, xhr) {
67-
// if no error occurred then err == null
68-
69-
// gistJson === httpResponse.data
70-
71-
// xhr === httpResponse
72-
});
34+
let createdGist = data;
35+
return gist.read();
36+
}).then(function({data}) {
37+
let retrievedGist = data;
38+
// do interesting things
7339
});
7440
```
7541

7642
```javascript
77-
import GitHub from 'github-api';
43+
var GitHub = require('github-api');
7844

7945
// basic auth
80-
const gh = new GitHub({
46+
var gh = new GitHub({
8147
username: 'FOO',
8248
password: 'NotFoo'
49+
/* also acceptable:
50+
token: 'MY_OAUTH_TOKEN'
51+
*/
8352
});
8453

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

90-
const clayreimann = gh.getUser('clayreimann');
91-
clayreimann.listStarredRepos()
92-
.then(function({data: reposJson}) {
93-
// do stuff with reposJson
94-
});
59+
var clayreimann = gh.getUser('clayreimann');
60+
clayreimann.listStarredRepos(function(err, repos) {
61+
// look at all the starred repos!
62+
});
9563
```
9664

97-
```javascript
98-
var GitHub = require('github-api');
65+
## API Documentation
9966

100-
// token auth
101-
var gh = new GitHub({
102-
token: 'MY_OAUTH_TOKEN'
103-
});
67+
[API documentation][docs] is hosted on github pages, and is generated from JSDoc; any contributions
68+
should include updated JSDoc.
69+
70+
## Installation
71+
Github.js is available from `npm` or [unpkg][unpkg].
10472

105-
var yahoo = gh.getOrganization('yahoo');
106-
yahoo.listRepos(function(err, repos) {
107-
// look at all the repos!
108-
})
73+
```shell
74+
npm install github-api
10975
```
11076

111-
[codecov]: https://codecov.io/github/michael/github?branch=master
77+
```html
78+
<!-- just github-api source (5.3kb) -->
79+
<script src="https://unpkg.com/github-api/dist/GitHub.min.js"></script>
80+
81+
<!-- standalone (20.3kb) -->
82+
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script>
83+
```
84+
85+
## Compatibility
86+
`Github.js` is tested on Node.js:
87+
* 6.x
88+
89+
Note: `Github.js` uses Promise, hence it will not work in Node.js < 4 without polyfill.
90+
91+
[codecov]: https://codecov.io/github/github-tools/github?branch=master
11292
[docs]: http://github-tools.github.io/github/
113-
[gitter]: https://gitter.im/michael/github
93+
[gitter]: https://gitter.im/github-tools/github
11494
[npm-package]: https://www.npmjs.com/package/github-api/
11595
[unpkg]: https://unpkg.com/github-api/
116-
[prose]: http://prose.io
117-
[travis-ci]: https://travis-ci.org/michael/github
118-
[xhr-link]: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
96+
[travis-ci]: https://travis-ci.org/github-tools/github

gulpfile.babel.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import uglify from 'gulp-uglify';
1313
const ALL_SOURCES = [
1414
'*.js',
1515
'lib/*.js',
16-
'test/*.js'
16+
'test/*.js',
1717
];
1818

1919
gulp.task('lint', function() {
@@ -33,13 +33,13 @@ gulp.task('build', [
3333
'build:external:min',
3434
'build:bundled:debug',
3535
'build:external:debug',
36-
'build:components'
36+
'build:components',
3737
]);
3838

3939
const bundledConfig = {
4040
debug: true,
4141
entries: 'lib/GitHub.js',
42-
standalone: 'GitHub'
42+
standalone: 'GitHub',
4343
};
4444
const externalConfig = {
4545
debug: true,
@@ -50,9 +50,9 @@ const externalConfig = {
5050
'js-base64',
5151
'es6-promise',
5252
'debug',
53-
'utf8'
53+
'utf8',
5454
],
55-
bundleExternal: false
55+
bundleExternal: false,
5656
};
5757
gulp.task('build:bundled:min', function() {
5858
return buildBundle(bundledConfig, '.bundle.min.js', true);
@@ -82,7 +82,7 @@ function buildBundle(options, extname, minify) {
8282
.pipe(source('GitHub.js'))
8383
.pipe(buffer())
8484
.pipe(sourcemaps.init({
85-
loadMaps: true
85+
loadMaps: true,
8686
}));
8787

8888
if (minify) {

lib/GitHub.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Repository from './Repository';
1515
import Organization from './Organization';
1616
import Team from './Team';
1717
import Markdown from './Markdown';
18+
import Project from './Project';
1819

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

117+
/**
118+
* Create a new Project wrapper
119+
* @param {string} id - the id of the project
120+
* @return {Markdown}
121+
*/
122+
getProject(id) {
123+
return new Project(id, this.__auth, this.__apiBase);
124+
}
125+
116126
/**
117127
* Computes the full repository name
118128
* @param {string} user - the username (or the full name)

lib/Issue.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Issue extends Requestable {
150150
* Get a milestone
151151
* @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
152152
* @param {string} milestone - the id of the milestone to fetch
153-
* @param {Requestable.callback} [cb] - will receive the array of milestones
153+
* @param {Requestable.callback} [cb] - will receive the milestone
154154
* @return {Promise} - the promise for the http request
155155
*/
156156
getMilestone(milestone, cb) {
@@ -161,7 +161,7 @@ class Issue extends Requestable {
161161
* Create a new milestone
162162
* @see https://developer.github.com/v3/issues/milestones/#create-a-milestone
163163
* @param {Object} milestoneData - the milestone definition
164-
* @param {Requestable.callback} [cb] - will receive the array of milestones
164+
* @param {Requestable.callback} [cb] - will receive the milestone
165165
* @return {Promise} - the promise for the http request
166166
*/
167167
createMilestone(milestoneData, cb) {
@@ -173,7 +173,7 @@ class Issue extends Requestable {
173173
* @see https://developer.github.com/v3/issues/milestones/#update-a-milestone
174174
* @param {string} milestone - the id of the milestone to edit
175175
* @param {Object} milestoneData - the updates to make to the milestone
176-
* @param {Requestable.callback} [cb] - will receive the array of milestones
176+
* @param {Requestable.callback} [cb] - will receive the updated milestone
177177
* @return {Promise} - the promise for the http request
178178
*/
179179
editMilestone(milestone, milestoneData, cb) {
@@ -184,7 +184,7 @@ class Issue extends Requestable {
184184
* Delete a milestone (this is distinct from closing a milestone)
185185
* @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone
186186
* @param {string} milestone - the id of the milestone to delete
187-
* @param {Requestable.callback} [cb] - will receive the array of milestones
187+
* @param {Requestable.callback} [cb] - will receive the status
188188
* @return {Promise} - the promise for the http request
189189
*/
190190
deleteMilestone(milestone, cb) {
@@ -201,6 +201,51 @@ class Issue extends Requestable {
201201
createLabel(labelData, cb) {
202202
return this._request('POST', `/repos/${this.__repository}/labels`, labelData, cb);
203203
}
204+
205+
/**
206+
* List the labels for the repository
207+
* @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
208+
* @param {Object} options - filtering options
209+
* @param {Requestable.callback} [cb] - will receive the array of labels
210+
* @return {Promise} - the promise for the http request
211+
*/
212+
listLabels(options, cb) {
213+
return this._request('GET', `/repos/${this.__repository}/labels`, options, cb);
214+
}
215+
216+
/**
217+
* Get a label
218+
* @see https://developer.github.com/v3/issues/labels/#get-a-single-label
219+
* @param {string} label - the name of the label to fetch
220+
* @param {Requestable.callback} [cb] - will receive the label
221+
* @return {Promise} - the promise for the http request
222+
*/
223+
getLabel(label, cb) {
224+
return this._request('GET', `/repos/${this.__repository}/labels/${label}`, null, cb);
225+
}
226+
227+
/**
228+
* Edit a label
229+
* @see https://developer.github.com/v3/issues/labels/#update-a-label
230+
* @param {string} label - the name of the label to edit
231+
* @param {Object} labelData - the updates to make to the label
232+
* @param {Requestable.callback} [cb] - will receive the updated label
233+
* @return {Promise} - the promise for the http request
234+
*/
235+
editLabel(label, labelData, cb) {
236+
return this._request('PATCH', `/repos/${this.__repository}/labels/${label}`, labelData, cb);
237+
}
238+
239+
/**
240+
* Delete a label
241+
* @see https://developer.github.com/v3/issues/labels/#delete-a-label
242+
* @param {string} label - the name of the label to delete
243+
* @param {Requestable.callback} [cb] - will receive the status
244+
* @return {Promise} - the promise for the http request
245+
*/
246+
deleteLabel(label, cb) {
247+
return this._request('DELETE', `/repos/${this.__repository}/labels/${label}`, null, cb);
248+
}
204249
}
205250

206251
module.exports = Issue;

lib/Markdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import Requestable from './Requestable';
99

1010
/**
11-
* RateLimit allows users to query their rate-limit status
11+
* Renders html from Markdown text
1212
*/
1313
class Markdown extends Requestable {
1414
/**
15-
* construct a RateLimit
15+
* construct a Markdown
1616
* @param {Requestable.auth} auth - the credentials to authenticate to GitHub
1717
* @param {string} [apiBase] - the base Github API URL
1818
* @return {Promise} - the promise for the http request

0 commit comments

Comments
 (0)