File tree 3 files changed +35
-2
lines changed
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,26 @@ describe('find comment tests', () => {
210
210
)
211
211
) . toEqual ( true )
212
212
213
+ expect (
214
+ findCommentPredicate (
215
+ {
216
+ token : 'token' ,
217
+ repository : 'repository' ,
218
+ issueNumber : 1 ,
219
+ commentAuthor : 'dorothy' ,
220
+ bodyIncludes : '' ,
221
+ bodyRegex : '/^.*KaNsAs.*$/i' ,
222
+ direction : 'direction'
223
+ } ,
224
+ {
225
+ id : 1 ,
226
+ body : `Toto, I've a feeling we're not in Kansas anymore.` ,
227
+ user : { login : 'dorothy' } ,
228
+ created_at : '2020-01-01T00:00:00Z'
229
+ }
230
+ )
231
+ ) . toEqual ( true )
232
+
213
233
expect (
214
234
findCommentPredicate (
215
235
{
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
48
48
Object.defineProperty(exports, "__esModule", ({ value: true }));
49
49
exports.findComment = exports.findCommentPredicate = void 0;
50
50
const github = __importStar(__nccwpck_require__(5438));
51
+ function stringToRegex(s) {
52
+ const m = s.match(/^(.)(.*?)\1([gimsuy]*)$/);
53
+ if (m)
54
+ return new RegExp(m[2], m[3]);
55
+ else
56
+ return new RegExp(s);
57
+ }
51
58
function findCommentPredicate(inputs, comment) {
52
59
return ((inputs.commentAuthor && comment.user
53
60
? comment.user.login === inputs.commentAuthor
@@ -56,7 +63,7 @@ function findCommentPredicate(inputs, comment) {
56
63
? comment.body.includes(inputs.bodyIncludes)
57
64
: true) &&
58
65
(inputs.bodyRegex && comment.body
59
- ? comment.body.match(inputs.bodyRegex) !== null
66
+ ? comment.body.match(stringToRegex( inputs.bodyRegex) ) !== null
60
67
: true));
61
68
}
62
69
exports.findCommentPredicate = findCommentPredicate;
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ export interface Comment {
19
19
created_at : string
20
20
}
21
21
22
+ function stringToRegex ( s : string ) : RegExp {
23
+ const m = s . match ( / ^ ( .) ( .* ?) \1( [ g i m s u y ] * ) $ / )
24
+ if ( m ) return new RegExp ( m [ 2 ] , m [ 3 ] )
25
+ else return new RegExp ( s )
26
+ }
27
+
22
28
export function findCommentPredicate (
23
29
inputs : Inputs ,
24
30
comment : Comment
@@ -31,7 +37,7 @@ export function findCommentPredicate(
31
37
? comment . body . includes ( inputs . bodyIncludes )
32
38
: true ) &&
33
39
( inputs . bodyRegex && comment . body
34
- ? comment . body . match ( inputs . bodyRegex ) !== null
40
+ ? comment . body . match ( stringToRegex ( inputs . bodyRegex ) ) !== null
35
41
: true )
36
42
)
37
43
}
You can’t perform that action at this time.
0 commit comments