@@ -368,6 +368,7 @@ const is_valid_date_1 = __nccwpck_require__(891);
368368const is_boolean_1 = __nccwpck_require__(8236);
369369const is_labeled_1 = __nccwpck_require__(6792);
370370const clean_label_1 = __nccwpck_require__(7752);
371+ const elapsed_millis_excluding_days_1 = __nccwpck_require__(4101);
371372const should_mark_when_stale_1 = __nccwpck_require__(2461);
372373const words_to_list_1 = __nccwpck_require__(1883);
373374const assignees_1 = __nccwpck_require__(7236);
@@ -386,9 +387,9 @@ const rate_limit_1 = __nccwpck_require__(7069);
386387 * Handle processing of issues for staleness/closure.
387388 */
388389class IssuesProcessor {
389- static _updatedSince(timestamp, num_days ) {
390- const daysInMillis = 1000 * 60 * 60 * 24 * num_days ;
391- const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime( );
390+ static _updatedSince(timestamp, numDays, excludeWeekdays ) {
391+ const daysInMillis = 1000 * 60 * 60 * 24 * numDays ;
392+ const millisSinceLastUpdated = (0, elapsed_millis_excluding_days_1.elapsedMillisExcludingDays)( new Date(timestamp), new Date(), excludeWeekdays );
392393 return millisSinceLastUpdated <= daysInMillis;
393394 }
394395 static _endIssueProcessing(issue) {
@@ -609,11 +610,11 @@ class IssuesProcessor {
609610 let shouldBeStale;
610611 // Ignore the last update and only use the creation date
611612 if (shouldIgnoreUpdates) {
612- shouldBeStale = !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale);
613+ shouldBeStale = !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale, this.options.excludeWeekdays );
613614 }
614615 // Use the last update to check if we need to stale
615616 else {
616- shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale);
617+ shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale, this.options.excludeWeekdays );
617618 }
618619 if (shouldBeStale) {
619620 if (shouldIgnoreUpdates) {
@@ -795,7 +796,7 @@ class IssuesProcessor {
795796 if (daysBeforeClose < 0) {
796797 return; // Nothing to do because we aren't closing stale issues
797798 }
798- const issueHasUpdateInCloseWindow = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose);
799+ const issueHasUpdateInCloseWindow = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose, this.options.excludeWeekdays );
799800 issueLogger.info(`$$type has been updated in the last ${daysBeforeClose} days: ${logger_service_1.LoggerService.cyan(issueHasUpdateInCloseWindow)}`);
800801 if (!issueHasCommentsSinceStale && !issueHasUpdateInCloseWindow) {
801802 issueLogger.info(`Closing $$type because it was last updated on: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`);
@@ -2333,6 +2334,62 @@ function isValidDate(date) {
23332334exports.isValidDate = isValidDate;
23342335
23352336
2337+ /***/ }),
2338+
2339+ /***/ 4101:
2340+ /***/ ((__unused_webpack_module, exports) => {
2341+
2342+ "use strict";
2343+
2344+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2345+ exports.elapsedMillisExcludingDays = void 0;
2346+ const DAY = 1000 * 60 * 60 * 24;
2347+ function startOfDay(date) {
2348+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
2349+ }
2350+ function countWeekdaysBetweenDates(start, end, excludeWeekdays) {
2351+ const totalDays = Math.floor((end.getTime() - start.getTime()) / DAY);
2352+ const startDayOfWeek = start.getDay();
2353+ const excludeWeekdaysMap = new Set(excludeWeekdays);
2354+ const fullWeeks = Math.floor(totalDays / 7);
2355+ const remainingDays = totalDays % 7;
2356+ // Count the number of excluded days in a full week (0-6)
2357+ let weeklyExcludedCount = 0;
2358+ for (let day = 0; day < 7; day++) {
2359+ if (excludeWeekdaysMap.has(day)) {
2360+ weeklyExcludedCount++;
2361+ }
2362+ }
2363+ // Count excluded days in the remaining days after full weeks
2364+ let extraExcludedCount = 0;
2365+ for (let i = 0; i < remainingDays; i++) {
2366+ const currentDay = (startDayOfWeek + i) % 7;
2367+ if (excludeWeekdaysMap.has(currentDay)) {
2368+ extraExcludedCount++;
2369+ }
2370+ }
2371+ // Compute the total excluded days
2372+ return fullWeeks * weeklyExcludedCount + extraExcludedCount;
2373+ }
2374+ const elapsedMillisExcludingDays = (from, to, excludeWeekdays) => {
2375+ let elapsedMillis = to.getTime() - from.getTime();
2376+ if (excludeWeekdays.length > 0) {
2377+ const startOfNextDayFrom = startOfDay(new Date(from.getTime() + DAY));
2378+ const startOfDayTo = startOfDay(to);
2379+ if (excludeWeekdays.includes(from.getDay())) {
2380+ elapsedMillis -= startOfNextDayFrom.getTime() - from.getTime();
2381+ }
2382+ if (excludeWeekdays.includes(to.getDay())) {
2383+ elapsedMillis -= to.getTime() - startOfDayTo.getTime();
2384+ }
2385+ const excludeWeekdaysCount = countWeekdaysBetweenDates(startOfNextDayFrom, startOfDayTo, excludeWeekdays);
2386+ elapsedMillis -= excludeWeekdaysCount * DAY;
2387+ }
2388+ return elapsedMillis;
2389+ };
2390+ exports.elapsedMillisExcludingDays = elapsedMillisExcludingDays;
2391+
2392+
23362393/***/ }),
23372394
23382395/***/ 8236:
@@ -2567,7 +2624,13 @@ function _getAndValidateArgs() {
25672624 ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
25682625 exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
25692626 closeIssueReason: core.getInput('close-issue-reason'),
2570- includeOnlyAssigned: core.getInput('include-only-assigned') === 'true'
2627+ includeOnlyAssigned: core.getInput('include-only-assigned') === 'true',
2628+ excludeWeekdays: core.getInput('exclude-weekdays')
2629+ ? core
2630+ .getInput('exclude-weekdays')
2631+ .split(',')
2632+ .map(day => parseInt(day.trim(), 10))
2633+ : []
25712634 };
25722635 for (const numberInput of ['days-before-stale']) {
25732636 if (isNaN(parseFloat(core.getInput(numberInput)))) {
@@ -2599,6 +2662,13 @@ function _getAndValidateArgs() {
25992662 core.setFailed(errorMessage);
26002663 throw new Error(errorMessage);
26012664 }
2665+ // Validate weekdays
2666+ if (args.excludeWeekdays &&
2667+ args.excludeWeekdays.some(day => isNaN(day) || day < 0 || day > 6)) {
2668+ const errorMessage = 'Option "exclude-weekdays" must be comma-separated integers between 0 (Sunday) and 6 (Saturday)';
2669+ core.setFailed(errorMessage);
2670+ throw new Error(errorMessage);
2671+ }
26022672 return args;
26032673}
26042674function processOutput(staledIssues, closedIssues) {
0 commit comments