-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
9 changed files
with
205 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters