-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: search comment body using a regular expression (#77)
* First stab at adding support for regex searching comments with body-regex input * false should have been true * Minor refactor and tests * Add ci test * Update readme Co-authored-by: dluftspring <[email protected]>
- Loading branch information
1 parent
1c328ad
commit f4499a7
Showing
9 changed files
with
903 additions
and
132 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
import {findCommentPredicate} from '../lib/find' | ||
|
||
describe('find comment tests', () => { | ||
test('find by bodyIncludes', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: '', | ||
bodyIncludes: 'Kansas', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: '', | ||
bodyIncludes: 'not-exist', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
}) | ||
|
||
test('find by bodyRegex', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: '', | ||
bodyIncludes: '', | ||
bodyRegex: '^.*Kansas.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: '', | ||
bodyIncludes: '', | ||
bodyRegex: '^.*not-exist.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
}) | ||
|
||
test('find by author', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: '', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'toto', | ||
bodyIncludes: '', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
}) | ||
|
||
test('find by bodyIncludes and author', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: 'Kansas', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: 'not-exist', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'toto', | ||
bodyIncludes: 'Kansas', | ||
bodyRegex: '', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
}) | ||
|
||
test('find by bodyRegex and author', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: '', | ||
bodyRegex: '^.*Kansas.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: '', | ||
bodyRegex: '^.*not-exist.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
|
||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'toto', | ||
bodyIncludes: '', | ||
bodyRegex: '^.*Kansas.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(false) | ||
}) | ||
|
||
test('find by bodyIncludes, bodyRegex and author', async () => { | ||
expect( | ||
findCommentPredicate( | ||
{ | ||
token: 'token', | ||
repository: 'repository', | ||
issueNumber: 1, | ||
commentAuthor: 'dorothy', | ||
bodyIncludes: 'feeling', | ||
bodyRegex: '^.*Kansas.*$', | ||
direction: 'direction' | ||
}, | ||
{ | ||
id: 1, | ||
body: `Toto, I've a feeling we're not in Kansas anymore.`, | ||
user: {login: 'dorothy'} | ||
} | ||
) | ||
).toEqual(true) | ||
}) | ||
}) |
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
Oops, something went wrong.