Skip to content

Commit

Permalink
Merge pull request #12 from Doist/luke/exclude-weekends-when-checking…
Browse files Browse the repository at this point in the history
…-staleness

fix: Exclude Weekends When Checking Deadline
  • Loading branch information
lukemerrett authored Feb 3, 2025
2 parents c871d70 + 8b9a4f3 commit bdd1fa7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
# If index.js was different then expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v4
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
Expand Down
12 changes: 11 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9795,6 +9795,8 @@ function getLatestCreatedAtTime(nodes) {
* based on the time between when the review was requested, and whether
* there has been any review activity since then.
*
* Only counts weekdays, excludes weekends when checking if 24 hours have passed.
*
* @param reviewRequestTime The latest time the creator requested a person review the PR
* @param reviewTime The latest time the PR was reviewed
* @param reviewDeadline The total time in ms before a PR is considered stale
Expand All @@ -9806,7 +9808,12 @@ function isAfterReviewDeadline(reviewRequestTime, reviewTime, reviewDeadline) {
return false;
}
const now = new Date().getTime();
if (now - reviewRequestTime < reviewDeadline) {
let adjustedReviewDeadline = reviewDeadline;
if (isWeekend(new Date(reviewRequestTime + reviewDeadline))) {
// Push the deadline past the weekend (shift forward by 2 days)
adjustedReviewDeadline = reviewDeadline + 172800000;
}
if (now - reviewRequestTime < adjustedReviewDeadline) {
// There is still time for review.
return false;
}
Expand All @@ -9819,6 +9826,9 @@ function isAfterReviewDeadline(reviewRequestTime, reviewTime, reviewDeadline) {
function splitStringList(input) {
return input.split(',').map((item) => item.trim());
}
function isWeekend(date) {
return date.getDay() % 6 === 0;
}


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/pullrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ function getLatestCreatedAtTime(nodes: GraphQlNode[]): number | undefined {
* based on the time between when the review was requested, and whether
* there has been any review activity since then.
*
* Only counts weekdays, excludes weekends when checking if 24 hours have passed.
*
* @param reviewRequestTime The latest time the creator requested a person review the PR
* @param reviewTime The latest time the PR was reviewed
* @param reviewDeadline The total time in ms before a PR is considered stale
Expand All @@ -189,7 +191,14 @@ function isAfterReviewDeadline(
return false
}
const now = new Date().getTime()
if (now - reviewRequestTime < reviewDeadline) {

let adjustedReviewDeadline = reviewDeadline
if (isWeekend(new Date(reviewRequestTime + reviewDeadline))) {
// Push the deadline past the weekend (shift forward by 2 days)
adjustedReviewDeadline = reviewDeadline + 172800000
}

if (now - reviewRequestTime < adjustedReviewDeadline) {
// There is still time for review.
return false
}
Expand All @@ -204,3 +213,7 @@ function isAfterReviewDeadline(
function splitStringList(input: string): Array<string> {
return input.split(',').map((item) => item.trim())
}

function isWeekend(date: Date): boolean {
return date.getDay() % 6 === 0
}

0 comments on commit bdd1fa7

Please sign in to comment.