diff --git a/README.md b/README.md index 0eaac5a..3511e3c 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,7 @@ gfi('golang/dep') console.error(error) }) ``` - -Passing in a custom set of organizations to search: +Passing in a custom set of organizations to search and using sort and order: ```js const gfi = require('libgfi') @@ -62,7 +61,9 @@ const options = { q: 'org:nodejs is:issue is:open label:"good first issue"', //GitHub search query description: "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine." // Human readable description } - } + }, + sort: 'comments', + order: 'asc' } let log = async () => { @@ -71,6 +72,7 @@ let log = async () => { log() ``` +The valid options available in sort and order can be found at [Github's documentation](https://developer.github.com/v3/search/#search-issues-and-pull-requests). Passing any of the allowed parameters as strings should work. Passing in GitHub credentials (see Octokit's [authentication documentation](https://octokit.github.io/rest.js/#authentication) for more details) for authentication to exponentially increase the rate limit: diff --git a/examples/node.js b/examples/node.js index 71fafc8..55e3427 100644 --- a/examples/node.js +++ b/examples/node.js @@ -8,7 +8,9 @@ const options = { q: 'org:nodejs is:issue is:open label:"good first issue"', description: "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine." } - } + }, + sort: 'comments', + order: 'asc' } const log = async () => { diff --git a/index.js b/index.js index 0588d36..389f46f 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ module.exports = (project, options) => { } if (options.projects !== undefined && project in options.projects) { - return search(options.projects[project].q, options.auth) + return search(options.projects[project].q, options.auth, options.sort, options.order) } else { return search(`${project.includes('/') ? 'repo' : 'org'}:${project} state:open label:"good first issue"`, options.auth) } diff --git a/lib/search.js b/lib/search.js index f599547..68e053f 100644 --- a/lib/search.js +++ b/lib/search.js @@ -14,7 +14,7 @@ const PAGE = 1 // page_number is 1-based index // MAX_PAGE_ALLOWED = Math.ceil(MAX_RESULTS_POSSIBLE / PER_PAGE) const MAX_PAGE_ALLOWED = 34 -async function search (q, auth) { +async function search (q, auth, sort, order) { const octokit = auth ? Octokit({ auth }) : Octokit() const { data } = await octokit.search.issuesAndPullRequests(getSearchParams({ q })) @@ -25,7 +25,7 @@ async function search (q, auth) { // page_number is 1-based index const page = Math.floor(Math.random() * Math.floor(lastPageAllowed)) + 1 - const pageRes = await octokit.search.issuesAndPullRequests(getSearchParams({ q, page })) + const pageRes = await octokit.search.issuesAndPullRequests(getSearchParams({ q, page, sort, order })) return transform(pageRes.data) } else { return transform(data) @@ -34,11 +34,11 @@ async function search (q, auth) { function getSearchParams (searchParams) { return { - q: searchParams['q'], - sort: searchParams['sort'] || SORT, - order: searchParams['order'] || ORDER, - per_page: searchParams['per_page'] || PER_PAGE, - page: searchParams['page'] || PAGE + q: searchParams.q, + sort: searchParams.sort || SORT, + order: searchParams.order || ORDER, + per_page: searchParams.per_page || PER_PAGE, + page: searchParams.page || PAGE } }