(qualifiers)
| 3 | const githubService = require("../services/githubService"); |
| 4 | |
| 5 | const getFilteredPRsOrIssues = async (qualifiers) => { |
| 6 | let allPRs = []; |
| 7 | let githubServiceCallback = () => {}; |
| 8 | const { sortBy = "RECENT_FIRST", filterBy } = qualifiers; |
| 9 | const order = sortBy === "RECENT_FIRST" ? ORDER_TYPE.DESC : ORDER_TYPE.ASC; |
| 10 | |
| 11 | const startDate = qualifiers?.startDate; |
| 12 | const endDate = qualifiers?.endDate; |
| 13 | const dateTime = getDateTimeRangeForPRs(startDate, endDate); |
| 14 | |
| 15 | const searchParams = {}; // searchParams used to create list of params to create github API URL |
| 16 | const resultOptions = { order }; // resultOptions is used for ordering, searching within date-time range and pagination of results |
| 17 | |
| 18 | if (filterBy === "OPEN_PRS") { |
| 19 | if (dateTime) { |
| 20 | searchParams.created = dateTime; |
| 21 | } |
| 22 | |
| 23 | githubServiceCallback = githubService.fetchOpenPRs; |
| 24 | } |
| 25 | if (filterBy === "MERGED_PRS") { |
| 26 | if (dateTime) { |
| 27 | searchParams.merged = dateTime; |
| 28 | } |
| 29 | |
| 30 | githubServiceCallback = githubService.fetchMergedPRs; |
| 31 | } |
| 32 | |
| 33 | if (filterBy === "OPEN_ISSUES") { |
| 34 | if (dateTime) { |
| 35 | searchParams.created = dateTime; |
| 36 | } |
| 37 | |
| 38 | githubServiceCallback = githubService.fetchOpenIssues; |
| 39 | } |
| 40 | |
| 41 | if (filterBy === "CLOSED_ISSUES") { |
| 42 | if (dateTime) { |
| 43 | searchParams.closed = dateTime; |
| 44 | } |
| 45 | |
| 46 | githubServiceCallback = githubService.fetchClosedIssues; |
| 47 | } |
| 48 | |
| 49 | allPRs = await fetchMultiplePageResults(githubServiceCallback, { |
| 50 | searchParams, |
| 51 | resultOptions, |
| 52 | }); |
| 53 | |
| 54 | return allPRs; |
| 55 | }; |
| 56 | |
| 57 | const ORDER_TYPE = { |
| 58 | ASC: "asc", |
no test coverage detected