Remove labels on stale (#959)

This commit is contained in:
Milos Pantic
2023-03-21 13:11:19 +00:00
committed by GitHub
parent 01aa53266c
commit 75d4d955ac
11 changed files with 1398 additions and 1315 deletions

View File

@@ -56,6 +56,7 @@ describe('Issue', (): void => {
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: false,
labelsToRemoveWhenStale: '',
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
ignoreUpdates: false,

View File

@@ -123,6 +123,10 @@ export class IssuesProcessor {
);
}
const labelsToRemoveWhenStale: string[] = wordsToList(
this.options.labelsToRemoveWhenStale
);
const labelsToAddWhenUnstale: string[] = wordsToList(
this.options.labelsToAddWhenUnstale
);
@@ -141,7 +145,8 @@ export class IssuesProcessor {
await this.processIssue(
issue,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale
labelsToRemoveWhenUnstale,
labelsToRemoveWhenStale
);
});
}
@@ -179,7 +184,8 @@ export class IssuesProcessor {
async processIssue(
issue: Issue,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[]
labelsToRemoveWhenUnstale: Readonly<string>[],
labelsToRemoveWhenStale: Readonly<string>[]
): Promise<void> {
this.statistics?.incrementProcessedItemsCount(issue);
@@ -509,6 +515,7 @@ export class IssuesProcessor {
staleMessage,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale,
labelsToRemoveWhenStale,
closeMessage,
closeLabel
);
@@ -623,6 +630,7 @@ export class IssuesProcessor {
staleMessage: string,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[],
labelsToRemoveWhenStale: Readonly<string>[],
closeMessage?: string,
closeLabel?: string
) {
@@ -671,6 +679,11 @@ export class IssuesProcessor {
if (issue.markedStaleThisRun) {
issueLogger.info(`marked stale this run, so don't check for updates`);
await this._removeLabelsOnStatusTransition(
issue,
labelsToRemoveWhenStale,
Option.LabelsToRemoveWhenStale
);
}
// The issue.updated_at and markedStaleOn are not always exactly in sync (they can be off by a second or 2)
@@ -699,7 +712,11 @@ export class IssuesProcessor {
await this._removeStaleLabel(issue, staleLabel);
// Are there labels to remove or add when an issue is no longer stale?
await this._removeLabelsWhenUnstale(issue, labelsToRemoveWhenUnstale);
await this._removeLabelsOnStatusTransition(
issue,
labelsToRemoveWhenUnstale,
Option.LabelsToRemoveWhenUnstale
);
await this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
@@ -1074,9 +1091,10 @@ export class IssuesProcessor {
return this.options.removeStaleWhenUpdated;
}
private async _removeLabelsWhenUnstale(
private async _removeLabelsOnStatusTransition(
issue: Issue,
removeLabels: Readonly<string>[]
removeLabels: Readonly<string>[],
staleStatus: Option
): Promise<void> {
if (!removeLabels.length) {
return;
@@ -1086,7 +1104,7 @@ export class IssuesProcessor {
issueLogger.info(
`Removing all the labels specified via the ${this._logger.createOptionLink(
Option.LabelsToRemoveWhenUnstale
staleStatus
)} option.`
);

View File

@@ -41,6 +41,7 @@ export enum Option {
ExemptAllIssueAssignees = 'exempt-all-issue-assignees',
ExemptAllPrAssignees = 'exempt-all-pr-assignees',
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenStale = 'labels-to-remove-when-stale',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
IgnoreUpdates = 'ignore-updates',

View File

@@ -45,6 +45,7 @@ export interface IIssuesProcessorOptions {
exemptAllIssueAssignees: boolean | undefined;
exemptAllPrAssignees: boolean | undefined;
enableStatistics: boolean;
labelsToRemoveWhenStale: string;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
ignoreUpdates: boolean;

View File

@@ -82,6 +82,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'),
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenStale: core.getInput('labels-to-remove-when-stale'),
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
ignoreUpdates: core.getInput('ignore-updates') === 'true',