mirror of
https://github.com/actions/stale.git
synced 2025-12-11 04:32:53 +00:00
feat(only-labels): add 2 new options to distinguish issue and PR configs (#336)
* feat(assignees): add new option to avoid stale for assignees closes #271 * test: add more coverage * docs: fix readme format issue * docs: reorder and enhance typo * docs(contributing): add more information about the npm scripts * feat(only-labels): add new options to customize it for issues and PR closes #308
This commit is contained in:
committed by
GitHub
parent
836169b81a
commit
0e95ddbecb
@@ -28,6 +28,8 @@ describe('Issue', (): void => {
|
||||
exemptIssueLabels: '',
|
||||
exemptPrLabels: '',
|
||||
onlyLabels: '',
|
||||
onlyIssueLabels: '',
|
||||
onlyPrLabels: '',
|
||||
operationsPerRun: 0,
|
||||
removeStaleWhenUpdated: false,
|
||||
repoToken: '',
|
||||
|
||||
@@ -120,6 +120,34 @@ export class IssuesProcessor {
|
||||
const daysBeforeStale: number = issue.isPullRequest
|
||||
? this._getDaysBeforePrStale()
|
||||
: this._getDaysBeforeIssueStale();
|
||||
const onlyLabels: string[] = wordsToList(this._getOnlyLabels(issue));
|
||||
|
||||
if (onlyLabels.length > 0) {
|
||||
issueLogger.info(
|
||||
`The option "onlyLabels" was specified to only processed the issues and pull requests with all those labels (${onlyLabels.length})`
|
||||
);
|
||||
|
||||
const hasAllWhitelistedLabels: boolean = onlyLabels.every(
|
||||
(label: Readonly<string>): boolean => {
|
||||
return isLabeled(issue, label);
|
||||
}
|
||||
);
|
||||
|
||||
if (!hasAllWhitelistedLabels) {
|
||||
issueLogger.info(
|
||||
`Skipping this $$type because it doesn't have all the required labels`
|
||||
);
|
||||
continue; // Don't process issues without all of the required labels
|
||||
} else {
|
||||
issueLogger.info(
|
||||
`All the required labels are present on this $$type. Continuing the process`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
issueLogger.info(
|
||||
`The option "onlyLabels" was not specified. Continuing the process for this $$type`
|
||||
);
|
||||
}
|
||||
|
||||
issueLogger.info(`Days before $$type stale: ${daysBeforeStale}`);
|
||||
|
||||
@@ -398,7 +426,6 @@ export class IssuesProcessor {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
state: 'open',
|
||||
labels: this.options.onlyLabels,
|
||||
per_page: 100,
|
||||
direction: this.options.ascending ? 'asc' : 'desc',
|
||||
page
|
||||
@@ -660,6 +687,20 @@ export class IssuesProcessor {
|
||||
: this.options.daysBeforePrClose;
|
||||
}
|
||||
|
||||
private _getOnlyLabels(issue: Issue): string {
|
||||
if (issue.isPullRequest) {
|
||||
if (this.options.onlyPrLabels !== '') {
|
||||
return this.options.onlyPrLabels;
|
||||
}
|
||||
} else {
|
||||
if (this.options.onlyIssueLabels !== '') {
|
||||
return this.options.onlyIssueLabels;
|
||||
}
|
||||
}
|
||||
|
||||
return this.options.onlyLabels;
|
||||
}
|
||||
|
||||
private async _removeStaleLabel(
|
||||
issue: Issue,
|
||||
staleLabel: Readonly<string>
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface IIssuesProcessorOptions {
|
||||
closePrLabel: string;
|
||||
exemptPrLabels: string;
|
||||
onlyLabels: string;
|
||||
onlyIssueLabels: string;
|
||||
onlyPrLabels: string;
|
||||
operationsPerRun: number;
|
||||
removeStaleWhenUpdated: boolean;
|
||||
debugOnly: boolean;
|
||||
|
||||
@@ -39,6 +39,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
|
||||
closePrLabel: core.getInput('close-pr-label'),
|
||||
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
||||
onlyLabels: core.getInput('only-labels'),
|
||||
onlyIssueLabels: core.getInput('only-issue-labels'),
|
||||
onlyPrLabels: core.getInput('only-pr-labels'),
|
||||
operationsPerRun: parseInt(
|
||||
core.getInput('operations-per-run', {required: true})
|
||||
),
|
||||
@@ -106,4 +108,4 @@ function _toOptionalBoolean(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
_run();
|
||||
void _run();
|
||||
|
||||
Reference in New Issue
Block a user