feat(any-of-labels): add 2 new options to customize for issues/PRs (#380)

* docs(only-labels): enhance the docs and fix duplicate (#341)

* docs(only-labels): remove duplicated option and improve descriptions

a bad rebase happend

* docs(readme): use a multi-line array and remove the optional column

the option column was not helpful since each value is optional
the multi-line array will allow to have a better UI in small devices and basically in GitHub too due to the max-width

* style(readme): break line for the statistics

* docs(readme): add a better description for the ascending option

* docs(action): add missing punctuation

* build(deps-dev): bump @typescript-eslint/eslint-plugin (#342)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.15.2 to 4.16.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.16.1/packages/eslint-plugin)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump @octokit/rest from 18.3.0 to 18.3.2 (#350)

Bumps [@octokit/rest](https://github.com/octokit/rest.js) from 18.3.0 to 18.3.2.
- [Release notes](https://github.com/octokit/rest.js/releases)
- [Commits](https://github.com/octokit/rest.js/compare/v18.3.0...v18.3.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* test: add more coverage for the stale label behaviour (#352) (#15)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* test: add more coverage for the stale label behaviour (#352) (#17)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* test: add more coverage for the stale label behaviour (#352) (#18)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(any-of-labels): add 2 new options to customize for issues/PRs

closes #371
change this option and only-labels to have tree-logs

* chore(index): update it

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Geoffrey Testelin 2021-04-28 22:33:42 +02:00 committed by GitHub
parent 704929ea5a
commit c70e174d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1245 additions and 107 deletions

View File

@ -9,7 +9,7 @@ Warns and then closes issues and PRs that have had no activity for a specified a
Every argument is optional. Every argument is optional.
| Input | Description | | Input | Description |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `repo-token` | PAT(Personal Access Token) for authorizing repository.<br>_Defaults to **${{ github.token }}**_. | | `repo-token` | PAT(Personal Access Token) for authorizing repository.<br>_Defaults to **${{ github.token }}**_. |
| `days-before-stale` | Idle number of days before marking an issue/PR as stale.<br>_Defaults to **60**_. | | `days-before-stale` | Idle number of days before marking an issue/PR as stale.<br>_Defaults to **60**_. |
| `days-before-issue-stale` | Idle number of days before marking an issue as stale.<br>_Override `days-before-stale`_. | | `days-before-issue-stale` | Idle number of days before marking an issue as stale.<br>_Override `days-before-stale`_. |
@ -31,6 +31,8 @@ Every argument is optional.
| `only-issue-labels` | Only issues with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. | | `only-issue-labels` | Only issues with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. |
| `only-pr-labels` | Only PRs with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. | | `only-pr-labels` | Only PRs with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. |
| `any-of-labels` | Only issues and PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback"). | | `any-of-labels` | Only issues and PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback"). |
| `any-of-issue-labels` | Only issues with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback").<br>_Override `any-of-labels`_. |
| `any-of-pr-labels` | Only PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback").<br>_Override `any-of-labels`_. |
| `operations-per-run` | Maximum number of operations per run.<br>GitHub API CRUD related.<br>_Defaults to **30**_. | | `operations-per-run` | Maximum number of operations per run.<br>GitHub API CRUD related.<br>_Defaults to **30**_. |
| `remove-stale-when-updated` | Remove stale label from issue/PR on updates or comments.<br>_Defaults to **true**_. | | `remove-stale-when-updated` | Remove stale label from issue/PR on updates or comments.<br>_Defaults to **true**_. |
| `debug-only` | Dry-run on action.<br>_Defaults to **false**_. | | `debug-only` | Dry-run on action.<br>_Defaults to **false**_. |
@ -244,7 +246,7 @@ jobs:
- uses: actions/stale@v3 - uses: actions/stale@v3
with: with:
any-of-labels: 'needs-more-info,needs-demo' any-of-labels: 'needs-more-info,needs-demo'
# You can opt for 'only-labels' instead if your usecase requires all labels # You can opt for 'only-labels' instead if your use-case requires all labels
# to be present in the issue/PR # to be present in the issue/PR
``` ```

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
onlyIssueLabels: '', onlyIssueLabels: '',
onlyPrLabels: '', onlyPrLabels: '',
anyOfLabels: '', anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 100, operationsPerRun: 100,
debugOnly: true, debugOnly: true,
removeStaleWhenUpdated: false, removeStaleWhenUpdated: false,

View File

@ -92,6 +92,14 @@ inputs:
description: 'Only issues or pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.' description: 'Only issues or pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.'
default: '' default: ''
required: false required: false
any-of-issue-labels:
description: 'Only issues with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels. Override "any-of-labels" option regarding only the issues.'
default: ''
required: false
any-of-pr-labels:
description: 'Only pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels. Override "any-of-labels" option regarding only the pull requests.'
default: ''
required: false
only-issue-labels: 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.' 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: '' default: ''

46
dist/index.js vendored
View File

@ -312,15 +312,17 @@ class IssuesProcessor {
return is_labeled_1.isLabeled(issue, label); return is_labeled_1.isLabeled(issue, label);
}); });
if (!hasAllWhitelistedLabels) { if (!hasAllWhitelistedLabels) {
issueLogger.info(`Skipping this $$type because it doesn't have all the required labels`); issueLogger.info(chalk_1.default.white('└──'), `Skipping this $$type because it doesn't have all the required labels`);
continue; // Don't process issues without all of the required labels continue; // Don't process issues without all of the required labels
} }
else { else {
issueLogger.info(`All the required labels are present on this $$type. Continuing the process`); issueLogger.info(chalk_1.default.white('├──'), `All the required labels are present on this $$type`);
issueLogger.info(chalk_1.default.white('└──'), `Continuing the process for this $$type`);
} }
} }
else { else {
issueLogger.info(`The option "onlyLabels" was not specified. Continuing the process for this $$type`); issueLogger.info(`The option "onlyLabels" was not specified`);
issueLogger.info(chalk_1.default.white('└──'), `Continuing the process for this $$type`);
} }
issueLogger.info(`Days before $$type stale: ${daysBeforeStale}`); issueLogger.info(`Days before $$type stale: ${daysBeforeStale}`);
const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale); const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale);
@ -370,11 +372,24 @@ class IssuesProcessor {
issueLogger.info(`Skipping $$type because it has an exempt label`); issueLogger.info(`Skipping $$type because it has an exempt label`);
continue; // don't process exempt issues continue; // don't process exempt issues
} }
const anyOfLabels = words_to_list_1.wordsToList(this.options.anyOfLabels); const anyOfLabels = words_to_list_1.wordsToList(this._getAnyOfLabels(issue));
if (anyOfLabels.length && if (anyOfLabels.length > 0) {
!anyOfLabels.some((label) => is_labeled_1.isLabeled(issue, label))) { issueLogger.info(`The option "anyOfLabels" was specified to only processed the issues and pull requests with one of those labels (${anyOfLabels.length})`);
issueLogger.info(`Skipping $$type because it does not have any of the required labels`); const hasOneOfWhitelistedLabels = anyOfLabels.some((label) => {
continue; // don't process issues without any of the required labels return is_labeled_1.isLabeled(issue, label);
});
if (!hasOneOfWhitelistedLabels) {
issueLogger.info(chalk_1.default.white('└──'), `Skipping this $$type because it doesn't have one of the required labels`);
continue; // Don't process issues without any of the required labels
}
else {
issueLogger.info(chalk_1.default.white('├──'), `One of the required labels is present on this $$type`);
issueLogger.info(chalk_1.default.white('└──'), `Continuing the process for this $$type`);
}
}
else {
issueLogger.info(`The option "anyOfLabels" was not specified`);
issueLogger.info(chalk_1.default.white('└──'), `Continuing the process for this $$type`);
} }
const milestones = new milestones_1.Milestones(this.options, issue); const milestones = new milestones_1.Milestones(this.options, issue);
if (milestones.shouldExemptMilestones()) { if (milestones.shouldExemptMilestones()) {
@ -759,6 +774,19 @@ class IssuesProcessor {
} }
return this.options.onlyLabels; return this.options.onlyLabels;
} }
_getAnyOfLabels(issue) {
if (issue.isPullRequest) {
if (this.options.anyOfPrLabels !== '') {
return this.options.anyOfPrLabels;
}
}
else {
if (this.options.anyOfIssueLabels !== '') {
return this.options.anyOfIssueLabels;
}
}
return this.options.anyOfLabels;
}
_removeStaleLabel(issue, staleLabel) { _removeStaleLabel(issue, staleLabel) {
var _a; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -1758,6 +1786,8 @@ function _getAndValidateArgs() {
onlyIssueLabels: core.getInput('only-issue-labels'), onlyIssueLabels: core.getInput('only-issue-labels'),
onlyPrLabels: core.getInput('only-pr-labels'), onlyPrLabels: core.getInput('only-pr-labels'),
anyOfLabels: core.getInput('any-of-labels'), anyOfLabels: core.getInput('any-of-labels'),
anyOfIssueLabels: core.getInput('any-of-issue-labels'),
anyOfPrLabels: core.getInput('any-of-pr-labels'),
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })), operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })),
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'), removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
debugOnly: core.getInput('debug-only') === 'true', debugOnly: core.getInput('debug-only') === 'true',

View File

@ -31,6 +31,8 @@ describe('Issue', (): void => {
onlyIssueLabels: '', onlyIssueLabels: '',
onlyPrLabels: '', onlyPrLabels: '',
anyOfLabels: '', anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 0, operationsPerRun: 0,
removeStaleWhenUpdated: false, removeStaleWhenUpdated: false,
repoToken: '', repoToken: '',

View File

@ -132,17 +132,25 @@ export class IssuesProcessor {
if (!hasAllWhitelistedLabels) { if (!hasAllWhitelistedLabels) {
issueLogger.info( issueLogger.info(
chalk.white('└──'),
`Skipping this $$type because it doesn't have all the required labels` `Skipping this $$type because it doesn't have all the required labels`
); );
continue; // Don't process issues without all of the required labels continue; // Don't process issues without all of the required labels
} else { } else {
issueLogger.info( issueLogger.info(
`All the required labels are present on this $$type. Continuing the process` chalk.white('├──'),
`All the required labels are present on this $$type`
);
issueLogger.info(
chalk.white('└──'),
`Continuing the process for this $$type`
); );
} }
} else { } else {
issueLogger.info(`The option "onlyLabels" was not specified`);
issueLogger.info( issueLogger.info(
`The option "onlyLabels" was not specified. Continuing the process for this $$type` chalk.white('└──'),
`Continuing the process for this $$type`
); );
} }
@ -229,18 +237,41 @@ export class IssuesProcessor {
continue; // don't process exempt issues continue; // don't process exempt issues
} }
const anyOfLabels: string[] = wordsToList(this.options.anyOfLabels); const anyOfLabels: string[] = wordsToList(this._getAnyOfLabels(issue));
if ( if (anyOfLabels.length > 0) {
anyOfLabels.length &&
!anyOfLabels.some((label: Readonly<string>): boolean =>
isLabeled(issue, label)
)
) {
issueLogger.info( issueLogger.info(
`Skipping $$type because it does not have any of the required labels` `The option "anyOfLabels" was specified to only processed the issues and pull requests with one of those labels (${anyOfLabels.length})`
);
const hasOneOfWhitelistedLabels: boolean = anyOfLabels.some(
(label: Readonly<string>): boolean => {
return isLabeled(issue, label);
}
);
if (!hasOneOfWhitelistedLabels) {
issueLogger.info(
chalk.white('└──'),
`Skipping this $$type because it doesn't have one of the required labels`
);
continue; // Don't process issues without any of the required labels
} else {
issueLogger.info(
chalk.white('├──'),
`One of the required labels is present on this $$type`
);
issueLogger.info(
chalk.white('└──'),
`Continuing the process for this $$type`
);
}
} else {
issueLogger.info(`The option "anyOfLabels" was not specified`);
issueLogger.info(
chalk.white('└──'),
`Continuing the process for this $$type`
); );
continue; // don't process issues without any of the required labels
} }
const milestones: Milestones = new Milestones(this.options, issue); const milestones: Milestones = new Milestones(this.options, issue);
@ -736,6 +767,20 @@ export class IssuesProcessor {
return this.options.onlyLabels; return this.options.onlyLabels;
} }
private _getAnyOfLabels(issue: Issue): string {
if (issue.isPullRequest) {
if (this.options.anyOfPrLabels !== '') {
return this.options.anyOfPrLabels;
}
} else {
if (this.options.anyOfIssueLabels !== '') {
return this.options.anyOfIssueLabels;
}
}
return this.options.anyOfLabels;
}
private async _removeStaleLabel( private async _removeStaleLabel(
issue: Issue, issue: Issue,
staleLabel: Readonly<string> staleLabel: Readonly<string>

View File

@ -22,6 +22,8 @@ export interface IIssuesProcessorOptions {
onlyIssueLabels: string; onlyIssueLabels: string;
onlyPrLabels: string; onlyPrLabels: string;
anyOfLabels: string; anyOfLabels: string;
anyOfIssueLabels: string;
anyOfPrLabels: string;
operationsPerRun: number; operationsPerRun: number;
removeStaleWhenUpdated: boolean; removeStaleWhenUpdated: boolean;
debugOnly: boolean; debugOnly: boolean;

View File

@ -41,6 +41,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
onlyIssueLabels: core.getInput('only-issue-labels'), onlyIssueLabels: core.getInput('only-issue-labels'),
onlyPrLabels: core.getInput('only-pr-labels'), onlyPrLabels: core.getInput('only-pr-labels'),
anyOfLabels: core.getInput('any-of-labels'), anyOfLabels: core.getInput('any-of-labels'),
anyOfIssueLabels: core.getInput('any-of-issue-labels'),
anyOfPrLabels: core.getInput('any-of-pr-labels'),
operationsPerRun: parseInt( operationsPerRun: parseInt(
core.getInput('operations-per-run', {required: true}) core.getInput('operations-per-run', {required: true})
), ),