From d6ad07ac92d8cbd8987fd4ab64c527df12f1b94f Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Tue, 18 Jun 2019 12:01:46 -0600 Subject: [PATCH 01/20] Added developer setup instructions. --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index bf021040..362182ab 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,33 @@ npm install github-api [npm-package]: https://www.npmjs.com/package/github-api/ [unpkg]: https://unpkg.com/github-api/ [travis-ci]: https://travis-ci.org/github-tools/github + +## Contributing + +We welcome contributions of all types! This section will guide you through setting up your development environment. + +### Setup + +1. [Install Node](https://nodejs.org/en/) version 8,10 or 11. It can often help to use a Node version switcher such as [NVM](https://github.com/nvm-sh/nvm). +2. Fork this repo to your GitHub account. +3. Clone the fork to your development machine (`git clone https://github.com/{YOUR_USERNAME}/github`). +4. From the root of the cloned repo, run `npm install`. +5. Email jaredrewerts@gmail.com with the subject **GitHub API - Personal Access Token Request** + +A personal access token for our test user, @github-tools-tests, will be generated for you. + +6. Set the environment variable `GHTOOLS_USER` to `github-tools-tests`. + +`export GHTOOLS_USER=github-tools-tests` + +7. Set the environment variable `GHTOOLS_PASSWORD` to the personal access token that was generated for you. + +`export GHTOOLS_PASSWORD={YOUR_PAT}` + +**NOTE** Windows users can use [this guide](http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-windows-command-line-and-registry/) to learn about setting environment variables on Windows. + +### Tests + +The main way we write code for `github-api` is using test-driven development. We use Mocha to run our tests. Given that the bulk of this library is just interacting with GitHub's API, nearly all of our tests are integration tests. + +To run the test suite, run `npm run test`. From 11e74f598638ea8fb4af5967a7b56943aa5d1aa9 Mon Sep 17 00:00:00 2001 From: brandon Date: Mon, 26 Aug 2019 22:29:43 -0400 Subject: [PATCH 02/20] implement getCombinedStatus --- lib/Repository.js | 11 +++++++++++ test/repository.spec.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/Repository.js b/lib/Repository.js index 16733e67..3908775c 100644 --- a/lib/Repository.js +++ b/lib/Repository.js @@ -234,6 +234,17 @@ class Repository extends Requestable { return this._request('GET', `/repos/${this.__fullname}/commits/${sha}/statuses`, null, cb); } + /** + * Get the combined view of commit statuses for a particular sha, branch, or tag + * @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref + * @param {string} sha - the sha, branch, or tag to get the combined status for + * @param {Requestable.callback} cb - will receive the combined status + * @returns {Promise} - the promise for the http request + */ + getCombinedStatus(sha, cb) { + return this._request('GET', `/repos/${this.__fullname}/commits/${sha}/status`, null, cb); + } + /** * Get a description of a git tree * @see https://developer.github.com/v3/git/trees/#get-a-tree diff --git a/test/repository.spec.js b/test/repository.spec.js index e248faca..3de25bef 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -255,6 +255,17 @@ describe('Repository', function() { })); }); + it('should get combined view of commit statuses for a SHA from a repo', function(done) { + remoteRepo.getCombinedStatus(v10SHA, assertSuccessful(done, function(err, combinedStatusesView) { + expect(combinedStatusesView.sha).to.equal(v10SHA); + expect(combinedStatusesView.state).to.equal('success'); + expect(combinedStatusesView.statuses[0].context).to.equal('continuous-integration/travis-ci/push'); + expect(combinedStatusesView.total_count).to.equal(1); + + done(); + })); + }); + it('should get a SHA from a repo', function(done) { remoteRepo.getSha('master', '.gitignore', assertSuccessful(done)); }); From 295a16da04b42c1fda872ca4609ec31e5152492a Mon Sep 17 00:00:00 2001 From: brandon feldkamp Date: Wed, 28 Aug 2019 20:33:51 -0400 Subject: [PATCH 03/20] update editLabel test Signed-off-by: brandon feldkamp --- test/issue.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/issue.spec.js b/test/issue.spec.js index 3a407811..7e9af51e 100644 --- a/test/issue.spec.js +++ b/test/issue.spec.js @@ -241,6 +241,7 @@ describe('Issue', function() { it('should update a label', (done) => { let label = { color: '789abc', + name: createdLabel }; expect(createdLabel).to.be.a.string(); From 3bb02d6d48d9617e2aa9e2cf6a15f9dd6301f6bb Mon Sep 17 00:00:00 2001 From: j-rewerts Date: Sat, 31 Aug 2019 23:09:35 -0600 Subject: [PATCH 04/20] Fixed lint. --- test/issue.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/issue.spec.js b/test/issue.spec.js index 7e9af51e..274ca793 100644 --- a/test/issue.spec.js +++ b/test/issue.spec.js @@ -241,7 +241,7 @@ describe('Issue', function() { it('should update a label', (done) => { let label = { color: '789abc', - name: createdLabel + name: createdLabel, }; expect(createdLabel).to.be.a.string(); From 4fccb1011d57268b885f2c8e024d2afac95d81f6 Mon Sep 17 00:00:00 2001 From: j-rewerts Date: Sun, 1 Sep 2019 10:21:11 -0600 Subject: [PATCH 05/20] Updated version to 3.3.0. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eeaf092a..b3c78db3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-api", - "version": "3.2.3", + "version": "3.3.0", "license": "BSD-3-Clause-Clear", "description": "A higher-level wrapper around the Github API.", "main": "dist/components/GitHub.js", From 172979f5f9fe270a010e72c0e70d873227c556e4 Mon Sep 17 00:00:00 2001 From: Andrii Trybynenko Date: Sun, 1 Sep 2019 20:37:42 +0200 Subject: [PATCH 06/20] RegExp Fix for _requestAllPages '&' RegExp Fix for _requestAllPages --- lib/Requestable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Requestable.js b/lib/Requestable.js index beec9e13..b0852e7a 100644 --- a/lib/Requestable.js +++ b/lib/Requestable.js @@ -261,7 +261,7 @@ class Requestable { options = {}; } options.page = parseInt( - nextUrl.match(/(page=[0-9]*)/g) + nextUrl.match(/(&page=[0-9]*)/g) .shift() .split('=') .pop() From e807fc36c0bc2132e7d27e41ed392cba4c5e189f Mon Sep 17 00:00:00 2001 From: Andrii Trybynenko Date: Mon, 2 Sep 2019 13:43:36 +0200 Subject: [PATCH 07/20] regexp compatible with both: ?page=, &page= regexp compatible with both: ?page=, &page= --- lib/Requestable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Requestable.js b/lib/Requestable.js index b0852e7a..4d6e8d9d 100644 --- a/lib/Requestable.js +++ b/lib/Requestable.js @@ -261,7 +261,7 @@ class Requestable { options = {}; } options.page = parseInt( - nextUrl.match(/(&page=[0-9]*)/g) + nextUrl.match(/([&\?]page=[0-9]*)/g) .shift() .split('=') .pop() From eb2b4f311c2d5f876bcc669c2b78092847e9f9b7 Mon Sep 17 00:00:00 2001 From: Mahmudul Hazra Date: Thu, 19 Sep 2019 21:30:55 +0200 Subject: [PATCH 08/20] fix(repository): prevents lib from crashing when not providing optional arguments --- lib/Repository.js | 1 + test/repository.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Repository.js b/lib/Repository.js index 3908775c..daf9443f 100644 --- a/lib/Repository.js +++ b/lib/Repository.js @@ -749,6 +749,7 @@ class Repository extends Requestable { * @return {Promise} - the promise for the http request */ writeFile(branch, path, content, message, options, cb) { + options = options || {}; if (typeof options === 'function') { cb = options; options = {}; diff --git a/test/repository.spec.js b/test/repository.spec.js index 3de25bef..5885916f 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -385,6 +385,17 @@ describe('Repository', function() { })); }); + it('should successfully write to repo when not providing optional options argument', function(done) { + remoteRepo.writeFile('master', fileName, initialText, initialMessage, undefined, assertSuccessful(done, function() { + 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() { wait()().then(() => remoteRepo.move('master', fileName, 'new_name', assertSuccessful(done, function() { From a8b9f620c97916acf0d1ca787104614df5cdb85f Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Tue, 8 Oct 2019 22:23:00 +0900 Subject: [PATCH 09/20] Fixed test user name. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 362182ab..5e5f527f 100644 --- a/README.md +++ b/README.md @@ -107,11 +107,11 @@ We welcome contributions of all types! This section will guide you through setti 4. From the root of the cloned repo, run `npm install`. 5. Email jaredrewerts@gmail.com with the subject **GitHub API - Personal Access Token Request** -A personal access token for our test user, @github-tools-tests, will be generated for you. +A personal access token for our test user, @github-tools-test, will be generated for you. -6. Set the environment variable `GHTOOLS_USER` to `github-tools-tests`. +6. Set the environment variable `GHTOOLS_USER` to `github-tools-test`. -`export GHTOOLS_USER=github-tools-tests` +`export GHTOOLS_USER=github-tools-test` 7. Set the environment variable `GHTOOLS_PASSWORD` to the personal access token that was generated for you. From 0234b39555e25065e4db1847d2ebd29731740590 Mon Sep 17 00:00:00 2001 From: Mahmudul Hazra Date: Sat, 19 Oct 2019 17:11:22 +0200 Subject: [PATCH 10/20] test(repository): updates test to use promise instead of callback --- test/repository.spec.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/repository.spec.js b/test/repository.spec.js index 5885916f..7102874b 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -386,14 +386,13 @@ describe('Repository', function() { }); it('should successfully write to repo when not providing optional options argument', function(done) { - remoteRepo.writeFile('master', fileName, initialText, initialMessage, undefined, assertSuccessful(done, function() { - wait()().then(() => remoteRepo.getContents('master', fileName, 'raw', - assertSuccessful(done, function(err, fileText) { - expect(fileText).to.be(initialText); + const promise = remoteRepo.writeFile('master', fileName, initialText, initialMessage); + promise.then(() => remoteRepo.getContents('master', fileName, 'raw', + assertSuccessful(done, function(err, fileText) { + expect(fileText).to.be(initialText); - done(); - }))); - })); + done(); + }))) }); it('should rename files', function(done) { From bc3619437ed5ff10ecffa8c836d2f1ca2ad5de68 Mon Sep 17 00:00:00 2001 From: Mahmudul Hazra Date: Mon, 4 Nov 2019 21:10:30 +0100 Subject: [PATCH 11/20] test(repository): fixes linting errors --- test/repository.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/repository.spec.js b/test/repository.spec.js index 7102874b..4cd46a76 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -392,7 +392,7 @@ describe('Repository', function() { expect(fileText).to.be(initialText); done(); - }))) + }))); }); it('should rename files', function(done) { From 95fb236fb18d03eee6e8e7abb0a291c3f20dc5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Cala=C3=A7a?= Date: Wed, 6 Nov 2019 18:51:13 -0300 Subject: [PATCH 12/20] improve(repository): add list commits on pull request function --- lib/Repository.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Repository.js b/lib/Repository.js index daf9443f..74452dde 100644 --- a/lib/Repository.js +++ b/lib/Repository.js @@ -198,6 +198,23 @@ class Repository extends Requestable { return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb); } + /** + * List the commits on a pull request + * @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository + * @param {number|string} number - the number of the pull request to list the commits + * @param {Object} [options] - the filtering options for commits + * @param {Requestable.callback} [cb] - will receive the commits information + * @return {Promise} - the promise for the http request + */ + listCommitsOnPR(number, options, cb) { + options = options || {}; + if (typeof options === 'function') { + cb = options; + options = {}; + } + return this._request('GET', `/repos/${this.__fullname}/pulls/${number}/commits`, options, cb); + } + /** * Gets a single commit information for a repository * @see https://developer.github.com/v3/repos/commits/#get-a-single-commit From ba74ee2196a48d619241691b27630b9d32bc8b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Cala=C3=A7a?= Date: Wed, 6 Nov 2019 18:52:15 -0300 Subject: [PATCH 13/20] test(repository): add specs to test the new listCommitsOnPR function --- test/repository.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/repository.spec.js b/test/repository.spec.js index 7102874b..2d71b04f 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -173,6 +173,24 @@ describe('Repository', function() { })); }); + it('should list commits on a PR with no options', function(done) { + const PR_NUMBER = 588; + remoteRepo.listCommitsOnPR(PR_NUMBER, assertSuccessful(done, function(err, commits) { + expect(commits).to.be.an.array(); + expect(commits.length).to.be.equal(2); + + let message1 = 'fix(repository): prevents lib from crashing when not providing optional arguments'; + expect(commits[0].author).to.have.own('login', 'hazmah0'); + expect(commits[0].commit).to.have.own('message', message1); + + let message2 = 'test(repository): updates test to use promise instead of callback'; + expect(commits[1].author).to.have.own('login', 'hazmah0'); + expect(commits[1].commit).to.have.own('message', message2); + + done(); + })); + }); + it('should get the latest commit from master', function(done) { remoteRepo.getSingleCommit('master', assertSuccessful(done, function(err, commit) { expect(commit).to.have.own('sha'); From 3b4b7b02a2308ce8106c2f92667c092602c66c79 Mon Sep 17 00:00:00 2001 From: Jivthesh M R Date: Thu, 6 Aug 2020 23:23:37 +0530 Subject: [PATCH 14/20] added code of conduct --- CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..09827eb1 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at . All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq From dfe3df43593d6a2378fd57e789129ff35c798aa1 Mon Sep 17 00:00:00 2001 From: Nick Lynch Date: Fri, 22 Jan 2021 11:35:26 +0000 Subject: [PATCH 15/20] chore: update axios due to CVE There's a CVE for axios < 0.21.1. See https://github.com/advisories/GHSA-4w2v-q235-vp99 Closes #633 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3c78db3..42b1c81f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "dist/*" ], "dependencies": { - "axios": "^0.19.0", + "axios": "^0.21.1", "debug": "^2.2.0", "js-base64": "^2.1.9", "utf8": "^2.1.1" From b11839534abe38b1c5b84afa46f2fa9f91d2b28f Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Sun, 24 Jan 2021 16:30:23 -0800 Subject: [PATCH 16/20] Fixed auth message. --- test/auth.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/auth.spec.js b/test/auth.spec.js index d1aea684..00842ee9 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -84,7 +84,7 @@ describe('Github', function() { it('should fail authentication and return err', function(done) { user.listNotifications(assertFailure(done, function(err) { expect(err.response.status).to.be.equal(401, 'Return 401 status for bad auth'); - expect(err.response.data.message).to.equal('Bad credentials'); + expect(err.response.data.message).to.equal('Requires authentication'); done(); })); From 606bcc8791b55b5132b7e919739efa29c809bd63 Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Sun, 24 Jan 2021 16:54:15 -0800 Subject: [PATCH 17/20] Update markdown response. --- test/markdown.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/markdown.spec.js b/test/markdown.spec.js index bd9e7c37..909581fa 100644 --- a/test/markdown.spec.js +++ b/test/markdown.spec.js @@ -37,7 +37,7 @@ describe('Markdown', function() { }; markdown.render(options) .then(function({data: html}) { - expect(html).to.be('

Hello world github/linguist#1 cool, and gollum#1!

'); // eslint-disable-line + expect(html).to.be('

Hello world github/linguist#1 cool, and gollum#1!

'); // eslint-disable-line done(); }).catch(done); }); From c8ab54b8c737ae0a1af63f45757d5147c8f54ee2 Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Sun, 24 Jan 2021 17:50:00 -0800 Subject: [PATCH 18/20] 3.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 42b1c81f..8e54341a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-api", - "version": "3.3.0", + "version": "3.4.0", "license": "BSD-3-Clause-Clear", "description": "A higher-level wrapper around the Github API.", "main": "dist/components/GitHub.js", From 935488e16eb7ea26f2ed9c3ccd8b911318f7553d Mon Sep 17 00:00:00 2001 From: luisborit Date: Tue, 26 Jan 2021 01:38:19 -0500 Subject: [PATCH 19/20] corrected link --- lib/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/User.js b/lib/User.js index d6470324..64d377fd 100644 --- a/lib/User.js +++ b/lib/User.js @@ -93,7 +93,7 @@ class User extends Requestable { /** * List users followed by another user - * @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user + * @see https://docs.github.com/en/rest/reference/users#list-the-people-the-authenticated-user-follows * @param {Requestable.callback} [cb] - will receive the list of who a user is following * @return {Promise} - the promise for the http request */ From ac6cd1f69e4770ced303c4a9723239f3266cca57 Mon Sep 17 00:00:00 2001 From: luisborit Date: Thu, 4 Feb 2021 23:48:09 -0500 Subject: [PATCH 20/20] comment edited --- lib/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/User.js b/lib/User.js index 64d377fd..a6f22324 100644 --- a/lib/User.js +++ b/lib/User.js @@ -92,7 +92,7 @@ class User extends Requestable { } /** - * List users followed by another user + * Lists the people who the authenticated user follows. * @see https://docs.github.com/en/rest/reference/users#list-the-people-the-authenticated-user-follows * @param {Requestable.callback} [cb] - will receive the list of who a user is following * @return {Promise} - the promise for the http request