Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 () => {
Expand All @@ -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:

Expand Down
4 changes: 3 additions & 1 deletion examples/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand All @@ -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)
Expand All @@ -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
}
}

Expand Down