Skip to content

Commit c6c98e1

Browse files
committed
✨ add a limit param to increase the contributors list
A new CLI parameter `--limit, -l` has been introduced. The various API functions now also accept a `limit` option. Note that the maximum limit for now is 100. Closes #32
1 parent dac8188 commit c6c98e1

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const cli = meow(
1111
1212
Options
1313
--exclude, -e Exclude contributors, glob.
14+
--limit, -l Limit the number of contributors (default: 30).
1415
1516
Examples
1617
$ contributor-faces --exclude "*-bot"
1718
`,
1819
{
1920
alias: {
2021
e: 'exclude',
22+
l: 'limit'
2123
}
2224
}
2325
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"repository": "facebook/react"
3+
}

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ function getRepo(baton) {
1818
}
1919

2020
function fetch(baton) {
21-
return gh(`repos/${baton.repo}/contributors`).then(res => {
21+
const searchParams = {
22+
['per_page']: baton.limit
23+
}
24+
25+
return gh(`repos/${baton.repo}/contributors`, { searchParams }).then(res => {
2226
baton.contributors = res.body
2327
return baton
2428
})
@@ -77,6 +81,7 @@ function end(prop) {
7781
function core(dir, opts) {
7882
opts = opts || {}
7983
opts.dir = dir || '.'
84+
opts.limit = opts.limit || 30
8085
return Promise.resolve(opts).then(getRepo).then(fetch).then(filter)
8186
}
8287

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ test('list contributors', async t => {
1010
t.true(Array.isArray(contribs))
1111
})
1212

13+
test('limit contributors to 30 by default', async t => {
14+
const repoDir = path.join('fixtures', 'lots-of-contributors')
15+
const contribs = await contributors(repoDir)
16+
17+
t.is(contribs.length, 30)
18+
})
19+
20+
test('accept a limit parameter', async t => {
21+
const repoDir = path.join('fixtures', 'lots-of-contributors')
22+
const contribs = await contributors(repoDir, { limit: 100 })
23+
24+
t.is(contribs.length, 100)
25+
})
26+
1327
test.serial('use current directory by default', async t => {
1428
process.chdir('fixtures')
1529
const contribs = await contributors()

0 commit comments

Comments
 (0)