diff --git a/src/github/github.ts b/src/github/github.ts index a0a6fc4..6b2cf3f 100644 --- a/src/github/github.ts +++ b/src/github/github.ts @@ -60,32 +60,8 @@ export function getMyIssues( if (!account?.token) { return Promise.resolve({ meta: {}, response: [] }); } - const listParams = mapObject( - params, - { - assignee: true, - creator: true, - direction: true, - labels: (params) => { - if (Array.isArray(params.labels)) { - return params.labels.join(","); - } - return params.labels; - }, - mentioned: true, - page: true, - per_page: true, - since: true, - sort: (params) => issueListSortFromQuery(params), - state: true, - }, - true, - true, - ); - setPageSize(listParams); - - return api.listIssuesForToken(listParams, account.token, skipCache); + return api.listIssuesForToken(toIssueListParams(params), account.token, skipCache); } export function getIssuesForRepo( @@ -94,33 +70,7 @@ export function getIssuesForRepo( repo: string, skipCache = false, ): Promise> { - const listParams = mapObject( - params, - { - assignee: true, - creator: true, - direction: true, - labels: (params) => { - if (Array.isArray(params.labels)) { - return params.labels.join(","); - } - return params.labels; - }, - mentioned: true, - page: true, - per_page: true, - since: true, - sort: (params) => issueListSortFromQuery(params), - state: true, - filter: true, - }, - true, - true, - ); - - setPageSize(listParams); - - return api.listIssuesForRepo(org, repo, listParams, getToken(org), skipCache); + return api.listIssuesForRepo(org, repo, toIssueListParams(params), getToken(org), skipCache); } export function getIssuesForOrganization( @@ -250,3 +200,30 @@ export async function getPRForIssue(timelineUrl: string, org?: string): Promise< function setPageSize(params: { per_page?: number }): void { params.per_page = params.per_page ?? PluginSettings.defaultPageSize; } + +function toIssueListParams(queryParams: QueryParams): IssueListParams { + const listParams = mapObject( + queryParams, + { + assignee: true, + creator: true, + direction: true, + labels: (params) => { + if (Array.isArray(params.labels)) { + return params.labels.join(","); + } + return params.labels; + }, + mentioned: true, + page: true, + per_page: true, + since: true, + sort: (params) => issueListSortFromQuery(params), + state: true, + }, + true, + true, + ); + setPageSize(listParams); + return listParams; +}