(username, days)
| 335 | * @returns {boolean} - True if last PR merged is within the last `days` days else false |
| 336 | **/ |
| 337 | const isLastPRMergedWithinDays = async (username, days) => { |
| 338 | try { |
| 339 | const res = await fetchLastMergedPR(username); |
| 340 | if (!res) { |
| 341 | return false; |
| 342 | } |
| 343 | const mergedAt = res.items[0].pull_request.merged_at; |
| 344 | const lastPRMergedDate = new Date(mergedAt); |
| 345 | const currentDate = new Date(); |
| 346 | |
| 347 | const timeDifferenceInMilliseconds = currentDate - lastPRMergedDate; |
| 348 | const timeDifferenceInDays = timeDifferenceInMilliseconds / (1000 * 60 * 60 * 24); |
| 349 | |
| 350 | return timeDifferenceInDays <= days; |
| 351 | } catch (err) { |
| 352 | logger.error(`Error while checking last PR merged: ${err}`); |
| 353 | throw err; |
| 354 | } |
| 355 | }; |
| 356 | |
| 357 | module.exports = { |
| 358 | fetchPRsByUser, |
no test coverage detected