Add rotten functionality

Add processRottenIssue
Add Options to support rotten issues
Update main.ts to process rotten related inputs
Update the Option enum to include rotten related variables
Update issue.ts to include function to get the rotten label
Add helper functions for rotten related options
This commit is contained in:
mviswanathsai 2024-02-27 17:53:19 +05:30
parent 3f3b0175e8
commit 9e2995bba5
No known key found for this signature in database
GPG Key ID: 87DE7BD64227C60A
9 changed files with 1976 additions and 1320 deletions

View File

@ -6,18 +6,25 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
repoToken: 'none', repoToken: 'none',
staleIssueMessage: 'This issue is stale', staleIssueMessage: 'This issue is stale',
stalePrMessage: 'This PR is stale', stalePrMessage: 'This PR is stale',
rottenIssueMessage: 'This issue is rotten',
rottenPrMessage: 'This PR is rotten',
closeIssueMessage: 'This issue is being closed', closeIssueMessage: 'This issue is being closed',
closePrMessage: 'This PR is being closed', closePrMessage: 'This PR is being closed',
daysBeforeStale: 1, daysBeforeStale: 1,
daysBeforeRotten: 0,
daysBeforeIssueStale: NaN, daysBeforeIssueStale: NaN,
daysBeforePrStale: NaN, daysBeforePrStale: NaN,
daysBeforeIssueRotten: NaN,
daysBeforePrRotten: NaN,
daysBeforeClose: 30, daysBeforeClose: 30,
daysBeforeIssueClose: NaN, daysBeforeIssueClose: NaN,
daysBeforePrClose: NaN, daysBeforePrClose: NaN,
staleIssueLabel: 'Stale', staleIssueLabel: 'Stale',
rottenIssueLabel: 'Rotten',
closeIssueLabel: '', closeIssueLabel: '',
exemptIssueLabels: '', exemptIssueLabels: '',
stalePrLabel: 'Stale', stalePrLabel: 'Stale',
rottenPrLabel: 'Rotten',
closePrLabel: '', closePrLabel: '',
exemptPrLabels: '', exemptPrLabels: '',
onlyLabels: '', onlyLabels: '',
@ -31,6 +38,9 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeStaleWhenUpdated: false, removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined, removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined, removePrStaleWhenUpdated: undefined,
removeRottenWhenUpdated: false,
removeIssueRottenWhenUpdated: undefined,
removePrRottenWhenUpdated: undefined,
ascending: false, ascending: false,
deleteBranch: false, deleteBranch: false,
startDate: '', startDate: '',
@ -50,6 +60,9 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
labelsToRemoveWhenStale: '', labelsToRemoveWhenStale: '',
labelsToRemoveWhenUnstale: '', labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '', labelsToAddWhenUnstale: '',
labelsToRemoveWhenRotten: '',
labelsToRemoveWhenUnrotten: '',
labelsToAddWhenUnrotten: '',
ignoreUpdates: false, ignoreUpdates: false,
ignoreIssueUpdates: undefined, ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined, ignorePrUpdates: undefined,

View File

@ -159,11 +159,12 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
}); });
test('processing an issue with no label and a start date as ISO 8601 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => { test('processing an issue with no label and a start date as ISO 8601 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => {
expect.assertions(2); expect.assertions(3);
const january2000 = '2000-01-01T00:00:00Z'; const january2000 = '2000-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = { const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions, ...DefaultProcessorOptions,
daysBeforeClose: 0, daysBeforeClose: 0,
daysBeforeRotten: 0,
startDate: january2000.toString() startDate: january2000.toString()
}; };
const TestIssueList: Issue[] = [ const TestIssueList: Issue[] = [
@ -187,6 +188,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
await processor.processIssues(1); await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(1); expect(processor.staleIssues.length).toStrictEqual(1);
expect(processor.rottenIssues.length).toStrictEqual(1);
expect(processor.closedIssues.length).toStrictEqual(1); expect(processor.closedIssues.length).toStrictEqual(1);
}); });
@ -222,6 +224,39 @@ test('processing an issue with no label and a start date as ISO 8601 being after
expect(processor.closedIssues.length).toStrictEqual(0); expect(processor.closedIssues.length).toStrictEqual(0);
}); });
test('processing an issue with no label and a start date as ISO 8601 being after the issue creation date will not make it stale , rotten or close it when it is old enough and days-before-close is set to 0', async () => {
expect.assertions(3);
const january2021 = '2021-01-01T00:00:00Z';
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeClose: 0,
startDate: january2021.toString()
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z'
)
];
const processor = new IssuesProcessorMock(
opts,
alwaysFalseStateMock,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(0);
expect(processor.rottenIssues.length).toStrictEqual(0);
expect(processor.closedIssues.length).toStrictEqual(0);
});
test('processing an issue with no label and a start date as RFC 2822 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => { test('processing an issue with no label and a start date as RFC 2822 being before the issue creation date will make it stale and close it when it is old enough and days-before-close is set to 0', async () => {
expect.assertions(2); expect.assertions(2);
const january2000 = 'January 1, 2000 00:00:00'; const january2000 = 'January 1, 2000 00:00:00';
@ -290,6 +325,7 @@ test('processing an issue with no label will make it stale and close it, if it i
const opts: IIssuesProcessorOptions = { const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions, ...DefaultProcessorOptions,
daysBeforeClose: 1, daysBeforeClose: 1,
daysBeforeRotten: 0,
daysBeforeIssueClose: 0 daysBeforeIssueClose: 0
}; };
const TestIssueList: Issue[] = [ const TestIssueList: Issue[] = [
@ -307,6 +343,7 @@ test('processing an issue with no label will make it stale and close it, if it i
await processor.processIssues(1); await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1); expect(processor.staleIssues).toHaveLength(1);
expect(processor.rottenIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(1); expect(processor.closedIssues).toHaveLength(1);
expect(processor.deletedBranchIssues).toHaveLength(0); expect(processor.deletedBranchIssues).toHaveLength(0);
}); });
@ -488,6 +525,7 @@ test('processing a stale issue will close it', async () => {
await processor.processIssues(1); await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(0); expect(processor.staleIssues).toHaveLength(0);
expect(processor.rottenIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(1); expect(processor.closedIssues).toHaveLength(1);
}); });

View File

@ -1,6 +1,6 @@
name: 'Close Stale Issues' name: 'Close, Rotten and Stale Issues'
description: 'Close issues and pull requests with no recent activity' description: 'Close issues and pull requests with no recent activity'
author: 'GitHub' author: 'M Viswanath Sai'
inputs: inputs:
repo-token: repo-token:
description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.' description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.'
@ -12,6 +12,12 @@ inputs:
stale-pr-message: stale-pr-message:
description: 'The message to post on the pull request when tagging it. If none provided, will not mark pull requests stale.' description: 'The message to post on the pull request when tagging it. If none provided, will not mark pull requests stale.'
required: false required: false
rotten-issue-message:
description: 'The message to post on the issue when tagging it. If none provided, will not mark issues rotten.'
required: false
rotten-pr-message:
description: 'The message to post on the pull request when tagging it. If none provided, will not mark pull requests rotten.'
required: false
close-issue-message: close-issue-message:
description: 'The message to post on the issue when closing it. If none provided, will not comment when closing an issue.' description: 'The message to post on the issue when closing it. If none provided, will not comment when closing an issue.'
required: false required: false
@ -21,17 +27,27 @@ inputs:
days-before-stale: days-before-stale:
description: 'The number of days old an issue or a pull request can be before marking it stale. Set to -1 to never mark issues or pull requests as stale automatically.' description: 'The number of days old an issue or a pull request can be before marking it stale. Set to -1 to never mark issues or pull requests as stale automatically.'
required: false required: false
default: '60' default: '90'
days-before-issue-stale: days-before-issue-stale:
description: 'The number of days old an issue can be before marking it stale. Set to -1 to never mark issues as stale automatically. Override "days-before-stale" option regarding only the issues.' description: 'The number of days old an issue can be before marking it stale. Set to -1 to never mark issues as stale automatically. Override "days-before-stale" option regarding only the issues.'
required: false required: false
days-before-pr-stale: days-before-pr-stale:
description: 'The number of days old a pull request can be before marking it stale. Set to -1 to never mark pull requests as stale automatically. Override "days-before-stale" option regarding only the pull requests.' description: 'The number of days old a pull request can be before marking it stale. Set to -1 to never mark pull requests as stale automatically. Override "days-before-stale" option regarding only the pull requests.'
required: false required: false
days-before-rotten:
description: 'The number of days old an issue or a pull request can be before marking it rotten. Set to -1 to never mark issues or pull requests as rotten automatically.'
required: false
default: '30'
days-before-issue-rotten:
description: 'The number of days old an issue can be before marking it rotten. Set to -1 to never mark issues as rotten automatically. Override "days-before-rotten" option regarding only the issues.'
required: false
days-before-pr-rotten:
description: 'The number of days old a pull request can be before marking it rotten. Set to -1 to never mark pull requests as rotten automatically. Override "days-before-rotten" option regarding only the pull requests.'
required: false
days-before-close: days-before-close:
description: 'The number of days to wait to close an issue or a pull request after it being marked stale. Set to -1 to never close stale issues or pull requests.' description: 'The number of days to wait to close an issue or a pull request after it being marked stale. Set to -1 to never close stale issues or pull requests.'
required: false required: false
default: '7' default: '30'
days-before-issue-close: days-before-issue-close:
description: 'The number of days to wait to close an issue after it being marked stale. Set to -1 to never close stale issues. Override "days-before-close" option regarding only the issues.' description: 'The number of days to wait to close an issue after it being marked stale. Set to -1 to never close stale issues. Override "days-before-close" option regarding only the issues.'
required: false required: false
@ -42,6 +58,10 @@ inputs:
description: 'The label to apply when an issue is stale.' description: 'The label to apply when an issue is stale.'
required: false required: false
default: 'Stale' default: 'Stale'
rotten-issue-label:
description: 'The label to apply when an issue is rotten.'
required: false
default: 'Rotten'
close-issue-label: close-issue-label:
description: 'The label to apply when an issue is closed.' description: 'The label to apply when an issue is closed.'
required: false required: false
@ -57,6 +77,10 @@ inputs:
description: 'The label to apply when a pull request is stale.' description: 'The label to apply when a pull request is stale.'
default: 'Stale' default: 'Stale'
required: false required: false
rotten-pr-label:
description: 'The label to apply when a pull request is rotten.'
default: 'Rotten'
required: false
close-pr-label: close-pr-label:
description: 'The label to apply when a pull request is closed.' description: 'The label to apply when a pull request is closed.'
required: false required: false
@ -128,6 +152,18 @@ inputs:
description: 'Remove stale labels from pull requests when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the pull requests.' description: 'Remove stale labels from pull requests when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the pull requests.'
default: '' default: ''
required: false required: false
remove-rotten-when-updated:
description: 'Remove rotten labels from issues and pull requests when they are updated or commented on.'
default: 'true'
required: false
remove-issue-rotten-when-updated:
description: 'Remove rotten labels from issues when they are updated or commented on. Override "remove-rotten-when-updated" option regarding only the issues.'
default: ''
required: false
remove-pr-rotten-when-updated:
description: 'Remove rotten labels from pull requests when they are updated or commented on. Override "remove-rotten-when-updated" option regarding only the pull requests.'
default: ''
required: false
debug-only: debug-only:
description: 'Run the processor in debug mode without actually performing any operations on live issues.' description: 'Run the processor in debug mode without actually performing any operations on live issues.'
default: 'false' default: 'false'
@ -188,6 +224,18 @@ inputs:
description: 'A comma delimited list of labels to remove when an issue or pull request becomes unstale.' description: 'A comma delimited list of labels to remove when an issue or pull request becomes unstale.'
default: '' default: ''
required: false required: false
labels-to-add-when-unrotten:
description: 'A comma delimited list of labels to add when an issue or pull request becomes unrotten.'
default: ''
required: false
labels-to-remove-when-rotten:
description: 'A comma delimited list of labels to remove when an issue or pull request becomes rotten.'
default: ''
required: false
labels-to-remove-when-unrotten:
description: 'A comma delimited list of labels to remove when an issue or pull request becomes unrotten.'
default: ''
required: false
ignore-updates: ignore-updates:
description: 'Any update (update/comment) can reset the stale idle time on the issues and pull requests.' description: 'Any update (update/comment) can reset the stale idle time on the issues and pull requests.'
default: 'false' default: 'false'

View File

@ -1,76 +1,88 @@
import {isLabeled} from '../functions/is-labeled'; import { isLabeled } from '../functions/is-labeled';
import {isPullRequest} from '../functions/is-pull-request'; import { isPullRequest } from '../functions/is-pull-request';
import {Assignee} from '../interfaces/assignee'; import { Assignee } from '../interfaces/assignee';
import {IIssue, OctokitIssue} from '../interfaces/issue'; import { IIssue, OctokitIssue } from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import { IIssuesProcessorOptions } from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label'; import { ILabel } from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone'; import { IMilestone } from '../interfaces/milestone';
import {IsoDateString} from '../types/iso-date-string'; import { IsoDateString } from '../types/iso-date-string';
import {Operations} from './operations'; import { Operations } from './operations';
export class Issue implements IIssue { export class Issue implements IIssue {
readonly title: string; readonly title: string;
readonly number: number; readonly number: number;
created_at: IsoDateString; created_at: IsoDateString;
updated_at: IsoDateString; updated_at: IsoDateString;
readonly draft: boolean; readonly draft: boolean;
readonly labels: ILabel[]; readonly labels: ILabel[];
readonly pull_request: object | null | undefined; readonly pull_request: object | null | undefined;
readonly state: string | 'closed' | 'open'; readonly state: string | 'closed' | 'open';
readonly locked: boolean; readonly locked: boolean;
readonly milestone?: IMilestone | null; readonly milestone?: IMilestone | null;
readonly assignees: Assignee[]; readonly assignees: Assignee[];
isStale: boolean; isStale: boolean;
markedStaleThisRun: boolean; isRotten: boolean;
operations = new Operations(); markedStaleThisRun: boolean;
private readonly _options: IIssuesProcessorOptions; markedRottenThisRun: boolean;
operations = new Operations();
private readonly _options: IIssuesProcessorOptions;
constructor( constructor(
options: Readonly<IIssuesProcessorOptions>, options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<OctokitIssue> | Readonly<IIssue> issue: Readonly<OctokitIssue> | Readonly<IIssue>
) { ) {
this._options = options; this._options = options;
this.title = issue.title; this.title = issue.title;
this.number = issue.number; this.number = issue.number;
this.created_at = issue.created_at; this.created_at = issue.created_at;
this.updated_at = issue.updated_at; this.updated_at = issue.updated_at;
this.draft = Boolean(issue.draft); this.draft = Boolean(issue.draft);
this.labels = mapLabels(issue.labels); this.labels = mapLabels(issue.labels);
this.pull_request = issue.pull_request; this.pull_request = issue.pull_request;
this.state = issue.state; this.state = issue.state;
this.locked = issue.locked; this.locked = issue.locked;
this.milestone = issue.milestone; this.milestone = issue.milestone;
this.assignees = issue.assignees || []; this.assignees = issue.assignees || [];
this.isStale = isLabeled(this, this.staleLabel); this.isStale = isLabeled(this, this.staleLabel);
this.markedStaleThisRun = false; this.isRotten = isLabeled(this, this.rottenLabel);
} this.markedStaleThisRun = false;
this.markedRottenThisRun = false;
}
get isPullRequest(): boolean { get isPullRequest(): boolean {
return isPullRequest(this); return isPullRequest(this);
} }
get staleLabel(): string { get staleLabel(): string {
return this._getStaleLabel(); return this._getStaleLabel();
} }
get rottenLabel(): string {
return this._getRottenLabel();
}
get hasAssignees(): boolean { get hasAssignees(): boolean {
return this.assignees.length > 0; return this.assignees.length > 0;
} }
private _getStaleLabel(): string { private _getStaleLabel(): string {
return this.isPullRequest return this.isPullRequest
? this._options.stalePrLabel ? this._options.stalePrLabel
: this._options.staleIssueLabel; : this._options.staleIssueLabel;
} }
private _getRottenLabel(): string {
return this.isPullRequest
? this._options.rottenPrLabel
: this._options.rottenIssueLabel;
}
} }
function mapLabels(labels: (string | ILabel)[] | ILabel[]): ILabel[] { function mapLabels(labels: (string | ILabel)[] | ILabel[]): ILabel[] {
return labels.map(label => { return labels.map(label => {
if (typeof label == 'string') { if (typeof label == 'string') {
return { return {
name: label name: label
}; };
} }
return label; return label;
}); });
} }

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,10 @@ export class Statistics {
stalePullRequestsCount = 0; stalePullRequestsCount = 0;
undoStaleIssuesCount = 0; undoStaleIssuesCount = 0;
undoStalePullRequestsCount = 0; undoStalePullRequestsCount = 0;
rottenIssuesCount = 0;
rottenPullRequestsCount = 0;
undoRottenIssuesCount = 0;
undoRottenPullRequestsCount = 0;
operationsCount = 0; operationsCount = 0;
closedIssuesCount = 0; closedIssuesCount = 0;
closedPullRequestsCount = 0; closedPullRequestsCount = 0;
@ -65,6 +69,18 @@ export class Statistics {
return this._incrementUndoStaleIssuesCount(increment); return this._incrementUndoStaleIssuesCount(increment);
} }
incrementUndoRottenItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementUndoRottenPullRequestsCount(increment);
}
return this._incrementUndoRottenIssuesCount(increment);
}
setOperationsCount(operationsCount: Readonly<number>): Statistics { setOperationsCount(operationsCount: Readonly<number>): Statistics {
this.operationsCount = operationsCount; this.operationsCount = operationsCount;
@ -222,6 +238,21 @@ export class Statistics {
return this; return this;
} }
private _incrementUndoRottenPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this.undoRottenPullRequestsCount += increment;
return this;
}
private _incrementUndoRottenIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this.undoRottenIssuesCount += increment;
return this;
}
private _incrementUndoStalePullRequestsCount( private _incrementUndoStalePullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {

View File

@ -2,18 +2,25 @@ export enum Option {
RepoToken = 'repo-token', RepoToken = 'repo-token',
StaleIssueMessage = 'stale-issue-message', StaleIssueMessage = 'stale-issue-message',
StalePrMessage = 'stale-pr-message', StalePrMessage = 'stale-pr-message',
RottenIssueMessage = 'rotten-issue-message',
RottenPrMessage = 'rotten-pr-message',
CloseIssueMessage = 'close-issue-message', CloseIssueMessage = 'close-issue-message',
ClosePrMessage = 'close-pr-message', ClosePrMessage = 'close-pr-message',
DaysBeforeStale = 'days-before-stale', DaysBeforeStale = 'days-before-stale',
DaysBeforeIssueStale = 'days-before-issue-stale', DaysBeforeIssueStale = 'days-before-issue-stale',
DaysBeforePrStale = 'days-before-pr-stale', DaysBeforePrStale = 'days-before-pr-stale',
DaysBeforeRotten = 'days-before-rotten',
DaysBeforeIssueRotten = 'days-before-issue-rotten',
DaysBeforePrRotten = 'days-before-pr-rotten',
DaysBeforeClose = 'days-before-close', DaysBeforeClose = 'days-before-close',
DaysBeforeIssueClose = 'days-before-issue-close', DaysBeforeIssueClose = 'days-before-issue-close',
DaysBeforePrClose = 'days-before-pr-close', DaysBeforePrClose = 'days-before-pr-close',
StaleIssueLabel = 'stale-issue-label', StaleIssueLabel = 'stale-issue-label',
RottenIssueLabel = 'rotten-issue-label',
CloseIssueLabel = 'close-issue-label', CloseIssueLabel = 'close-issue-label',
ExemptIssueLabels = 'exempt-issue-labels', ExemptIssueLabels = 'exempt-issue-labels',
StalePrLabel = 'stale-pr-label', StalePrLabel = 'stale-pr-label',
RottenPrLabel = 'rotten-pr-label',
ClosePrLabel = 'close-pr-label', ClosePrLabel = 'close-pr-label',
ExemptPrLabels = 'exempt-pr-labels', ExemptPrLabels = 'exempt-pr-labels',
OnlyLabels = 'only-labels', OnlyLabels = 'only-labels',
@ -24,6 +31,9 @@ export enum Option {
RemoveStaleWhenUpdated = 'remove-stale-when-updated', RemoveStaleWhenUpdated = 'remove-stale-when-updated',
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated', RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated', RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
RemoveRottenWhenUpdated = 'remove-rotten-when-updated',
RemoveIssueRottenWhenUpdated = 'remove-issue-rotten-when-updated',
RemovePrRottenWhenUpdated = 'remove-pr-rotten-when-updated',
DebugOnly = 'debug-only', DebugOnly = 'debug-only',
Ascending = 'ascending', Ascending = 'ascending',
DeleteBranch = 'delete-branch', DeleteBranch = 'delete-branch',
@ -44,6 +54,9 @@ export enum Option {
LabelsToRemoveWhenStale = 'labels-to-remove-when-stale', LabelsToRemoveWhenStale = 'labels-to-remove-when-stale',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale', LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale', LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
LabelsToRemoveWhenRotten = 'labels-to-remove-when-rotten',
LabelsToRemoveWhenUnrotten = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnrotten = 'labels-to-add-when-unstale',
IgnoreUpdates = 'ignore-updates', IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates', IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates', IgnorePrUpdates = 'ignore-pr-updates',

View File

@ -1,57 +1,70 @@
import {IsoOrRfcDateString} from '../types/iso-or-rfc-date-string'; import { IsoOrRfcDateString } from '../types/iso-or-rfc-date-string';
export interface IIssuesProcessorOptions { export interface IIssuesProcessorOptions {
repoToken: string; repoToken: string;
staleIssueMessage: string; staleIssueMessage: string;
stalePrMessage: string; stalePrMessage: string;
closeIssueMessage: string; rottenIssueMessage: string;
closePrMessage: string; rottenPrMessage: string;
daysBeforeStale: number; closeIssueMessage: string;
daysBeforeIssueStale: number; // Could be NaN closePrMessage: string;
daysBeforePrStale: number; // Could be NaN daysBeforeStale: number;
daysBeforeClose: number; daysBeforeIssueStale: number; // Could be NaN
daysBeforeIssueClose: number; // Could be NaN daysBeforePrStale: number; // Could be NaN
daysBeforePrClose: number; // Could be NaN daysBeforeRotten: number;
staleIssueLabel: string; daysBeforeIssueRotten: number; // Could be NaN
closeIssueLabel: string; daysBeforePrRotten: number; // Could be NaN
exemptIssueLabels: string; daysBeforeClose: number;
stalePrLabel: string; daysBeforeIssueClose: number; // Could be NaN
closePrLabel: string; daysBeforePrClose: number; // Could be NaN
exemptPrLabels: string; staleIssueLabel: string;
onlyLabels: string; rottenIssueLabel: string;
onlyIssueLabels: string; closeIssueLabel: string;
onlyPrLabels: string; exemptIssueLabels: string;
anyOfLabels: string; stalePrLabel: string;
anyOfIssueLabels: string; rottenPrLabel: string;
anyOfPrLabels: string; closePrLabel: string;
operationsPerRun: number; exemptPrLabels: string;
removeStaleWhenUpdated: boolean; onlyLabels: string;
removeIssueStaleWhenUpdated: boolean | undefined; onlyIssueLabels: string;
removePrStaleWhenUpdated: boolean | undefined; onlyPrLabels: string;
debugOnly: boolean; anyOfLabels: string;
ascending: boolean; anyOfIssueLabels: string;
deleteBranch: boolean; anyOfPrLabels: string;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822 operationsPerRun: number;
exemptMilestones: string; removeStaleWhenUpdated: boolean;
exemptIssueMilestones: string; removeIssueStaleWhenUpdated: boolean | undefined;
exemptPrMilestones: string; removePrStaleWhenUpdated: boolean | undefined;
exemptAllMilestones: boolean; removeRottenWhenUpdated: boolean;
exemptAllIssueMilestones: boolean | undefined; removeIssueRottenWhenUpdated: boolean | undefined;
exemptAllPrMilestones: boolean | undefined; removePrRottenWhenUpdated: boolean | undefined;
exemptAssignees: string; debugOnly: boolean;
exemptIssueAssignees: string; ascending: boolean;
exemptPrAssignees: string; deleteBranch: boolean;
exemptAllAssignees: boolean; startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptAllIssueAssignees: boolean | undefined; exemptMilestones: string;
exemptAllPrAssignees: boolean | undefined; exemptIssueMilestones: string;
enableStatistics: boolean; exemptPrMilestones: string;
labelsToRemoveWhenStale: string; exemptAllMilestones: boolean;
labelsToRemoveWhenUnstale: string; exemptAllIssueMilestones: boolean | undefined;
labelsToAddWhenUnstale: string; exemptAllPrMilestones: boolean | undefined;
ignoreUpdates: boolean; exemptAssignees: string;
ignoreIssueUpdates: boolean | undefined; exemptIssueAssignees: string;
ignorePrUpdates: boolean | undefined; exemptPrAssignees: string;
exemptDraftPr: boolean; exemptAllAssignees: boolean;
closeIssueReason: string; exemptAllIssueAssignees: boolean | undefined;
includeOnlyAssigned: boolean; exemptAllPrAssignees: boolean | undefined;
enableStatistics: boolean;
labelsToRemoveWhenStale: string;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
labelsToRemoveWhenRotten: string;
labelsToRemoveWhenUnrotten: string;
labelsToAddWhenUnrotten: string;
ignoreUpdates: boolean;
ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined;
exemptDraftPr: boolean;
closeIssueReason: string;
includeOnlyAssigned: boolean;
} }

View File

@ -46,6 +46,7 @@ async function _run(): Promise<void> {
await processOutput( await processOutput(
issueProcessor.staleIssues, issueProcessor.staleIssues,
issueProcessor.rottenIssues,
issueProcessor.closedIssues issueProcessor.closedIssues
); );
} catch (error) { } catch (error) {
@ -59,22 +60,31 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
repoToken: core.getInput('repo-token'), repoToken: core.getInput('repo-token'),
staleIssueMessage: core.getInput('stale-issue-message'), staleIssueMessage: core.getInput('stale-issue-message'),
stalePrMessage: core.getInput('stale-pr-message'), stalePrMessage: core.getInput('stale-pr-message'),
rottenIssueMessage: core.getInput('rotten-issue-message'),
rottenPrMessage: core.getInput('rotten-pr-message'),
closeIssueMessage: core.getInput('close-issue-message'), closeIssueMessage: core.getInput('close-issue-message'),
closePrMessage: core.getInput('close-pr-message'), closePrMessage: core.getInput('close-pr-message'),
daysBeforeStale: parseFloat( daysBeforeStale: parseFloat(
core.getInput('days-before-stale', {required: true}) core.getInput('days-before-stale', {required: true})
), ),
daysBeforeRotten: parseFloat(
core.getInput('days-before-rotten', {required: true})
),
daysBeforeIssueStale: parseFloat(core.getInput('days-before-issue-stale')), daysBeforeIssueStale: parseFloat(core.getInput('days-before-issue-stale')),
daysBeforePrStale: parseFloat(core.getInput('days-before-pr-stale')), daysBeforePrStale: parseFloat(core.getInput('days-before-pr-stale')),
daysBeforeIssueRotten: parseFloat(core.getInput('days-before-issue-rotten')),
daysBeforePrRotten: parseFloat(core.getInput('days-before-pr-rotten')),
daysBeforeClose: parseInt( daysBeforeClose: parseInt(
core.getInput('days-before-close', {required: true}) core.getInput('days-before-close', {required: true})
), ),
daysBeforeIssueClose: parseInt(core.getInput('days-before-issue-close')), daysBeforeIssueClose: parseInt(core.getInput('days-before-issue-close')),
daysBeforePrClose: parseInt(core.getInput('days-before-pr-close')), daysBeforePrClose: parseInt(core.getInput('days-before-pr-close')),
staleIssueLabel: core.getInput('stale-issue-label', {required: true}), staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
rottenIssueLabel: core.getInput('rotten-issue-label', {required: true}),
closeIssueLabel: core.getInput('close-issue-label'), closeIssueLabel: core.getInput('close-issue-label'),
exemptIssueLabels: core.getInput('exempt-issue-labels'), exemptIssueLabels: core.getInput('exempt-issue-labels'),
stalePrLabel: core.getInput('stale-pr-label', {required: true}), stalePrLabel: core.getInput('stale-pr-label', {required: true}),
rottenPrLabel: core.getInput('rotten-pr-label', {required: true}),
closePrLabel: core.getInput('close-pr-label'), closePrLabel: core.getInput('close-pr-label'),
exemptPrLabels: core.getInput('exempt-pr-labels'), exemptPrLabels: core.getInput('exempt-pr-labels'),
onlyLabels: core.getInput('only-labels'), onlyLabels: core.getInput('only-labels'),
@ -95,6 +105,15 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
removePrStaleWhenUpdated: _toOptionalBoolean( removePrStaleWhenUpdated: _toOptionalBoolean(
'remove-pr-stale-when-updated' 'remove-pr-stale-when-updated'
), ),
removeRottenWhenUpdated: !(
core.getInput('remove-rotten-when-updated') === 'false'
),
removeIssueRottenWhenUpdated: _toOptionalBoolean(
'remove-issue-rotten-when-updated'
),
removePrRottenWhenUpdated: _toOptionalBoolean(
'remove-pr-rotten-when-updated'
),
debugOnly: core.getInput('debug-only') === 'true', debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true', ascending: core.getInput('ascending') === 'true',
deleteBranch: core.getInput('delete-branch') === 'true', deleteBranch: core.getInput('delete-branch') === 'true',
@ -118,6 +137,9 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
labelsToRemoveWhenStale: core.getInput('labels-to-remove-when-stale'), labelsToRemoveWhenStale: core.getInput('labels-to-remove-when-stale'),
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'), labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'), labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
labelsToRemoveWhenRotten: core.getInput('labels-to-remove-when-rotten'),
labelsToRemoveWhenUnrotten: core.getInput('labels-to-remove-when-unrotten'),
labelsToAddWhenUnrotten: core.getInput('labels-to-add-when-unrotten'),
ignoreUpdates: core.getInput('ignore-updates') === 'true', ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'), ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'), ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
@ -133,6 +155,13 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
throw new Error(errorMessage); throw new Error(errorMessage);
} }
} }
for (const numberInput of ['days-before-rotten']) {
if (isNaN(parseFloat(core.getInput(numberInput)))) {
const errorMessage = `Option "${numberInput}" did not parse to a valid float`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
}
}
for (const numberInput of ['days-before-close', 'operations-per-run']) { for (const numberInput of ['days-before-close', 'operations-per-run']) {
if (isNaN(parseInt(core.getInput(numberInput)))) { if (isNaN(parseInt(core.getInput(numberInput)))) {
@ -167,9 +196,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
async function processOutput( async function processOutput(
staledIssues: Issue[], staledIssues: Issue[],
rottenIssues: Issue[],
closedIssues: Issue[] closedIssues: Issue[]
): Promise<void> { ): Promise<void> {
core.setOutput('staled-issues-prs', JSON.stringify(staledIssues)); core.setOutput('staled-issues-prs', JSON.stringify(staledIssues));
core.setOutput('rotten-issues-prs', JSON.stringify(rottenIssues));
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
} }