Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option labels-to-remove-when-stale #771

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Every argument is optional.
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
| [labels-to-remove-when-stale](#labels-to-remove-when-stale) | Remove specified labels from issues/PRs when they become stale | |
| [debug-only](#debug-only) | Dry-run | `false` |
| [ascending](#ascending) | Order to get issues/PRs | `false` |
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
Expand Down Expand Up @@ -362,6 +363,15 @@ Warning: each label results in a unique API call which can drastically consume t
Default value: unset
Required Permission: `pull-requests: write`

#### labels-to-remove-when-stale

A comma delimited list of labels to remove from an issue or pull request when the stale workflow marks it automatically as stale with a label.

Warning: each label results in a unique API call which can drastically consume the limit of [operations-per-run](#operations-per-run).

Default value: unset
Required Permission: `pull-requests: write`

#### debug-only

Run the stale workflow as dry-run.
Expand Down
1 change: 1 addition & 0 deletions __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
enableStatistics: true,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
labelsToRemoveWhenStale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ inputs:
description: 'A comma delimited list of labels to remove when a stale issue or pull request receives activity and has the stale-issue-label or stale-pr-label removed from it.'
default: ''
required: false
labels-to-remove-when-stale:
description: 'A comma delimited list of labels to remove from an issue or pull request when the stale workflow marks it automatically as stale with a label.'
default: ''
required: false
ignore-updates:
description: 'Any update (update/comment) can reset the stale idle time on the issues and pull requests.'
default: 'false'
Expand Down
1 change: 1 addition & 0 deletions src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Issue', (): void => {
enableStatistics: false,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
labelsToRemoveWhenStale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
Expand Down
24 changes: 15 additions & 9 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export class IssuesProcessor {
const labelsToRemoveWhenUnstale: string[] = wordsToList(
this.options.labelsToRemoveWhenUnstale
);
const labelsToRemoveWhenStale: string[] = wordsToList(
this.options.labelsToRemoveWhenStale
);

for (const issue of issues.values()) {
// Stop the processing if no more operations remains
Expand All @@ -140,7 +143,8 @@ export class IssuesProcessor {
await this.processIssue(
issue,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale
labelsToRemoveWhenUnstale,
labelsToRemoveWhenStale
);
});
}
Expand Down Expand Up @@ -178,7 +182,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);

Expand Down Expand Up @@ -463,7 +468,7 @@ export class IssuesProcessor {
this._getDaysBeforeStaleUsedOptionName(issue)
)} (${LoggerService.cyan(daysBeforeStale)})`
);
await this._markStale(issue, staleMessage, staleLabel, skipMessage);
await this._markStale(issue, staleMessage, staleLabel, labelsToRemoveWhenStale, skipMessage);
issue.isStale = true; // This issue is now considered stale
issue.markedStaleThisRun = true;
issueLogger.info(`This $$type is now stale`);
Expand Down Expand Up @@ -683,7 +688,7 @@ 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._removeLabels(issue, labelsToRemoveWhenUnstale, Option.LabelsToRemoveWhenUnstale);
await this._addLabelsWhenUnstale(issue, labelsToAddWhenUnstale);

issueLogger.info(`Skipping the process since the $$type is now un-stale`);
Expand Down Expand Up @@ -760,6 +765,7 @@ export class IssuesProcessor {
issue: Issue,
staleMessage: string,
staleLabel: string,
labelsToRemoveWhenStale: Readonly<string>[],
skipMessage: boolean
): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
Expand Down Expand Up @@ -802,6 +808,7 @@ export class IssuesProcessor {
issue_number: issue.number,
labels: [staleLabel]
});
await this._removeLabels(issue, labelsToRemoveWhenStale, Option.LabelsToRemoveWhenStale);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the behavior if we attempt to remove a label that isn't currently on the issue/PR? Does it block others from being removed? Or does it no-op and move on?

}
} catch (error) {
issueLogger.error(`Error when adding a label: ${error.message}`);
Expand Down Expand Up @@ -1029,9 +1036,10 @@ export class IssuesProcessor {
return this.options.removeStaleWhenUpdated;
}

private async _removeLabelsWhenUnstale(
private async _removeLabels(
issue: Issue,
removeLabels: Readonly<string>[]
removeLabels: Readonly<string>[],
option: Readonly<Option>
): Promise<void> {
if (!removeLabels.length) {
return;
Expand All @@ -1040,9 +1048,7 @@ export class IssuesProcessor {
const issueLogger: IssueLogger = new IssueLogger(issue);

issueLogger.info(
`Removing all the labels specified via the ${this._logger.createOptionLink(
Option.LabelsToRemoveWhenUnstale
)} option.`
`Removing all the labels specified via the ${this._logger.createOptionLink(option)} option.`
);

for (const label of removeLabels.values()) {
Expand Down
1 change: 1 addition & 0 deletions src/enums/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export enum Option {
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
LabelsToRemoveWhenStale = 'labels-to-remove-when-stale',
IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates',
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/issues-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface IIssuesProcessorOptions {
enableStatistics: boolean;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
labelsToRemoveWhenStale: string;
ignoreUpdates: boolean;
ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
labelsToRemoveWhenStale: core.getInput('labels-to-remove-when-stale'),
ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
Expand Down