labeler icon indicating copy to clipboard operation
labeler copied to clipboard

Negative lookahead is not supported

Open Robin-Hoodie opened this issue 2 years ago • 2 comments

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

Robin-Hoodie avatar Jul 26 '22 10:07 Robin-Hoodie

Hi, thanks for reporting this. It looks like a limitation in the go regex package:

image

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 avatar Jul 26 '22 13:07 srvaroa

@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 🙂

Robin-Hoodie avatar Jul 29 '22 09:07 Robin-Hoodie

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

srvaroa avatar Feb 20 '23 18:02 srvaroa

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

Robin-Hoodie avatar Feb 20 '23 18:02 Robin-Hoodie

Thanks @Robin-Hoodie !

srvaroa avatar Feb 20 '23 22:02 srvaroa

Workaround merged, please refer to docs here: https://github.com/srvaroa/labeler#negate-rules

Will be released in v1.3

srvaroa avatar Feb 20 '23 22:02 srvaroa