From cdf8a8af91d0efbff39b0d6ced49ea22a8ad7c47 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Mon, 28 Nov 2022 19:47:29 +0000 Subject: [PATCH 1/6] Prevent stale label removal from exempt items --- README.md | 8 ++-- __tests__/main.spec.ts | 74 ++++++++++++++++----------------- dist/index.js | 38 +++++++++++++---- src/classes/issues-processor.ts | 57 ++++++++++++++++++++----- 4 files changed, 118 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index b35614e46..045b8a631 100644 --- a/README.md +++ b/README.md @@ -246,8 +246,8 @@ Required Permission: `pull-requests: write` #### exempt-issue-labels -The label(s) that can exempt to automatically mark as stale the issues. -It can be a comma separated list of labels (e.g: `question,bug`). +Comma separated list of labels that exclude the issue from being marked as stale +(e.g: `question,bug`) If unset (or an empty string), this option will not alter the stale workflow. @@ -255,8 +255,8 @@ Default value: unset #### exempt-pr-labels -The label(s) that can exempt to automatically mark as stale the pull requests. -It can be a comma separated list of labels (e.g: `need-help,WIP`). +Comma separated list of labels that exclude the pull request from being marked as stale +(e.g: `need-help,WIP`) If unset (or an empty string), this option will not alter the stale workflow. diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index 218825471..8f83ff580 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -1094,43 +1094,43 @@ test('exempt pr labels will not be marked stale', async () => { expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label }); -test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => { - expect.assertions(3); - const opts = {...DefaultProcessorOptions}; - opts.exemptIssueLabels = 'Exempt'; - const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'My first issue', - '2020-01-01T17:00:00Z', - '2020-01-01T17:00:00Z', - false, - ['Exempt', 'Stale'] - ) - ]; - const processor = new IssuesProcessorMock( - opts, - async p => (p === 1 ? TestIssueList : []), - async () => [ - { - user: { - login: 'notme', - type: 'User' - }, - body: 'Body' - } - ], // return a fake comment to indicate there was an update - async () => new Date().toDateString() - ); - - // process our fake issue list - await processor.processIssues(1); - - expect(processor.staleIssues.length).toStrictEqual(0); - expect(processor.closedIssues.length).toStrictEqual(0); - expect(processor.removedLabelIssues.length).toStrictEqual(1); -}); +// test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => { +// expect.assertions(3); +// const opts = {...DefaultProcessorOptions}; +// opts.exemptIssueLabels = 'Exempt'; +// const TestIssueList: Issue[] = [ +// generateIssue( +// opts, +// 1, +// 'My super duper cool first issue', +// '2020-01-01T17:00:00Z', +// '2020-01-01T17:00:00Z', +// false, +// ['Exempt', 'Stale'] +// ) +// ]; +// const processor = new IssuesProcessorMock( +// opts, +// async p => (p === 1 ? TestIssueList : []), +// async () => [ +// { +// user: { +// login: 'notme', +// type: 'User' +// }, +// body: 'Body' +// } +// ], // return a fake comment to indicate there was an update +// async () => new Date().toDateString() +// ); + +// // process our fake issue list +// await processor.processIssues(1); + +// expect(processor.staleIssues.length).toStrictEqual(0); +// expect(processor.closedIssues.length).toStrictEqual(0); +// expect(processor.removedLabelIssues.length).toStrictEqual(1); +// }); test('stale issues should not be closed if days is set to -1', async () => { const opts = {...DefaultProcessorOptions}; diff --git a/dist/index.js b/dist/index.js index 0e78fccc9..e831fafa0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -447,6 +447,7 @@ class IssuesProcessor { (_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementProcessedItemsCount(issue); const issueLogger = new issue_logger_1.IssueLogger(issue); issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); + const shouldIgnoreUpdates = new ignore_updates_1.IgnoreUpdates(this.options, issue).shouldIgnoreUpdates(); // calculate string based messages for this issue const staleMessage = issue.isPullRequest ? this.options.stalePrMessage @@ -523,19 +524,21 @@ class IssuesProcessor { } } if (issue.isStale) { - issueLogger.info(`This $$type has a stale label`); + issueLogger.info(`This $$type includes a stale label`); } else { - issueLogger.info(`This $$type hasn't a stale label`); + issueLogger.info(`This $$type does not include a stale label`); } const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest ? this.options.exemptPrLabels : this.options.exemptIssueLabels); + //Check to see if the item should be stale? if its no longer stale --> remove the stale label + const isItemStale = this._shouldItemBeStale(issue, shouldIgnoreUpdates, daysBeforeStale); + issueLogger.info(`IS this item stale? ${isItemStale}, ${issue.updated_at}`); if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) { - if (issue.isStale) { - issueLogger.info(`An exempt label was added after the stale label.`); - yield this._removeStaleLabel(issue, staleLabel); - } + // if(!isItemStale){ + // //remove the stale label, the item is no longer stale + // } issueLogger.info(`Skipping this $$type because it has an exempt label`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues @@ -583,7 +586,6 @@ class IssuesProcessor { // Determine if this issue needs to be marked stale first if (!issue.isStale) { issueLogger.info(`This $$type is not stale`); - const shouldIgnoreUpdates = new ignore_updates_1.IgnoreUpdates(this.options, issue).shouldIgnoreUpdates(); // Should this issue be marked as stale? let shouldBeStale; // Ignore the last update and only use the creation date @@ -1122,6 +1124,28 @@ class IssuesProcessor { } return option_1.Option.RemoveStaleWhenUpdated; } + /** + * Checks to see if the issue/pr should be considered stale + * if the ignore-updates flag is enabled use the creation date + * otherwise, use the last updated date to determine whether the item is stale. + * @param issue - the item we are evaluating + * @param shouldIgnoreUpdates - whether the ignore-updates flag is enabled + * @param daysBeforeStale - number of days before the item is stale + */ + _shouldItemBeStale(issue, shouldIgnoreUpdates, daysBeforeStale) { + return shouldIgnoreUpdates + ? !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale) + : !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); + // // Ignore the last update and only use the creation date + // if (shouldIgnoreUpdates) { + // shouldBeStale = + // } + // // Use the last update to check if we need to stale + // else { + // shouldBeStale = + // } + // return !! + } } exports.IssuesProcessor = IssuesProcessor; diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 70e3bf242..e1270e0ca 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -189,6 +189,11 @@ export class IssuesProcessor { )}` ); + const shouldIgnoreUpdates: boolean = new IgnoreUpdates( + this.options, + issue + ).shouldIgnoreUpdates(); + // calculate string based messages for this issue const staleMessage: string = issue.isPullRequest ? this.options.stalePrMessage @@ -321,9 +326,9 @@ export class IssuesProcessor { } if (issue.isStale) { - issueLogger.info(`This $$type has a stale label`); + issueLogger.info(`This $$type includes a stale label`); } else { - issueLogger.info(`This $$type hasn't a stale label`); + issueLogger.info(`This $$type does not include a stale label`); } const exemptLabels: string[] = wordsToList( @@ -332,16 +337,23 @@ export class IssuesProcessor { : this.options.exemptIssueLabels ); + //Check to see if the item should be stale? if its no longer stale --> remove the stale label + + const isItemStale = this._shouldItemBeStale( + issue, + shouldIgnoreUpdates, + daysBeforeStale + ); + issueLogger.info(`IS this item stale? ${isItemStale}, ${issue.updated_at}`); + if ( exemptLabels.some((exemptLabel: Readonly): boolean => isLabeled(issue, exemptLabel) ) ) { - if (issue.isStale) { - issueLogger.info(`An exempt label was added after the stale label.`); - await this._removeStaleLabel(issue, staleLabel); - } - + // if(!isItemStale){ + // //remove the stale label, the item is no longer stale + // } issueLogger.info(`Skipping this $$type because it has an exempt label`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues @@ -427,10 +439,6 @@ export class IssuesProcessor { // Determine if this issue needs to be marked stale first if (!issue.isStale) { issueLogger.info(`This $$type is not stale`); - const shouldIgnoreUpdates: boolean = new IgnoreUpdates( - this.options, - issue - ).shouldIgnoreUpdates(); // Should this issue be marked as stale? let shouldBeStale: boolean; @@ -1227,4 +1235,31 @@ export class IssuesProcessor { return Option.RemoveStaleWhenUpdated; } + + /** + * Checks to see if the issue/pr should be considered stale + * if the ignore-updates flag is enabled use the creation date + * otherwise, use the last updated date to determine whether the item is stale. + * @param issue - the item we are evaluating + * @param shouldIgnoreUpdates - whether the ignore-updates flag is enabled + * @param daysBeforeStale - number of days before the item is stale + */ + private _shouldItemBeStale( + issue: Readonly, + shouldIgnoreUpdates: boolean, + daysBeforeStale: number + ): boolean { + return shouldIgnoreUpdates + ? !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale) + : !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); + // // Ignore the last update and only use the creation date + // if (shouldIgnoreUpdates) { + // shouldBeStale = + // } + // // Use the last update to check if we need to stale + // else { + // shouldBeStale = + // } + // return !! + } } From d1cf1cd172c16e5d8898498a678e1d77e48edcd3 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:01:00 +0000 Subject: [PATCH 2/6] New flag that will remove stale from exempt items --- README.md | 7 + .../constants/default-processor-options.ts | 3 +- __tests__/main.spec.ts | 121 ++++++++++++------ action.yml | 4 + dist/index.js | 61 +++++---- src/classes/issue.spec.ts | 3 +- src/classes/issues-processor.ts | 98 ++++++++------ src/enums/option.ts | 3 +- src/interfaces/issues-processor-options.ts | 1 + src/main.ts | 4 +- 10 files changed, 201 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 045b8a631..fda658a39 100644 --- a/README.md +++ b/README.md @@ -524,6 +524,13 @@ If set to `true`, only the issues or the pull requests with an assignee will be Default value: `false` +#### remove-stale-from-exempt-items + +If set to `true`, issues or pull request with an [exempt-issue-label](#exempt-issue-label) or [exempt-pr-labels](#exempt-pr-labels) +that are no longer stale will have the stale label removed. + +Default value: `false` + ### Usage See also [action.yml](./action.yml) for a comprehensive list of all the options. diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index 4ef2359dd..9ea194234 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -54,5 +54,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ ignorePrUpdates: undefined, exemptDraftPr: false, closeIssueReason: 'not_planned', - includeOnlyAssigned: false + includeOnlyAssigned: false, + removeStaleFromExemptItems: false }); diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index 8f83ff580..72d765275 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -1094,43 +1094,90 @@ test('exempt pr labels will not be marked stale', async () => { expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label }); -// test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => { -// expect.assertions(3); -// const opts = {...DefaultProcessorOptions}; -// opts.exemptIssueLabels = 'Exempt'; -// const TestIssueList: Issue[] = [ -// generateIssue( -// opts, -// 1, -// 'My super duper cool first issue', -// '2020-01-01T17:00:00Z', -// '2020-01-01T17:00:00Z', -// false, -// ['Exempt', 'Stale'] -// ) -// ]; -// const processor = new IssuesProcessorMock( -// opts, -// async p => (p === 1 ? TestIssueList : []), -// async () => [ -// { -// user: { -// login: 'notme', -// type: 'User' -// }, -// body: 'Body' -// } -// ], // return a fake comment to indicate there was an update -// async () => new Date().toDateString() -// ); - -// // process our fake issue list -// await processor.processIssues(1); - -// expect(processor.staleIssues.length).toStrictEqual(0); -// expect(processor.closedIssues.length).toStrictEqual(0); -// expect(processor.removedLabelIssues.length).toStrictEqual(1); -// }); +describe('remove-stale-from-exempt-items is used', () => { + test('remove-stale-from-exempt-items is enabled, exempt issues that were recently updated will have stale removed', async () => { + expect.assertions(3); + const opts = { + ...DefaultProcessorOptions, + removeStaleWhenUpdated: true, + removeStaleFromExemptItems: true + }; + opts.exemptIssueLabels = 'Exempt'; + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'My first issue', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + ['Exempt', 'Stale'] + ) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [ + { + user: { + login: 'notme', + type: 'User' + }, + body: 'Body' + } + ], // return a fake comment to indicate there was an update + async () => new Date().toDateString() + ); + + // process our fake issue list + await processor.processIssues(1); + + expect(processor.staleIssues.length).toStrictEqual(0); + expect(processor.closedIssues.length).toStrictEqual(0); + expect(processor.removedLabelIssues.length).toStrictEqual(1); + }); + + test('remove-stale-from-exempt-items is disabled, exempt issues that are no longer stale will not have stale removed', async () => { + expect.assertions(3); + const opts = { + ...DefaultProcessorOptions, + removeStaleWhenUpdated: true, + removeStaleFromExemptItems: false + }; + opts.exemptIssueLabels = 'Exempt'; + const TestIssueList: Issue[] = [ + generateIssue( + opts, + 1, + 'My first issue', + '2020-01-01T17:00:00Z', + '2020-01-01T17:00:00Z', + false, + ['Stale', 'Exempt'] + ) + ]; + const processor = new IssuesProcessorMock( + opts, + async p => (p === 1 ? TestIssueList : []), + async () => [ + { + user: { + login: 'notme', + type: 'User' + }, + body: 'Body' + } + ], // return a fake comment to indicate there was an update + async () => new Date().toDateString() + ); + // process our fake issue list + await processor.processIssues(1); + + expect(processor.statistics?.processedIssuesCount).toStrictEqual(1); + expect(processor.closedIssues).toHaveLength(0); + expect(processor.removedLabelIssues).toHaveLength(0); + }); +}); test('stale issues should not be closed if days is set to -1', async () => { const opts = {...DefaultProcessorOptions}; diff --git a/action.yml b/action.yml index ea63e364a..2fc43fcc9 100644 --- a/action.yml +++ b/action.yml @@ -200,6 +200,10 @@ inputs: description: 'Only the issues or the pull requests with an assignee will be marked as stale automatically.' default: 'false' required: false + remove-stale-from-exempt-items: + description: 'When stale exempt items are updated, remove the stale label from the exempt item.' + default: 'false' + required: false outputs: closed-issues-prs: description: 'List of all closed issues and pull requests.' diff --git a/dist/index.js b/dist/index.js index e831fafa0..c83039256 100644 --- a/dist/index.js +++ b/dist/index.js @@ -532,13 +532,17 @@ class IssuesProcessor { const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest ? this.options.exemptPrLabels : this.options.exemptIssueLabels); - //Check to see if the item should be stale? if its no longer stale --> remove the stale label - const isItemStale = this._shouldItemBeStale(issue, shouldIgnoreUpdates, daysBeforeStale); - issueLogger.info(`IS this item stale? ${isItemStale}, ${issue.updated_at}`); - if (exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel))) { - // if(!isItemStale){ - // //remove the stale label, the item is no longer stale - // } + const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel)); + const isRemoveStaleFromExemptItemEnabled = this._removeStaleFromExemptItems(hasExemptLabel); + if (hasExemptLabel) { + // Determine whether we want to manage an exempt item + // Only check to see if the issue is stale if the option is enabled + const isIssueStale = isRemoveStaleFromExemptItemEnabled && + (yield this._isIssueStale(issue, staleLabel, staleMessage)); + if (isIssueStale) { + issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.RemoveStaleFromExemptItem)} is enabled, this $$type is no longer stale`); + yield this._removeStaleLabel(issue, staleLabel); + } issueLogger.info(`Skipping this $$type because it has an exempt label`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues @@ -1000,6 +1004,9 @@ class IssuesProcessor { _isIncludeOnlyAssigned(issue) { return this.options.includeOnlyAssigned && !issue.hasAssignees; } + _removeStaleFromExemptItems(hasExemptLabel) { + return this.options.removeStaleFromExemptItems && hasExemptLabel; + } _getAnyOfLabels(issue) { if (issue.isPullRequest) { if (this.options.anyOfPrLabels !== '') { @@ -1125,26 +1132,26 @@ class IssuesProcessor { return option_1.Option.RemoveStaleWhenUpdated; } /** - * Checks to see if the issue/pr should be considered stale - * if the ignore-updates flag is enabled use the creation date - * otherwise, use the last updated date to determine whether the item is stale. + * Checks to see if there has been activity on an item after the issue was marked stale + * This consumes 2 operations, one to fetch when the issue was marked stale, and one to fetch the comments * @param issue - the item we are evaluating - * @param shouldIgnoreUpdates - whether the ignore-updates flag is enabled - * @param daysBeforeStale - number of days before the item is stale + * @param staleLabel - the stale label we use on our items + * @param staleMessage - the stale message we use on our items + * @returns - false by default */ - _shouldItemBeStale(issue, shouldIgnoreUpdates, daysBeforeStale) { - return shouldIgnoreUpdates - ? !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale) - : !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); - // // Ignore the last update and only use the creation date - // if (shouldIgnoreUpdates) { - // shouldBeStale = - // } - // // Use the last update to check if we need to stale - // else { - // shouldBeStale = - // } - // return !! + _isIssueStale(issue, staleLabel, staleMessage) { + return __awaiter(this, void 0, void 0, function* () { + if (issue.isStale) { + const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || + issue.updated_at; + const issueHasCommentsSinceStale = yield this._hasCommentsSince(issue, markedStaleOn, staleMessage); + const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue); + const issueHasUpdateSinceStale = is_date_more_recent_than_1.isDateMoreRecentThan(new Date(issue.updated_at), new Date(markedStaleOn), 15); + return (shouldRemoveStaleWhenUpdated && + (issueHasUpdateSinceStale || issueHasCommentsSinceStale)); + } + return false; + }); } } exports.IssuesProcessor = IssuesProcessor; @@ -1930,6 +1937,7 @@ var Option; Option["IgnorePrUpdates"] = "ignore-pr-updates"; Option["ExemptDraftPr"] = "exempt-draft-pr"; Option["CloseIssueReason"] = "close-issue-reason"; + Option["RemoveStaleFromExemptItem"] = "remove-stale-from-exempt-item"; })(Option = exports.Option || (exports.Option = {})); @@ -2255,7 +2263,8 @@ function _getAndValidateArgs() { ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', closeIssueReason: core.getInput('close-issue-reason'), - includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' + includeOnlyAssigned: core.getInput('include-only-assigned') === 'true', + removeStaleFromExemptItems: core.getInput('remove-stale-from-exempt-items') === 'true' }; for (const numberInput of ['days-before-stale']) { if (isNaN(parseFloat(core.getInput(numberInput)))) { diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index 977b767cc..07a49e398 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -63,7 +63,8 @@ describe('Issue', (): void => { ignorePrUpdates: undefined, exemptDraftPr: false, closeIssueReason: '', - includeOnlyAssigned: false + includeOnlyAssigned: false, + removeStaleFromExemptItems: false }; issueInterface = { title: 'dummy-title', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index e1270e0ca..235ea3af5 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -337,23 +337,28 @@ export class IssuesProcessor { : this.options.exemptIssueLabels ); - //Check to see if the item should be stale? if its no longer stale --> remove the stale label - - const isItemStale = this._shouldItemBeStale( - issue, - shouldIgnoreUpdates, - daysBeforeStale + const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly) => + isLabeled(issue, exemptLabel) ); - issueLogger.info(`IS this item stale? ${isItemStale}, ${issue.updated_at}`); - if ( - exemptLabels.some((exemptLabel: Readonly): boolean => - isLabeled(issue, exemptLabel) - ) - ) { - // if(!isItemStale){ - // //remove the stale label, the item is no longer stale - // } + const isRemoveStaleFromExemptItemEnabled = + this._removeStaleFromExemptItems(hasExemptLabel); + + if (hasExemptLabel) { + // Determine whether we want to manage an exempt item + const isIssueStale = + isRemoveStaleFromExemptItemEnabled && + (await this._isIssueStale(issue, staleLabel, staleMessage)); + + if (isIssueStale) { + issueLogger.info( + `The option ${issueLogger.createOptionLink( + Option.RemoveStaleFromExemptItem + )} is enabled, this $$type is no longer stale` + ); + + await this._removeStaleLabel(issue, staleLabel); + } issueLogger.info(`Skipping this $$type because it has an exempt label`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues @@ -1037,6 +1042,10 @@ export class IssuesProcessor { return this.options.includeOnlyAssigned && !issue.hasAssignees; } + private _removeStaleFromExemptItems(hasExemptLabel: boolean) { + return this.options.removeStaleFromExemptItems && hasExemptLabel; + } + private _getAnyOfLabels(issue: Issue): string { if (issue.isPullRequest) { if (this.options.anyOfPrLabels !== '') { @@ -1237,29 +1246,44 @@ export class IssuesProcessor { } /** - * Checks to see if the issue/pr should be considered stale - * if the ignore-updates flag is enabled use the creation date - * otherwise, use the last updated date to determine whether the item is stale. + * Checks to see if there has been activity on an item after the issue was marked stale + * This consumes 2 operations, one to fetch when the issue was marked stale, and one to fetch the comments * @param issue - the item we are evaluating - * @param shouldIgnoreUpdates - whether the ignore-updates flag is enabled - * @param daysBeforeStale - number of days before the item is stale + * @param staleLabel - the stale label we use on our items + * @param staleMessage - the stale message we use on our items + * @returns - false by default */ - private _shouldItemBeStale( - issue: Readonly, - shouldIgnoreUpdates: boolean, - daysBeforeStale: number - ): boolean { - return shouldIgnoreUpdates - ? !IssuesProcessor._updatedSince(issue.created_at, daysBeforeStale) - : !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale); - // // Ignore the last update and only use the creation date - // if (shouldIgnoreUpdates) { - // shouldBeStale = - // } - // // Use the last update to check if we need to stale - // else { - // shouldBeStale = - // } - // return !! + private async _isIssueStale( + issue: Issue, + staleLabel: string, + staleMessage: string + ): Promise { + if (issue.isStale) { + const markedStaleOn = + (await this.getLabelCreationDate(issue, staleLabel)) || + issue.updated_at; + + const issueHasCommentsSinceStale = await this._hasCommentsSince( + issue, + markedStaleOn, + staleMessage + ); + + const shouldRemoveStaleWhenUpdated = + this._shouldRemoveStaleWhenUpdated(issue); + + const issueHasUpdateSinceStale = isDateMoreRecentThan( + new Date(issue.updated_at), + new Date(markedStaleOn), + 15 + ); + + return ( + shouldRemoveStaleWhenUpdated && + (issueHasUpdateSinceStale || issueHasCommentsSinceStale) + ); + } + + return false; } } diff --git a/src/enums/option.ts b/src/enums/option.ts index 38cfb193d..41d85d60d 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -47,5 +47,6 @@ export enum Option { IgnoreIssueUpdates = 'ignore-issue-updates', IgnorePrUpdates = 'ignore-pr-updates', ExemptDraftPr = 'exempt-draft-pr', - CloseIssueReason = 'close-issue-reason' + CloseIssueReason = 'close-issue-reason', + RemoveStaleFromExemptItem = 'remove-stale-from-exempt-item' } diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index b056a28c6..37e0dc2cf 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -53,4 +53,5 @@ export interface IIssuesProcessorOptions { exemptDraftPr: boolean; closeIssueReason: string; includeOnlyAssigned: boolean; + removeStaleFromExemptItems: boolean; } diff --git a/src/main.ts b/src/main.ts index 1045d6c57..3ff91884f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,7 +89,9 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', closeIssueReason: core.getInput('close-issue-reason'), - includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' + includeOnlyAssigned: core.getInput('include-only-assigned') === 'true', + removeStaleFromExemptItems: + core.getInput('remove-stale-from-exempt-items') === 'true' }; for (const numberInput of ['days-before-stale']) { From 0cd4aef52183ba8f16895b4be3c372cb9ae938d0 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Thu, 1 Dec 2022 20:05:19 +0000 Subject: [PATCH 3/6] update README and file structure --- README.md | 6 +++--- dist/index.js | 12 ++++-------- src/classes/issues-processor.ts | 19 ++++++++----------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index fda658a39..0b3e2c847 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ Required Permission: `pull-requests: write` #### exempt-issue-labels -Comma separated list of labels that exclude the issue from being marked as stale +Comma separated list of labels that can be assigned to issues to exclude them from being marked as stale (e.g: `question,bug`) If unset (or an empty string), this option will not alter the stale workflow. @@ -255,7 +255,7 @@ Default value: unset #### exempt-pr-labels -Comma separated list of labels that exclude the pull request from being marked as stale +Comma separated list of labels that can be assigned to pull requests to exclude them from being marked as stale (e.g: `need-help,WIP`) If unset (or an empty string), this option will not alter the stale workflow. @@ -526,7 +526,7 @@ Default value: `false` #### remove-stale-from-exempt-items -If set to `true`, issues or pull request with an [exempt-issue-label](#exempt-issue-label) or [exempt-pr-labels](#exempt-pr-labels) +If set to `true`, issues or pull requests with an [exempt-issue-label](#exempt-issue-labels) or [exempt-pr-label](#exempt-pr-labels) that are no longer stale will have the stale label removed. Default value: `false` diff --git a/dist/index.js b/dist/index.js index c83039256..545c71dfb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -447,7 +447,6 @@ class IssuesProcessor { (_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementProcessedItemsCount(issue); const issueLogger = new issue_logger_1.IssueLogger(issue); issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`); - const shouldIgnoreUpdates = new ignore_updates_1.IgnoreUpdates(this.options, issue).shouldIgnoreUpdates(); // calculate string based messages for this issue const staleMessage = issue.isPullRequest ? this.options.stalePrMessage @@ -536,7 +535,6 @@ class IssuesProcessor { const isRemoveStaleFromExemptItemEnabled = this._removeStaleFromExemptItems(hasExemptLabel); if (hasExemptLabel) { // Determine whether we want to manage an exempt item - // Only check to see if the issue is stale if the option is enabled const isIssueStale = isRemoveStaleFromExemptItemEnabled && (yield this._isIssueStale(issue, staleLabel, staleMessage)); if (isIssueStale) { @@ -590,6 +588,7 @@ class IssuesProcessor { // Determine if this issue needs to be marked stale first if (!issue.isStale) { issueLogger.info(`This $$type is not stale`); + const shouldIgnoreUpdates = new ignore_updates_1.IgnoreUpdates(this.options, issue).shouldIgnoreUpdates(); // Should this issue be marked as stale? let shouldBeStale; // Ignore the last update and only use the creation date @@ -1132,12 +1131,9 @@ class IssuesProcessor { return option_1.Option.RemoveStaleWhenUpdated; } /** - * Checks to see if there has been activity on an item after the issue was marked stale - * This consumes 2 operations, one to fetch when the issue was marked stale, and one to fetch the comments - * @param issue - the item we are evaluating - * @param staleLabel - the stale label we use on our items - * @param staleMessage - the stale message we use on our items - * @returns - false by default + * Checks to see if there has been activity on an item after the item was marked stale + * This consumes 2 operations, one to fetch when the item was marked stale, + * and one to fetch the comments on that item */ _isIssueStale(issue, staleLabel, staleMessage) { return __awaiter(this, void 0, void 0, function* () { diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 235ea3af5..0cf2d8fdd 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -189,11 +189,6 @@ export class IssuesProcessor { )}` ); - const shouldIgnoreUpdates: boolean = new IgnoreUpdates( - this.options, - issue - ).shouldIgnoreUpdates(); - // calculate string based messages for this issue const staleMessage: string = issue.isPullRequest ? this.options.stalePrMessage @@ -445,6 +440,11 @@ export class IssuesProcessor { if (!issue.isStale) { issueLogger.info(`This $$type is not stale`); + const shouldIgnoreUpdates: boolean = new IgnoreUpdates( + this.options, + issue + ).shouldIgnoreUpdates(); + // Should this issue be marked as stale? let shouldBeStale: boolean; @@ -1246,12 +1246,9 @@ export class IssuesProcessor { } /** - * Checks to see if there has been activity on an item after the issue was marked stale - * This consumes 2 operations, one to fetch when the issue was marked stale, and one to fetch the comments - * @param issue - the item we are evaluating - * @param staleLabel - the stale label we use on our items - * @param staleMessage - the stale message we use on our items - * @returns - false by default + * Checks to see if there has been activity on an item after the item was marked stale + * This consumes 2 operations, one to fetch when the item was marked stale, + * and one to fetch the comments on that item */ private async _isIssueStale( issue: Issue, From 330059ba240fb2a42ad8d7f1b3f0bd129b6cd797 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Thu, 15 Dec 2022 17:41:19 +0000 Subject: [PATCH 4/6] undo remove-stale-from-exempt-items and tweak some of the existing logging --- README.md | 7 -- .../constants/default-processor-options.ts | 3 +- __tests__/main.spec.ts | 85 ------------------- action.yml | 4 - dist/index.js | 41 ++------- src/classes/issue.spec.ts | 3 +- src/classes/issues-processor.ts | 76 +++-------------- src/enums/option.ts | 3 +- src/interfaces/issues-processor-options.ts | 1 - src/main.ts | 4 +- 10 files changed, 19 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index 0b3e2c847..41de7f225 100644 --- a/README.md +++ b/README.md @@ -524,13 +524,6 @@ If set to `true`, only the issues or the pull requests with an assignee will be Default value: `false` -#### remove-stale-from-exempt-items - -If set to `true`, issues or pull requests with an [exempt-issue-label](#exempt-issue-labels) or [exempt-pr-label](#exempt-pr-labels) -that are no longer stale will have the stale label removed. - -Default value: `false` - ### Usage See also [action.yml](./action.yml) for a comprehensive list of all the options. diff --git a/__tests__/constants/default-processor-options.ts b/__tests__/constants/default-processor-options.ts index 9ea194234..4ef2359dd 100644 --- a/__tests__/constants/default-processor-options.ts +++ b/__tests__/constants/default-processor-options.ts @@ -54,6 +54,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({ ignorePrUpdates: undefined, exemptDraftPr: false, closeIssueReason: 'not_planned', - includeOnlyAssigned: false, - removeStaleFromExemptItems: false + includeOnlyAssigned: false }); diff --git a/__tests__/main.spec.ts b/__tests__/main.spec.ts index 72d765275..6f752864f 100644 --- a/__tests__/main.spec.ts +++ b/__tests__/main.spec.ts @@ -1094,91 +1094,6 @@ test('exempt pr labels will not be marked stale', async () => { expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label }); -describe('remove-stale-from-exempt-items is used', () => { - test('remove-stale-from-exempt-items is enabled, exempt issues that were recently updated will have stale removed', async () => { - expect.assertions(3); - const opts = { - ...DefaultProcessorOptions, - removeStaleWhenUpdated: true, - removeStaleFromExemptItems: true - }; - opts.exemptIssueLabels = 'Exempt'; - const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'My first issue', - '2020-01-01T17:00:00Z', - '2020-01-01T17:00:00Z', - false, - ['Exempt', 'Stale'] - ) - ]; - const processor = new IssuesProcessorMock( - opts, - async p => (p === 1 ? TestIssueList : []), - async () => [ - { - user: { - login: 'notme', - type: 'User' - }, - body: 'Body' - } - ], // return a fake comment to indicate there was an update - async () => new Date().toDateString() - ); - - // process our fake issue list - await processor.processIssues(1); - - expect(processor.staleIssues.length).toStrictEqual(0); - expect(processor.closedIssues.length).toStrictEqual(0); - expect(processor.removedLabelIssues.length).toStrictEqual(1); - }); - - test('remove-stale-from-exempt-items is disabled, exempt issues that are no longer stale will not have stale removed', async () => { - expect.assertions(3); - const opts = { - ...DefaultProcessorOptions, - removeStaleWhenUpdated: true, - removeStaleFromExemptItems: false - }; - opts.exemptIssueLabels = 'Exempt'; - const TestIssueList: Issue[] = [ - generateIssue( - opts, - 1, - 'My first issue', - '2020-01-01T17:00:00Z', - '2020-01-01T17:00:00Z', - false, - ['Stale', 'Exempt'] - ) - ]; - const processor = new IssuesProcessorMock( - opts, - async p => (p === 1 ? TestIssueList : []), - async () => [ - { - user: { - login: 'notme', - type: 'User' - }, - body: 'Body' - } - ], // return a fake comment to indicate there was an update - async () => new Date().toDateString() - ); - // process our fake issue list - await processor.processIssues(1); - - expect(processor.statistics?.processedIssuesCount).toStrictEqual(1); - expect(processor.closedIssues).toHaveLength(0); - expect(processor.removedLabelIssues).toHaveLength(0); - }); -}); - test('stale issues should not be closed if days is set to -1', async () => { const opts = {...DefaultProcessorOptions}; opts.daysBeforeClose = -1; diff --git a/action.yml b/action.yml index 2fc43fcc9..ea63e364a 100644 --- a/action.yml +++ b/action.yml @@ -200,10 +200,6 @@ inputs: description: 'Only the issues or the pull requests with an assignee will be marked as stale automatically.' default: 'false' required: false - remove-stale-from-exempt-items: - description: 'When stale exempt items are updated, remove the stale label from the exempt item.' - default: 'false' - required: false outputs: closed-issues-prs: description: 'List of all closed issues and pull requests.' diff --git a/dist/index.js b/dist/index.js index 545c71dfb..7e19918b6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -528,20 +528,13 @@ class IssuesProcessor { else { issueLogger.info(`This $$type does not include a stale label`); } - const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest + const isExemptPr = issue.isPullRequest ? this.options.exemptPrLabels - : this.options.exemptIssueLabels); + : this.options.exemptIssueLabels; + const exemptLabels = words_to_list_1.wordsToList(isExemptPr); const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel)); - const isRemoveStaleFromExemptItemEnabled = this._removeStaleFromExemptItems(hasExemptLabel); if (hasExemptLabel) { - // Determine whether we want to manage an exempt item - const isIssueStale = isRemoveStaleFromExemptItemEnabled && - (yield this._isIssueStale(issue, staleLabel, staleMessage)); - if (isIssueStale) { - issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.RemoveStaleFromExemptItem)} is enabled, this $$type is no longer stale`); - yield this._removeStaleLabel(issue, staleLabel); - } - issueLogger.info(`Skipping this $$type because it has an exempt label`); + issueLogger.info(`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(isExemptPr ? option_1.Option.ExemptPrLabels : option_1.Option.ExemptIssueLabels)} for more details`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues } @@ -1003,9 +996,6 @@ class IssuesProcessor { _isIncludeOnlyAssigned(issue) { return this.options.includeOnlyAssigned && !issue.hasAssignees; } - _removeStaleFromExemptItems(hasExemptLabel) { - return this.options.removeStaleFromExemptItems && hasExemptLabel; - } _getAnyOfLabels(issue) { if (issue.isPullRequest) { if (this.options.anyOfPrLabels !== '') { @@ -1130,25 +1120,6 @@ class IssuesProcessor { } return option_1.Option.RemoveStaleWhenUpdated; } - /** - * Checks to see if there has been activity on an item after the item was marked stale - * This consumes 2 operations, one to fetch when the item was marked stale, - * and one to fetch the comments on that item - */ - _isIssueStale(issue, staleLabel, staleMessage) { - return __awaiter(this, void 0, void 0, function* () { - if (issue.isStale) { - const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || - issue.updated_at; - const issueHasCommentsSinceStale = yield this._hasCommentsSince(issue, markedStaleOn, staleMessage); - const shouldRemoveStaleWhenUpdated = this._shouldRemoveStaleWhenUpdated(issue); - const issueHasUpdateSinceStale = is_date_more_recent_than_1.isDateMoreRecentThan(new Date(issue.updated_at), new Date(markedStaleOn), 15); - return (shouldRemoveStaleWhenUpdated && - (issueHasUpdateSinceStale || issueHasCommentsSinceStale)); - } - return false; - }); - } } exports.IssuesProcessor = IssuesProcessor; @@ -1933,7 +1904,6 @@ var Option; Option["IgnorePrUpdates"] = "ignore-pr-updates"; Option["ExemptDraftPr"] = "exempt-draft-pr"; Option["CloseIssueReason"] = "close-issue-reason"; - Option["RemoveStaleFromExemptItem"] = "remove-stale-from-exempt-item"; })(Option = exports.Option || (exports.Option = {})); @@ -2259,8 +2229,7 @@ function _getAndValidateArgs() { ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', closeIssueReason: core.getInput('close-issue-reason'), - includeOnlyAssigned: core.getInput('include-only-assigned') === 'true', - removeStaleFromExemptItems: core.getInput('remove-stale-from-exempt-items') === 'true' + includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' }; for (const numberInput of ['days-before-stale']) { if (isNaN(parseFloat(core.getInput(numberInput)))) { diff --git a/src/classes/issue.spec.ts b/src/classes/issue.spec.ts index 07a49e398..977b767cc 100644 --- a/src/classes/issue.spec.ts +++ b/src/classes/issue.spec.ts @@ -63,8 +63,7 @@ describe('Issue', (): void => { ignorePrUpdates: undefined, exemptDraftPr: false, closeIssueReason: '', - includeOnlyAssigned: false, - removeStaleFromExemptItems: false + includeOnlyAssigned: false }; issueInterface = { title: 'dummy-title', diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 0cf2d8fdd..fb399254c 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -326,35 +326,22 @@ export class IssuesProcessor { issueLogger.info(`This $$type does not include a stale label`); } - const exemptLabels: string[] = wordsToList( - issue.isPullRequest - ? this.options.exemptPrLabels - : this.options.exemptIssueLabels - ); + const isExemptPr = issue.isPullRequest + ? this.options.exemptPrLabels + : this.options.exemptIssueLabels; + + const exemptLabels: string[] = wordsToList(isExemptPr); const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly) => isLabeled(issue, exemptLabel) ); - const isRemoveStaleFromExemptItemEnabled = - this._removeStaleFromExemptItems(hasExemptLabel); - if (hasExemptLabel) { - // Determine whether we want to manage an exempt item - const isIssueStale = - isRemoveStaleFromExemptItemEnabled && - (await this._isIssueStale(issue, staleLabel, staleMessage)); - - if (isIssueStale) { - issueLogger.info( - `The option ${issueLogger.createOptionLink( - Option.RemoveStaleFromExemptItem - )} is enabled, this $$type is no longer stale` - ); - - await this._removeStaleLabel(issue, staleLabel); - } - issueLogger.info(`Skipping this $$type because it has an exempt label`); + issueLogger.info( + `Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink( + isExemptPr ? Option.ExemptPrLabels : Option.ExemptIssueLabels + )} for more details` + ); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues } @@ -1042,10 +1029,6 @@ export class IssuesProcessor { return this.options.includeOnlyAssigned && !issue.hasAssignees; } - private _removeStaleFromExemptItems(hasExemptLabel: boolean) { - return this.options.removeStaleFromExemptItems && hasExemptLabel; - } - private _getAnyOfLabels(issue: Issue): string { if (issue.isPullRequest) { if (this.options.anyOfPrLabels !== '') { @@ -1244,43 +1227,4 @@ export class IssuesProcessor { return Option.RemoveStaleWhenUpdated; } - - /** - * Checks to see if there has been activity on an item after the item was marked stale - * This consumes 2 operations, one to fetch when the item was marked stale, - * and one to fetch the comments on that item - */ - private async _isIssueStale( - issue: Issue, - staleLabel: string, - staleMessage: string - ): Promise { - if (issue.isStale) { - const markedStaleOn = - (await this.getLabelCreationDate(issue, staleLabel)) || - issue.updated_at; - - const issueHasCommentsSinceStale = await this._hasCommentsSince( - issue, - markedStaleOn, - staleMessage - ); - - const shouldRemoveStaleWhenUpdated = - this._shouldRemoveStaleWhenUpdated(issue); - - const issueHasUpdateSinceStale = isDateMoreRecentThan( - new Date(issue.updated_at), - new Date(markedStaleOn), - 15 - ); - - return ( - shouldRemoveStaleWhenUpdated && - (issueHasUpdateSinceStale || issueHasCommentsSinceStale) - ); - } - - return false; - } } diff --git a/src/enums/option.ts b/src/enums/option.ts index 41d85d60d..38cfb193d 100644 --- a/src/enums/option.ts +++ b/src/enums/option.ts @@ -47,6 +47,5 @@ export enum Option { IgnoreIssueUpdates = 'ignore-issue-updates', IgnorePrUpdates = 'ignore-pr-updates', ExemptDraftPr = 'exempt-draft-pr', - CloseIssueReason = 'close-issue-reason', - RemoveStaleFromExemptItem = 'remove-stale-from-exempt-item' + CloseIssueReason = 'close-issue-reason' } diff --git a/src/interfaces/issues-processor-options.ts b/src/interfaces/issues-processor-options.ts index 37e0dc2cf..b056a28c6 100644 --- a/src/interfaces/issues-processor-options.ts +++ b/src/interfaces/issues-processor-options.ts @@ -53,5 +53,4 @@ export interface IIssuesProcessorOptions { exemptDraftPr: boolean; closeIssueReason: string; includeOnlyAssigned: boolean; - removeStaleFromExemptItems: boolean; } diff --git a/src/main.ts b/src/main.ts index 3ff91884f..1045d6c57 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,9 +89,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions { ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), exemptDraftPr: core.getInput('exempt-draft-pr') === 'true', closeIssueReason: core.getInput('close-issue-reason'), - includeOnlyAssigned: core.getInput('include-only-assigned') === 'true', - removeStaleFromExemptItems: - core.getInput('remove-stale-from-exempt-items') === 'true' + includeOnlyAssigned: core.getInput('include-only-assigned') === 'true' }; for (const numberInput of ['days-before-stale']) { From 2025b8ab61fd819e417fad16061f40fd26225e10 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:42:33 +0000 Subject: [PATCH 5/6] update logging --- dist/index.js | 7 ++----- src/classes/issues-processor.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7e19918b6..9524dfd29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -528,13 +528,10 @@ class IssuesProcessor { else { issueLogger.info(`This $$type does not include a stale label`); } - const isExemptPr = issue.isPullRequest - ? this.options.exemptPrLabels - : this.options.exemptIssueLabels; - const exemptLabels = words_to_list_1.wordsToList(isExemptPr); + const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest ? this.options.exemptPrLabels : this.options.exemptIssueLabels); const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel)); if (hasExemptLabel) { - issueLogger.info(`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(isExemptPr ? option_1.Option.ExemptPrLabels : option_1.Option.ExemptIssueLabels)} for more details`); + issueLogger.info(`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(issue.isPullRequest ? option_1.Option.ExemptPrLabels : option_1.Option.ExemptIssueLabels)} for more details`); IssuesProcessor._endIssueProcessing(issue); return; // Don't process exempt issues } diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index fb399254c..07aff68f9 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -326,11 +326,11 @@ export class IssuesProcessor { issueLogger.info(`This $$type does not include a stale label`); } - const isExemptPr = issue.isPullRequest - ? this.options.exemptPrLabels - : this.options.exemptIssueLabels; - - const exemptLabels: string[] = wordsToList(isExemptPr); + const exemptLabels: string[] = wordsToList( + issue.isPullRequest + ? this.options.exemptPrLabels + : this.options.exemptIssueLabels + ); const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly) => isLabeled(issue, exemptLabel) @@ -339,7 +339,7 @@ export class IssuesProcessor { if (hasExemptLabel) { issueLogger.info( `Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink( - isExemptPr ? Option.ExemptPrLabels : Option.ExemptIssueLabels + issue.isPullRequest ? Option.ExemptPrLabels : Option.ExemptIssueLabels )} for more details` ); IssuesProcessor._endIssueProcessing(issue); From 79261bc4d2887b885558482ae6fe9e3ed5a2e7bd Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:35:03 +0000 Subject: [PATCH 6/6] bump dist --- dist/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 9524dfd29..f039f498e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -528,7 +528,9 @@ class IssuesProcessor { else { issueLogger.info(`This $$type does not include a stale label`); } - const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest ? this.options.exemptPrLabels : this.options.exemptIssueLabels); + const exemptLabels = words_to_list_1.wordsToList(issue.isPullRequest + ? this.options.exemptPrLabels + : this.options.exemptIssueLabels); const hasExemptLabel = exemptLabels.some((exemptLabel) => is_labeled_1.isLabeled(issue, exemptLabel)); if (hasExemptLabel) { issueLogger.info(`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(issue.isPullRequest ? option_1.Option.ExemptPrLabels : option_1.Option.ExemptIssueLabels)} for more details`);