JJ / github-pr-contains-action

Action that checks whether the body or diff in a PR contains a certain word.
MIT License
29 stars 33 forks source link

Use real regexes for checking #111

Open JJ opened 11 months ago

JJ commented 11 months ago

Right now it's tricky, since strings are rexified; it's probably better to add new features for checking real regexes. You can code alternatives into regexes, so using several ones might not be it.

rshih32 commented 5 months ago

Thanks for making this github action!

Just wondering if you rexify by escaping: https://github.com/JJ/github-pr-contains-action/commit/6f56b9f5452bf0cc363db66b884d03a12ef8c73f

Could you just "reverse" the meaning of the escape?

so \s\ would be the original regex \s

Assuming that would be okay, you could just process the expression twice.

["(", ")", "[", "]", "?", "+", "*"].forEach((s) => {
  expression = expression.replace(s, `\\${s}`);
});
["\\\\(", "\\\\)", "\\\\[", "\\\\]", "\\\\?", "\\\\+", "\\\\*"].forEach((s) => {
  expression = expression.replace(s, `${s.slice(-1)}`);
});
return new RegExp(expression);
JJ commented 5 months ago

Thanks for the suggestion. I drew myself into a corner here. I think that the solution will rather be to use a different parameter for regexes, so that it keeps compatibility, maybe together with a deprecation cycle.