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:
Geoffrey Testelin 2021-03-01 01:08:33 +01:00 committed by GitHub
parent 836169b81a
commit 0e95ddbecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1246 additions and 4 deletions

View File

@ -24,6 +24,8 @@ Warns and then closes issues and PRs that have had no activity for a specified a
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. | Optional |
| `exempt-pr-labels` | Labels on the PR exempted from being marked as stale. | Optional |
| `only-labels` | Only labels checked for stale issue/PR. | Optional |
| `only-issue-labels` | Only labels checked for stale issue (override `only-labels`). | Optional |
| `only-pr-labels` | Only labels checked for stale PR (override `only-labels`). | Optional |
| `operations-per-run` | Maximum number of operations per run (GitHub API CRUD related). _Defaults to **30**_ | Optional |
| `remove-stale-when-updated` | Remove stale label from issue/PR on updates or comments. _Defaults to **true**_ | Optional |
| `debug-only` | Dry-run on action. _Defaults to **false**_ | Optional |

View File

@ -19,6 +19,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
closePrLabel: '',
exemptPrLabels: '',
onlyLabels: '',
onlyIssueLabels: '',
onlyPrLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenUpdated: false,

File diff suppressed because it is too large Load Diff

View File

@ -88,6 +88,14 @@ inputs:
description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels.'
default: ''
required: false
only-issue-labels:
description: 'Only issues with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels. Override "only-labels" option regarding only the issues.'
default: ''
required: false
only-pr-labels:
description: 'Only pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels. Override "only-labels" option regarding only the pull requests.'
default: ''
required: false
operations-per-run:
description: 'The maximum number of operations per run, used to control rate limiting (GitHub API CRUD related).'
default: '30'

35
dist/index.js vendored
View File

@ -285,6 +285,23 @@ class IssuesProcessor {
const daysBeforeStale = issue.isPullRequest
? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale();
const onlyLabels = words_to_list_1.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 = onlyLabels.every((label) => {
return is_labeled_1.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}`);
const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale);
if (!staleMessage && shouldMarkAsStale) {
@ -462,7 +479,6 @@ class IssuesProcessor {
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
state: 'open',
labels: this.options.onlyLabels,
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
page
@ -676,6 +692,19 @@ class IssuesProcessor {
? this.options.daysBeforeClose
: this.options.daysBeforePrClose;
}
_getOnlyLabels(issue) {
if (issue.isPullRequest) {
if (this.options.onlyPrLabels !== '') {
return this.options.onlyPrLabels;
}
}
else {
if (this.options.onlyIssueLabels !== '') {
return this.options.onlyIssueLabels;
}
}
return this.options.onlyLabels;
}
_removeStaleLabel(issue, staleLabel) {
return __awaiter(this, void 0, void 0, function* () {
const issueLogger = new issue_logger_1.IssueLogger(issue);
@ -1170,6 +1199,8 @@ function _getAndValidateArgs() {
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 })),
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
debugOnly: core.getInput('debug-only') === 'true',
@ -1222,7 +1253,7 @@ function _toOptionalBoolean(argumentName) {
}
return undefined;
}
_run();
void _run();
/***/ }),

View File

@ -28,6 +28,8 @@ describe('Issue', (): void => {
exemptIssueLabels: '',
exemptPrLabels: '',
onlyLabels: '',
onlyIssueLabels: '',
onlyPrLabels: '',
operationsPerRun: 0,
removeStaleWhenUpdated: false,
repoToken: '',

View File

@ -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>

View File

@ -19,6 +19,8 @@ export interface IIssuesProcessorOptions {
closePrLabel: string;
exemptPrLabels: string;
onlyLabels: string;
onlyIssueLabels: string;
onlyPrLabels: string;
operationsPerRun: number;
removeStaleWhenUpdated: boolean;
debugOnly: boolean;

View File

@ -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();