Skip to content

Commit 2b58cc9

Browse files
Fix issue when days-before-close is more than days-before-stale (#775)
1 parent 532554b commit 2b58cc9

2 files changed

Lines changed: 35 additions & 20 deletions

File tree

dist/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,12 @@ class IssuesProcessor {
720720
const issueLogger = new issue_logger_1.IssueLogger(issue);
721721
const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
722722
issueLogger.info(`$$type marked stale on: ${logger_service_1.LoggerService.cyan(markedStaleOn)}`);
723-
const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, staleMessage);
724-
issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasComments)}`);
723+
const issueHasCommentsSinceStale = yield this._hasCommentsSince(issue, markedStaleOn, staleMessage);
724+
issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasCommentsSinceStale)}`);
725725
const daysBeforeClose = issue.isPullRequest
726726
? this._getDaysBeforePrClose()
727727
: this._getDaysBeforeIssueClose();
728728
issueLogger.info(`Days before $$type close: ${logger_service_1.LoggerService.cyan(daysBeforeClose)}`);
729-
const issueHasUpdate = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose);
730-
issueLogger.info(`$$type has been updated: ${logger_service_1.LoggerService.cyan(issueHasUpdate)}`);
731729
const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue);
732730
issueLogger.info(`The option ${issueLogger.createOptionLink(this._getRemoveStaleWhenUpdatedUsedOptionName(issue))} is: ${logger_service_1.LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`);
733731
if (shouldRemoveStaleWhenUpdated) {
@@ -739,9 +737,11 @@ class IssuesProcessor {
739737
if (issue.markedStaleThisRun) {
740738
issueLogger.info(`marked stale this run, so don't check for updates`);
741739
}
740+
const issueHasUpdateSinceStale = new Date(issue.updated_at) > new Date(markedStaleOn);
741+
issueLogger.info(`$$type has been updated since it was marked stale: ${logger_service_1.LoggerService.cyan(issueHasUpdateSinceStale)}`);
742742
// Should we un-stale this issue?
743743
if (shouldRemoveStaleWhenUpdated &&
744-
(issueHasUpdate || issueHasComments) &&
744+
(issueHasUpdateSinceStale || issueHasCommentsSinceStale) &&
745745
!issue.markedStaleThisRun) {
746746
issueLogger.info(`Remove the stale label since the $$type has been updated and the workflow should remove the stale label when updated`);
747747
yield this._removeStaleLabel(issue, staleLabel);
@@ -755,7 +755,9 @@ class IssuesProcessor {
755755
if (daysBeforeClose < 0) {
756756
return; // Nothing to do because we aren't closing stale issues
757757
}
758-
if (!issueHasComments && !issueHasUpdate) {
758+
const issueHasUpdateInCloseWindow = IssuesProcessor._updatedSince(issue.updated_at, daysBeforeClose);
759+
issueLogger.info(`$$type has been updated in the last ${daysBeforeClose} days: ${logger_service_1.LoggerService.cyan(issueHasUpdateInCloseWindow)}`);
760+
if (!issueHasCommentsSinceStale && !issueHasUpdateInCloseWindow) {
759761
issueLogger.info(`Closing $$type because it was last updated on: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`);
760762
yield this._closeIssue(issue, closeMessage, closeLabel);
761763
if (this.options.deleteBranch && issue.pull_request) {
@@ -765,7 +767,7 @@ class IssuesProcessor {
765767
}
766768
}
767769
else {
768-
issueLogger.info(`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`);
770+
issueLogger.info(`Stale $$type is not old enough to close yet (hasComments? ${issueHasCommentsSinceStale}, hasUpdate? ${issueHasUpdateInCloseWindow})`);
769771
}
770772
});
771773
}

src/classes/issues-processor.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ export class IssuesProcessor {
625625
`$$type marked stale on: ${LoggerService.cyan(markedStaleOn)}`
626626
);
627627

628-
const issueHasComments: boolean = await this._hasCommentsSince(
628+
const issueHasCommentsSinceStale: boolean = await this._hasCommentsSince(
629629
issue,
630630
markedStaleOn,
631631
staleMessage
632632
);
633633
issueLogger.info(
634-
`$$type has been commented on: ${LoggerService.cyan(issueHasComments)}`
634+
`$$type has been commented on: ${LoggerService.cyan(
635+
issueHasCommentsSinceStale
636+
)}`
635637
);
636638

637639
const daysBeforeClose: number = issue.isPullRequest
@@ -642,14 +644,6 @@ export class IssuesProcessor {
642644
`Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}`
643645
);
644646

645-
const issueHasUpdate: boolean = IssuesProcessor._updatedSince(
646-
issue.updated_at,
647-
daysBeforeClose
648-
);
649-
issueLogger.info(
650-
`$$type has been updated: ${LoggerService.cyan(issueHasUpdate)}`
651-
);
652-
653647
const shouldRemoveStaleWhenUpdated: boolean =
654648
this._shouldRemoveStaleWhenUpdated(issue);
655649

@@ -671,10 +665,19 @@ export class IssuesProcessor {
671665
issueLogger.info(`marked stale this run, so don't check for updates`);
672666
}
673667

668+
const issueHasUpdateSinceStale =
669+
new Date(issue.updated_at) > new Date(markedStaleOn);
670+
671+
issueLogger.info(
672+
`$$type has been updated since it was marked stale: ${LoggerService.cyan(
673+
issueHasUpdateSinceStale
674+
)}`
675+
);
676+
674677
// Should we un-stale this issue?
675678
if (
676679
shouldRemoveStaleWhenUpdated &&
677-
(issueHasUpdate || issueHasComments) &&
680+
(issueHasUpdateSinceStale || issueHasCommentsSinceStale) &&
678681
!issue.markedStaleThisRun
679682
) {
680683
issueLogger.info(
@@ -696,7 +699,17 @@ export class IssuesProcessor {
696699
return; // Nothing to do because we aren't closing stale issues
697700
}
698701

699-
if (!issueHasComments && !issueHasUpdate) {
702+
const issueHasUpdateInCloseWindow: boolean = IssuesProcessor._updatedSince(
703+
issue.updated_at,
704+
daysBeforeClose
705+
);
706+
issueLogger.info(
707+
`$$type has been updated in the last ${daysBeforeClose} days: ${LoggerService.cyan(
708+
issueHasUpdateInCloseWindow
709+
)}`
710+
);
711+
712+
if (!issueHasCommentsSinceStale && !issueHasUpdateInCloseWindow) {
700713
issueLogger.info(
701714
`Closing $$type because it was last updated on: ${LoggerService.cyan(
702715
issue.updated_at
@@ -715,7 +728,7 @@ export class IssuesProcessor {
715728
}
716729
} else {
717730
issueLogger.info(
718-
`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`
731+
`Stale $$type is not old enough to close yet (hasComments? ${issueHasCommentsSinceStale}, hasUpdate? ${issueHasUpdateInCloseWindow})`
719732
);
720733
}
721734
}

0 commit comments

Comments
 (0)