mirror of
https://github.com/actions/stale.git
synced 2025-12-28 11:08:18 +00:00
feat(options): add new options to avoid stale base on comments (#494)
* feat(options): add new options to avoid stale based on comments Helping to close #441, #470, #435? Closes #390 due to no activity BREAKING CHANGES: the options related to remove-stale-when-updated will only check the updates, not the comment. It is only impactint the configurations using the value at false * style(readme): fix table syntax due to rebase * docs(readme): add permissions only for the new options
This commit is contained in:
committed by
GitHub
parent
f1017f33dd
commit
1efddcbe9f
@@ -37,6 +37,9 @@ describe('Issue', (): void => {
|
||||
removeStaleWhenUpdated: false,
|
||||
removeIssueStaleWhenUpdated: undefined,
|
||||
removePrStaleWhenUpdated: undefined,
|
||||
removeStaleWhenCommented: false,
|
||||
removeIssueStaleWhenCommented: undefined,
|
||||
removePrStaleWhenCommented: undefined,
|
||||
repoToken: '',
|
||||
staleIssueMessage: '',
|
||||
stalePrMessage: '',
|
||||
|
||||
@@ -616,7 +616,28 @@ export class IssuesProcessor {
|
||||
);
|
||||
|
||||
if (shouldRemoveStaleWhenUpdated) {
|
||||
issueLogger.info(`The stale label should not be removed`);
|
||||
issueLogger.info(
|
||||
`The stale label should not be removed due to an update`
|
||||
);
|
||||
} else {
|
||||
issueLogger.info(
|
||||
`The stale label should be removed if all conditions met`
|
||||
);
|
||||
}
|
||||
|
||||
const shouldRemoveStaleWhenCommented: boolean =
|
||||
this._shouldRemoveStaleWhenCommented(issue);
|
||||
|
||||
issueLogger.info(
|
||||
`The option ${issueLogger.createOptionLink(
|
||||
this._getRemoveStaleWhenCommentedUsedOptionName(issue)
|
||||
)} is: ${LoggerService.cyan(shouldRemoveStaleWhenCommented)}`
|
||||
);
|
||||
|
||||
if (shouldRemoveStaleWhenCommented) {
|
||||
issueLogger.info(
|
||||
`The stale label should not be removed due to a comment`
|
||||
);
|
||||
} else {
|
||||
issueLogger.info(
|
||||
`The stale label should be removed if all conditions met`
|
||||
@@ -624,9 +645,18 @@ export class IssuesProcessor {
|
||||
}
|
||||
|
||||
// Should we un-stale this issue?
|
||||
if (shouldRemoveStaleWhenUpdated && issueHasComments) {
|
||||
if (shouldRemoveStaleWhenUpdated && issueHasUpdate) {
|
||||
issueLogger.info(
|
||||
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated`
|
||||
`Remove the stale label since the $$type has an update and the workflow should remove the stale label when updated`
|
||||
);
|
||||
await this._removeStaleLabel(issue, staleLabel);
|
||||
|
||||
issueLogger.info(`Skipping the process since the $$type is now un-stale`);
|
||||
|
||||
return; // Nothing to do because it is no longer stale
|
||||
} else if (shouldRemoveStaleWhenCommented && issueHasComments) {
|
||||
issueLogger.info(
|
||||
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when commented`
|
||||
);
|
||||
await this._removeStaleLabel(issue, staleLabel);
|
||||
|
||||
@@ -1046,6 +1076,22 @@ export class IssuesProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private _shouldRemoveStaleWhenCommented(issue: Issue): boolean {
|
||||
if (issue.isPullRequest) {
|
||||
if (isBoolean(this.options.removePrStaleWhenCommented)) {
|
||||
return this.options.removePrStaleWhenCommented;
|
||||
}
|
||||
|
||||
return this.options.removeStaleWhenCommented;
|
||||
}
|
||||
|
||||
if (isBoolean(this.options.removeIssueStaleWhenCommented)) {
|
||||
return this.options.removeIssueStaleWhenCommented;
|
||||
}
|
||||
|
||||
return this.options.removeStaleWhenCommented;
|
||||
}
|
||||
|
||||
private async _removeStaleLabel(
|
||||
issue: Issue,
|
||||
staleLabel: Readonly<string>
|
||||
@@ -1157,4 +1203,25 @@ export class IssuesProcessor {
|
||||
|
||||
return Option.RemoveStaleWhenUpdated;
|
||||
}
|
||||
|
||||
private _getRemoveStaleWhenCommentedUsedOptionName(
|
||||
issue: Readonly<Issue>
|
||||
):
|
||||
| Option.RemovePrStaleWhenCommented
|
||||
| Option.RemoveStaleWhenCommented
|
||||
| Option.RemoveIssueStaleWhenCommented {
|
||||
if (issue.isPullRequest) {
|
||||
if (isBoolean(this.options.removePrStaleWhenCommented)) {
|
||||
return Option.RemovePrStaleWhenCommented;
|
||||
}
|
||||
|
||||
return Option.RemoveStaleWhenCommented;
|
||||
}
|
||||
|
||||
if (isBoolean(this.options.removeIssueStaleWhenCommented)) {
|
||||
return Option.RemoveIssueStaleWhenCommented;
|
||||
}
|
||||
|
||||
return Option.RemoveStaleWhenCommented;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ export enum Option {
|
||||
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
|
||||
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
|
||||
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
|
||||
RemoveStaleWhenCommented = 'remove-stale-when-commented',
|
||||
RemoveIssueStaleWhenCommented = 'remove-issue-stale-when-commented',
|
||||
RemovePrStaleWhenCommented = 'remove-pr-stale-when-commented',
|
||||
DebugOnly = 'debug-only',
|
||||
Ascending = 'ascending',
|
||||
DeleteBranch = 'delete-branch',
|
||||
|
||||
@@ -28,6 +28,9 @@ export interface IIssuesProcessorOptions {
|
||||
removeStaleWhenUpdated: boolean;
|
||||
removeIssueStaleWhenUpdated: boolean | undefined;
|
||||
removePrStaleWhenUpdated: boolean | undefined;
|
||||
removeStaleWhenCommented: boolean;
|
||||
removeIssueStaleWhenCommented: boolean | undefined;
|
||||
removePrStaleWhenCommented: boolean | undefined;
|
||||
debugOnly: boolean;
|
||||
ascending: boolean;
|
||||
deleteBranch: boolean;
|
||||
|
||||
@@ -62,6 +62,15 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
|
||||
removePrStaleWhenUpdated: _toOptionalBoolean(
|
||||
core.getInput('remove-pr-stale-when-updated')
|
||||
),
|
||||
removeStaleWhenCommented: !(
|
||||
core.getInput('remove-stale-when-commented') === 'false'
|
||||
),
|
||||
removeIssueStaleWhenCommented: _toOptionalBoolean(
|
||||
core.getInput('remove-issue-stale-when-commented')
|
||||
),
|
||||
removePrStaleWhenCommented: _toOptionalBoolean(
|
||||
core.getInput('remove-pr-stale-when-commented')
|
||||
),
|
||||
debugOnly: core.getInput('debug-only') === 'true',
|
||||
ascending: core.getInput('ascending') === 'true',
|
||||
deleteBranch: core.getInput('delete-branch') === 'true',
|
||||
|
||||
Reference in New Issue
Block a user