Description
Code of Conduct
- I agree to follow this project's Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues
GitHub-hosted runner
ubuntu-latest
Additional runner information
The code currently invokes a single RegExp.test()
call here: https://github.com/GsActions/commit-message-checker/blob/main/src/commit-message-checker.ts#L99
That approach does not work for the purpose of checking each line in a multi-line commit message or multi-line PR title+description.
Consider this Javascript example that checks for a maximum line length of 5:
const str = "tablex\ntable";
const regex = new RegExp("^.{0,5}$", "gm")
console.log(regex.test(str)); // output: true
One would expect that the regexp checks each line to be between 0 and 5 characters long, but what actually happens is that the entire multi-line string is searched for a line that is between 0 and 5 characters long. So it misses the first line which is supposed to make the check fail, and is happy by finding the second line that does match the condition.
Current Behavior
The current approach checks for the condition:
- There is at least one line in the multi-line string that matches the regexp.
Expected Behavior
The expected behavior is that the condition is checked:
- All lines in the multi-line string match the regexp.
This can be achieved by first splitting the multi-line string into a list of single-line strings, and then performing test()
on each of these lines, failing if at least one check fails.
Steps To Reproduce
See above for standalone Javascript that shows the issue.
To reproduce with the checker:
- Have a PR description with a title "tablex" and a description "table"
- Run the checker with:
- uses: gsactions/commit-message-checker@v2
with:
pattern: '^.{0,5}$'
flags: gm
error: PR title or description exceeds maximum line length of 5
The checker will succeed even though the "tablex" PR title exceeds the maximum line length of 5.
Anything else?
No response