Skip to content

Commit

Permalink
undo remove-stale-from-exempt-items and tweak some of the existing lo…
Browse files Browse the repository at this point in the history
…gging
  • Loading branch information
johnsudol committed Dec 15, 2022
1 parent 0cd4aef commit 330059b
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 208 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions __tests__/constants/default-processor-options.ts
Expand Up @@ -54,6 +54,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: 'not_planned',
includeOnlyAssigned: false,
removeStaleFromExemptItems: false
includeOnlyAssigned: false
});
85 changes: 0 additions & 85 deletions __tests__/main.spec.ts
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions action.yml
Expand Up @@ -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.'
Expand Down
41 changes: 5 additions & 36 deletions dist/index.js
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = {}));


Expand Down Expand Up @@ -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)))) {
Expand Down
3 changes: 1 addition & 2 deletions src/classes/issue.spec.ts
Expand Up @@ -63,8 +63,7 @@ describe('Issue', (): void => {
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: '',
includeOnlyAssigned: false,
removeStaleFromExemptItems: false
includeOnlyAssigned: false
};
issueInterface = {
title: 'dummy-title',
Expand Down
76 changes: 10 additions & 66 deletions src/classes/issues-processor.ts
Expand Up @@ -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<string>) =>
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
}
Expand Down Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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<boolean> {
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;
}
}
3 changes: 1 addition & 2 deletions src/enums/option.ts
Expand Up @@ -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'
}
1 change: 0 additions & 1 deletion src/interfaces/issues-processor-options.ts
Expand Up @@ -53,5 +53,4 @@ export interface IIssuesProcessorOptions {
exemptDraftPr: boolean;
closeIssueReason: string;
includeOnlyAssigned: boolean;
removeStaleFromExemptItems: boolean;
}
4 changes: 1 addition & 3 deletions src/main.ts
Expand Up @@ -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']) {
Expand Down

0 comments on commit 330059b

Please sign in to comment.