Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests, update dependencies and Project API #401

Merged
merged 42 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a8ae05f
add getContributorStats
mathieudutour Nov 18, 2016
f5e6fa3
add labels methods
mathieudutour Nov 18, 2016
26fa048
add updateStatus and updateRepository method
mathieudutour Nov 18, 2016
7c1684e
nice readme
mathieudutour Nov 18, 2016
a5e3dbb
add project api and fix tests
mathieudutour Nov 18, 2016
cff3973
3.0.0
mathieudutour Nov 18, 2016
4f46d10
improve release script
mathieudutour Nov 18, 2016
83292fd
3.0.1
mathieudutour Nov 18, 2016
332456b
remove prepublish script
mathieudutour Nov 18, 2016
8b8c4fd
request all pages for cards
mathieudutour Nov 18, 2016
0505bb3
3.0.2
mathieudutour Nov 18, 2016
68ef1f6
add getEmails
mathieudutour Nov 18, 2016
cda2c42
3.1.0
mathieudutour Nov 18, 2016
99c1aeb
remove polyfill
mathieudutour Nov 18, 2016
0c5546f
3.1.1
mathieudutour Nov 18, 2016
be44fd1
drop support for node < 4
mathieudutour Nov 18, 2016
c12ad57
do not hardcode project preview in requestable
mathieudutour Nov 18, 2016
308aced
3.2.0
mathieudutour Nov 18, 2016
3ec2837
test on node6 only
mathieudutour Nov 18, 2016
21e50ec
add coverage
mathieudutour Nov 18, 2016
2a0bdf2
fix lint
mathieudutour Nov 18, 2016
ee8af3f
fix travis.yml
mathieudutour Nov 18, 2016
5418512
fix tests
mathieudutour Nov 18, 2016
71a6326
fix scope
mathieudutour Nov 18, 2016
5dd868f
add tests for project
mathieudutour Nov 18, 2016
077736b
add some timeout to settle
mathieudutour Nov 18, 2016
55db033
fix _request204or404
mathieudutour Nov 18, 2016
068476d
remove clearRepo
mathieudutour Nov 18, 2016
97ac33f
fix typo
mathieudutour Nov 18, 2016
1605b89
remove unnesserary setTimeout
mathieudutour Nov 18, 2016
a80922c
fix conflicts
mathieudutour Nov 21, 2016
121066c
fix callbackErrorOrThrow
mathieudutour Nov 21, 2016
9877d9e
add some delay
mathieudutour Nov 21, 2016
45a6ef3
add some delay
mathieudutour Nov 21, 2016
fe146a5
add more delay
mathieudutour Nov 21, 2016
c9de004
test on node 4 and 5
mathieudutour Nov 21, 2016
e1ae825
add more waiting
mathieudutour Nov 21, 2016
fd5d57b
fix concurrency issues
mathieudutour Nov 21, 2016
39dc920
delete created org project
mathieudutour Nov 21, 2016
ac41f60
fix typo
mathieudutour Nov 21, 2016
e0bbf7e
wait more
mathieudutour Nov 21, 2016
f998a39
fix typo
mathieudutour Nov 21, 2016
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
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much longer is node4 supported? Maybe we don't drop support for node4 just yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not dropping the support for node4, just node 0.12 and earlier. I removed it from the test cause there were some issues with running the test 3 times in parallel. But maybe we should test on node4 only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- '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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the thought behind removing all this documentation? Are you proposing we drop the link to the generated Docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not removed, it's rearranged to fit https://github.com/noffle/art-of-readme

import GitHub from 'github-api';
var GitHub = require('github-api');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why downgrade from ECMA2015?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, because for people who are not using babel/ES6, it's an additional cognitive load which can be avoided. For people using ES6, I'm quite sure they know how to use const instead of var.
But again, no strong feeling and happy to roll back if you prefer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My opinion is that ECMA2015 is spec now, so there's no need to downgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but var is not deprecated in anyway, so if we can help people understand the repo, I think it's best, regardless of wether it's matching style guide or not, don't you think? (see #392)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was, and hope is, that we can have at least one example of each of: require vs import and then vs cb to give people the full flavor of the API.

That being said I think that perhaps that means most of our examples are import + then with an example included toward the end of require + cb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a solution. Feel free to commit on directly here


// basic auth
const gh = new GitHub({
var gh = new GitHub({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again downgrading from ECMA2015?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another downgrade from ECMA2015, I'll stop mentioning all the ones I see now.

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