-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add check command that compares GitHub contributors with credit…
…ed ones (#58) * feat: Add checking functionnality that compares contributors with GH data * fix(check): Use the info from config file, paginate GH data * doc(check): Document the new check command * fix(eslint): Add missing semicolon * tests: Add tests for utils.check * fix: Check for code and test only * refactor: use includes and correct awaits * refactor: more includes and template literals
- Loading branch information
Showing
14 changed files
with
8,405 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
var pify = require('pify'); | ||
var request = pify(require('request')); | ||
|
||
function getNextLink(link) { | ||
if (!link) { | ||
return null; | ||
} | ||
|
||
var nextLink = link.split(',').find(s => s.includes('rel="next"')); | ||
|
||
if (!nextLink) { | ||
return null; | ||
} | ||
|
||
return nextLink.split(';')[0].slice(1, -1); | ||
} | ||
|
||
function getContributorsPage(url) { | ||
return request.get({ | ||
url: url, | ||
headers: { | ||
'User-Agent': 'request' | ||
} | ||
}) | ||
.then(res => { | ||
var body = JSON.parse(res.body); | ||
var contributorsIds = body.map(contributor => contributor.login); | ||
|
||
var nextLink = getNextLink(res.headers.link); | ||
if (nextLink) { | ||
return getContributorsPage(nextLink).then(nextContributors => { | ||
return contributorsIds.concat(nextContributors); | ||
}); | ||
} | ||
|
||
return contributorsIds; | ||
}); | ||
} | ||
|
||
module.exports = function getContributorsFromGithub(owner, name) { | ||
var url = `https://api.github.com/repos/${owner}/${name}/contributors?per_page=100`; | ||
return getContributorsPage(url); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
import test from 'ava'; | ||
import nock from 'nock'; | ||
|
||
var check = require('./check'); | ||
import allContributorsCliResponse from './fixtures/all-contributors.response.json'; | ||
import allContributorsCliTransformed from './fixtures/all-contributors.transformed.json'; | ||
|
||
import reactNativeResponse1 from './fixtures/react-native.response.1.json'; | ||
import reactNativeResponse2 from './fixtures/react-native.response.2.json'; | ||
import reactNativeResponse3 from './fixtures/react-native.response.3.json'; | ||
import reactNativeResponse4 from './fixtures/react-native.response.4.json'; | ||
import reactNativeTransformed from './fixtures/react-native.transformed.json'; | ||
|
||
test.before(() => { | ||
nock('https://api.github.com') | ||
.persist() | ||
.get('/repos/jfmengels/all-contributors-cli/contributors?per_page=100') | ||
.reply(200, allContributorsCliResponse) | ||
.get('/repos/facebook/react-native/contributors?per_page=100') | ||
.reply(200, reactNativeResponse1, { | ||
Link: '<https://api.github.com/repositories/29028775/contributors?per_page=100&page=2>; rel="next", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=4>; rel="last"' | ||
}) | ||
.get('/repositories/29028775/contributors?per_page=100&page=2') | ||
.reply(200, reactNativeResponse2, { | ||
Link: '<https://api.github.com/repositories/29028775/contributors?per_page=100&page=3>; rel="next", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=4>; rel="last", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=1>; rel="first", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=1>; rel="prev"' | ||
}) | ||
.get('/repositories/29028775/contributors?per_page=100&page=3') | ||
.reply(200, reactNativeResponse3, { | ||
Link: '<https://api.github.com/repositories/29028775/contributors?per_page=100&page=4>; rel="next", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=4>; rel="last", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=1>; rel="first", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=2>; rel="prev"' | ||
}) | ||
.get('/repositories/29028775/contributors?per_page=100&page=4') | ||
.reply(200, reactNativeResponse4, { | ||
Link: '<https://api.github.com/repositories/29028775/contributors?per_page=100&page=1>; rel="first", <https://api.github.com/repositories/29028775/contributors?per_page=100&page=3>; rel="prev"' | ||
}); | ||
}); | ||
|
||
test('Handle a single results page correctly', async t => { | ||
const transformed = await check('jfmengels', 'all-contributors-cli'); | ||
t.deepEqual(transformed, allContributorsCliTransformed); | ||
}); | ||
|
||
test('Handle multiple results pages correctly', async t => { | ||
const transformed = await check('facebook', 'react-native'); | ||
t.deepEqual(transformed, reactNativeTransformed); | ||
}); |
Oops, something went wrong.