labeler
labeler copied to clipboard
Negative lookahead is not supported
Logs from GH action:
2022/07/26 13:26:48 Matching `^fix\(.*\)[^!]((?!BREAKING\sCHANGE).)*$` against: `fix(.github/labeler.yml): labels not being applied correctly [CDS-000]`
2022/07/26 13:26:48 release-as-fix: condition Title matches regex yields false
Label config
version: 1
labels:
// Other labels
- label: 'release-as-fix'
title: '^fix\(.*\)[^!]((?!BREAKING\sCHANGE).)*$'
- Regex that should match
^fix\(.*\)[^!]((?!BREAKING\sCHANGE).)*$
- PR title
fix(.github/labeler.yml): labels not being applied correctly [CDS-000]
If using a tool like https://regex101.com/ , you can verify that the PR title should match the regex
Hi, thanks for reporting this. It looks like a limitation in the go regex package:
It chokes on the negative look ahead. Removing the !?
makes the expression compile. A quick search in Stack Overflow seems to confirm it.
Is there a chance you can rewrite the expression without using it? I can look into using a different regex library but that might take me a bit longer.
Cheers,
@srvaroa I've taken a look at working around this, but couldn't find any other way to do this w/ a regex.
The reason I'm using the negative lookahead is is because we have another label, release-as-major
that's applied in case the PR title does contain "BREAKING CHANGE" and I don't want both "release-as-fix" and "release-as-major" to be applied in such a case
- label: 'release-as-fix'
title: '^fix\(.*\)((?!BREAKING\sCHANGE).)*'
- label: 'release-as-major'
title: '^.*BREAKING CHANGE'
An alternative would be if it'd be possible to conditionally prevent a label from being applied if another label is already being applied.
A hypothetical API could look like this
- label: 'release-as-fix'
title: '^fix.*$'
not-together-with: '^release-as-major$'
- label: 'release-as-major'
title: '^.*BREAKING CHANGE'
I'm open for other suggestions 🙂
Hi @Robin-Hoodie since this is a limitation in Go's regex library I've tried an imperfect workaround. I'm interested in knowing if this would cover your use case: https://github.com/srvaroa/labeler/pull/67
Hi @srvaroa I don't work on the repository for which I filed this issue anymore, but I believe that your suggested workaround would solve the problem I had, yes!
FYI I believe you meant to write https://github.com/srvaroa/labeler/pull/67#issuecomment-1437415476 in another PR
Thanks @Robin-Hoodie !
Workaround merged, please refer to docs here: https://github.com/srvaroa/labeler#negate-rules
Will be released in v1.3