feat: remove the remove-stale-when-updated option

BREAKING CHANGE:
The option remove-stale-when-updated was removed
This commit is contained in:
TESTELIN Geoffrey
2021-10-08 21:30:39 +02:00
parent bab816b473
commit b9a40762bf
11 changed files with 361 additions and 753 deletions

View File

@@ -30,9 +30,8 @@ describe('Issue', (): void => {
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 0,
removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
removeIssueStaleWhenUpdated: false,
removePrStaleWhenUpdated: false,
repoToken: '',
staleIssueMessage: '',
stalePrMessage: '',

View File

@@ -7,7 +7,6 @@ import {cleanLabel} from '../functions/clean-label';
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
import {isValidDate} from '../functions/dates/is-valid-date';
import {isBoolean} from '../functions/is-boolean';
import {isLabeled} from '../functions/is-labeled';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list';
@@ -660,7 +659,7 @@ export class IssuesProcessor {
issueLogger.info(
`The option ${issueLogger.createOptionLink(
this._getRemoveStaleWhenUpdatedUsedOptionName(issue)
IssuesProcessor._getRemoveStaleWhenUpdatedUsedOptionName(issue)
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenUpdated)}`
);
@@ -974,19 +973,9 @@ export class IssuesProcessor {
}
private _shouldRemoveStaleWhenUpdated(issue: Issue): boolean {
if (issue.isPullRequest) {
if (isBoolean(this.options.removePrStaleWhenUpdated)) {
return this.options.removePrStaleWhenUpdated;
}
return this.options.removeStaleWhenUpdated;
}
if (isBoolean(this.options.removeIssueStaleWhenUpdated)) {
return this.options.removeIssueStaleWhenUpdated;
}
return this.options.removeStaleWhenUpdated;
return issue.isPullRequest
? this.options.removePrStaleWhenUpdated
: this.options.removeIssueStaleWhenUpdated;
}
private async _removeLabelsWhenUnstale(
@@ -1113,29 +1102,16 @@ export class IssuesProcessor {
: Option.DaysBeforeIssueStale;
}
private static _getRemoveStaleWhenUpdatedUsedOptionName(
issue: Readonly<Issue>
): Option.RemovePrStaleWhenUpdated | Option.RemoveIssueStaleWhenUpdated {
return issue.isPullRequest
? Option.RemovePrStaleWhenUpdated
: Option.RemoveIssueStaleWhenUpdated;
}
private _consumeIssueOperation(issue: Readonly<Issue>): void {
this.operations.consumeOperation();
issue.operations.consumeOperation();
}
private _getRemoveStaleWhenUpdatedUsedOptionName(
issue: Readonly<Issue>
):
| Option.RemovePrStaleWhenUpdated
| Option.RemoveStaleWhenUpdated
| Option.RemoveIssueStaleWhenUpdated {
if (issue.isPullRequest) {
if (isBoolean(this.options.removePrStaleWhenUpdated)) {
return Option.RemovePrStaleWhenUpdated;
}
return Option.RemoveStaleWhenUpdated;
}
if (isBoolean(this.options.removeIssueStaleWhenUpdated)) {
return Option.RemoveIssueStaleWhenUpdated;
}
return Option.RemoveStaleWhenUpdated;
}
}

View File

@@ -19,7 +19,6 @@ export enum Option {
AnyOfIssueLabels = 'any-of-issue-labels',
AnyOfPrLabels = 'any-of-pr-labels',
OperationsPerRun = 'operations-per-run',
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
DebugOnly = 'debug-only',

View File

@@ -21,9 +21,8 @@ export interface IIssuesProcessorOptions {
anyOfIssueLabels: string;
anyOfPrLabels: string;
operationsPerRun: number;
removeStaleWhenUpdated: boolean;
removeIssueStaleWhenUpdated: boolean | undefined;
removePrStaleWhenUpdated: boolean | undefined;
removeIssueStaleWhenUpdated: boolean;
removePrStaleWhenUpdated: boolean;
debugOnly: boolean;
ascending: boolean;
deleteBranch: boolean;

View File

@@ -53,14 +53,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
operationsPerRun: parseInt(
core.getInput('operations-per-run', {required: true})
),
removeStaleWhenUpdated: !(
core.getInput('remove-stale-when-updated') === 'false'
removeIssueStaleWhenUpdated: !(
core.getInput('remove-issue-stale-when-updated') === 'false'
),
removeIssueStaleWhenUpdated: _toOptionalBoolean(
'remove-issue-stale-when-updated'
),
removePrStaleWhenUpdated: _toOptionalBoolean(
'remove-pr-stale-when-updated'
removePrStaleWhenUpdated: !(
core.getInput('remove-pr-stale-when-updated') === 'false'
),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
@@ -123,29 +120,4 @@ async function processOutput(
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
}
/**
* @description
* From an argument name, get the value as an optional boolean
* This is very useful for all the arguments that override others
* It will allow us to easily use the original one when the return value is `undefined`
* Which is different from `true` or `false` that consider the argument as set
*
* @param {Readonly<string>} argumentName The name of the argument to check
*
* @returns {boolean | undefined} The value matching the given argument name
*/
function _toOptionalBoolean(
argumentName: Readonly<string>
): boolean | undefined {
const argument: string = core.getInput(argumentName);
if (argument === 'true') {
return true;
} else if (argument === 'false') {
return false;
}
return undefined;
}
void _run();