mirror of
https://github.com/actions/stale.git
synced 2025-12-10 03:57:04 +00:00
Feat: add any-of-labels option (#319)
* feat: add any-of-labels option * chore: run pack script * fix: error in milestones spec * chore: update readme * chore: fix default value in action.yml * chore: add some unit tests * docs: update README.md Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com> * refactor: add return type to lambda Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
This commit is contained in:
107
__tests__/any-of-labels.spec.ts
Normal file
107
__tests__/any-of-labels.spec.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import {Issue} from '../src/classes/issue';
|
||||
import {IssuesProcessor} from '../src/classes/issues-processor';
|
||||
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
|
||||
import {DefaultProcessorOptions} from './constants/default-processor-options';
|
||||
import {generateIssue} from './functions/generate-issue';
|
||||
|
||||
describe('any-of-labels option', () => {
|
||||
test('should do nothing when not set', async () => {
|
||||
const sut = new IssuesProcessorBuilder()
|
||||
.emptyAnyOfLabels()
|
||||
.issues([{labels: [{name: 'some-label'}]}])
|
||||
.build();
|
||||
|
||||
await sut.processIssues();
|
||||
|
||||
expect(sut.staleIssues).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('should skip it when none of the issue labels match', async () => {
|
||||
const sut = new IssuesProcessorBuilder()
|
||||
.anyOfLabels('skip-this-issue,and-this-one')
|
||||
.issues([{labels: [{name: 'some-label'}, {name: 'some-other-label'}]}])
|
||||
.build();
|
||||
|
||||
await sut.processIssues();
|
||||
|
||||
expect(sut.staleIssues).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('should skip it when the issue has no labels', async () => {
|
||||
const sut = new IssuesProcessorBuilder()
|
||||
.anyOfLabels('skip-this-issue,and-this-one')
|
||||
.issues([{labels: []}])
|
||||
.build();
|
||||
|
||||
await sut.processIssues();
|
||||
|
||||
expect(sut.staleIssues).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('should process it when one of the issue labels match', async () => {
|
||||
const sut = new IssuesProcessorBuilder()
|
||||
.anyOfLabels('skip-this-issue,and-this-one')
|
||||
.issues([{labels: [{name: 'some-label'}, {name: 'skip-this-issue'}]}])
|
||||
.build();
|
||||
|
||||
await sut.processIssues();
|
||||
|
||||
expect(sut.staleIssues).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('should process it when all the issue labels match', async () => {
|
||||
const sut = new IssuesProcessorBuilder()
|
||||
.anyOfLabels('skip-this-issue,and-this-one')
|
||||
.issues([{labels: [{name: 'and-this-one'}, {name: 'skip-this-issue'}]}])
|
||||
.build();
|
||||
|
||||
await sut.processIssues();
|
||||
|
||||
expect(sut.staleIssues).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
class IssuesProcessorBuilder {
|
||||
private _options: IIssuesProcessorOptions;
|
||||
private _issues: Issue[];
|
||||
|
||||
constructor() {
|
||||
this._options = {...DefaultProcessorOptions};
|
||||
this._issues = [];
|
||||
}
|
||||
|
||||
anyOfLabels(labels: string): IssuesProcessorBuilder {
|
||||
this._options.anyOfLabels = labels;
|
||||
return this;
|
||||
}
|
||||
|
||||
emptyAnyOfLabels(): IssuesProcessorBuilder {
|
||||
return this.anyOfLabels('');
|
||||
}
|
||||
|
||||
issues(issues: Partial<Issue>[]): IssuesProcessorBuilder {
|
||||
this._issues = issues.map(
|
||||
(issue, index): Issue =>
|
||||
generateIssue(
|
||||
this._options,
|
||||
index,
|
||||
issue.title || 'Issue title',
|
||||
issue.updated_at || '2000-01-01T00:00:00Z', // we only care about stale/expired issues here
|
||||
issue.created_at || '2000-01-01T00:00:00Z',
|
||||
issue.isPullRequest || false,
|
||||
issue.labels ? issue.labels.map(label => label.name) : []
|
||||
)
|
||||
);
|
||||
return this;
|
||||
}
|
||||
|
||||
build(): IssuesProcessor {
|
||||
return new IssuesProcessor(
|
||||
this._options,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? this._issues : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
|
||||
onlyLabels: '',
|
||||
onlyIssueLabels: '',
|
||||
onlyPrLabels: '',
|
||||
anyOfLabels: '',
|
||||
operationsPerRun: 100,
|
||||
debugOnly: true,
|
||||
removeStaleWhenUpdated: false,
|
||||
|
||||
Reference in New Issue
Block a user