Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 22 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c21e2f2
Merge pull request #1 from actions/main
C0ZEN Nov 22, 2020
c913fa4
Merge pull request #2 from actions/main
C0ZEN Jan 16, 2021
9cf9bf2
Merge pull request #3 from actions/main
C0ZEN Jan 16, 2021
f11f623
Merge pull request #4 from actions/main
C0ZEN Jan 16, 2021
0f1457a
Merge pull request #5 from actions/main
C0ZEN Jan 17, 2021
fef6333
Merge pull request #6 from actions/main
C0ZEN Jan 18, 2021
e1ba62c
Merge pull request #7 from actions/main
C0ZEN Jan 23, 2021
abab4a6
Merge pull request #8 from actions/main
C0ZEN Feb 9, 2021
920683c
Merge pull request #9 from actions/main
C0ZEN Feb 13, 2021
a98474b
Merge pull request #10 from actions/main
C0ZEN Feb 18, 2021
915ed27
Merge pull request #11 from actions/main
C0ZEN Mar 1, 2021
4b097b3
Merge pull request #12 from actions/main
C0ZEN Mar 1, 2021
5575ade
docs(only-labels): enhance the docs and fix duplicate (#341)
C0ZEN Mar 4, 2021
b806328
build(deps-dev): bump @typescript-eslint/eslint-plugin (#342)
dependabot[bot] Mar 4, 2021
c6b2c30
build(deps): bump @octokit/rest from 18.3.0 to 18.3.2 (#350)
dependabot[bot] Mar 4, 2021
5a8ec1e
Merge pull request #14 from actions/main
C0ZEN Mar 4, 2021
6c29691
test: add more coverage for the stale label behaviour (#352) (#15)
C0ZEN Mar 5, 2021
d485d43
test: add more coverage for the stale label behaviour (#352) (#17)
C0ZEN Mar 9, 2021
25621f6
test: add more coverage for the stale label behaviour (#352) (#18)
C0ZEN Mar 9, 2021
69d190b
feat(any-of-labels): add 2 new options to customize for issues/PRs
C0ZEN Mar 9, 2021
f0aa23b
Merge branch 'main' into feature/any-of-labels-issues-prs
C0ZEN Mar 9, 2021
3e7d1c1
chore(index): update it
C0ZEN Mar 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 47 additions & 45 deletions README.md

Large diffs are not rendered by default.

1,131 changes: 1,088 additions & 43 deletions __tests__/any-of-labels.spec.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions __tests__/constants/default-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
onlyIssueLabels: '',
onlyPrLabels: '',
anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenUpdated: false,
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
default: ''
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:
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: ''
Expand Down
46 changes: 38 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,17 @@ class IssuesProcessor {
return is_labeled_1.isLabeled(issue, label);
});
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
}
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 {
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}`);
const shouldMarkAsStale = should_mark_when_stale_1.shouldMarkWhenStale(daysBeforeStale);
Expand Down Expand Up @@ -370,11 +372,24 @@ class IssuesProcessor {
issueLogger.info(`Skipping $$type because it has an exempt label`);
continue; // don't process exempt issues
}
const anyOfLabels = words_to_list_1.wordsToList(this.options.anyOfLabels);
if (anyOfLabels.length &&
!anyOfLabels.some((label) => is_labeled_1.isLabeled(issue, label))) {
issueLogger.info(`Skipping $$type because it does not have any of the required labels`);
continue; // don't process issues without any of the required labels
const anyOfLabels = words_to_list_1.wordsToList(this._getAnyOfLabels(issue));
if (anyOfLabels.length > 0) {
issueLogger.info(`The option "anyOfLabels" was specified to only processed the issues and pull requests with one of those labels (${anyOfLabels.length})`);
const hasOneOfWhitelistedLabels = anyOfLabels.some((label) => {
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);
if (milestones.shouldExemptMilestones()) {
Expand Down Expand Up @@ -759,6 +774,19 @@ class IssuesProcessor {
}
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) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -1546,6 +1574,8 @@ function _getAndValidateArgs() {
onlyIssueLabels: core.getInput('only-issue-labels'),
onlyPrLabels: core.getInput('only-pr-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 })),
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
debugOnly: core.getInput('debug-only') === 'true',
Expand Down
2 changes: 2 additions & 0 deletions src/classes/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('Issue', (): void => {
onlyIssueLabels: '',
onlyPrLabels: '',
anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 0,
removeStaleWhenUpdated: false,
repoToken: '',
Expand Down
67 changes: 56 additions & 11 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,25 @@ export class IssuesProcessor {

if (!hasAllWhitelistedLabels) {
issueLogger.info(
chalk.white('└──'),
`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`
chalk.white('├──'),
`All the required labels are present on this $$type`
);
issueLogger.info(
chalk.white('└──'),
`Continuing the process for this $$type`
);
}
} else {
issueLogger.info(`The option "onlyLabels" was not specified`);
issueLogger.info(
`The option "onlyLabels" was not specified. Continuing the process for this $$type`
chalk.white('└──'),
`Continuing the process for this $$type`
);
}

Expand Down Expand Up @@ -229,18 +237,41 @@ export class IssuesProcessor {
continue; // don't process exempt issues
}

const anyOfLabels: string[] = wordsToList(this.options.anyOfLabels);
const anyOfLabels: string[] = wordsToList(this._getAnyOfLabels(issue));

if (
anyOfLabels.length &&
!anyOfLabels.some((label: Readonly<string>): boolean =>
isLabeled(issue, label)
)
) {
if (anyOfLabels.length > 0) {
issueLogger.info(
`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(
`Skipping $$type because it does not have any of the required labels`
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);
Expand Down Expand Up @@ -736,6 +767,20 @@ export class IssuesProcessor {
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(
issue: Issue,
staleLabel: Readonly<string>
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/issues-processor-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface IIssuesProcessorOptions {
onlyIssueLabels: string;
onlyPrLabels: string;
anyOfLabels: string;
anyOfIssueLabels: string;
anyOfPrLabels: string;
operationsPerRun: number;
removeStaleWhenUpdated: boolean;
debugOnly: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
onlyIssueLabels: core.getInput('only-issue-labels'),
onlyPrLabels: core.getInput('only-pr-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})
),
Expand Down