release-drafter
release-drafter copied to clipboard
autolabeler needs on option to stop labeling on match (break on match)
I observed that is almost impossible to prevent multiple label matches, regardless how well you try to define the matching patterns. This does not play well with labels that are supposed to be exclusive, like being a bug or a feature or something to be excluded from the changelog.
Lucky for us the current configuration format is using sequence of objects for labeling, making it very easy to implement a break on match option for labels.
Basically by adding an option that tells labeler to stop finding other labels to add to the pull request when current pattern is matched we can prevent duplicates.
Using this we can put all labels that do not have conflicts at the top of the sequence and after them start adding labels with stop_on_match: true
at the bottom.
Isn't this just basic regex?
/a/
should only match the first occurrence.
/a/g
should match all the occurrences.
@jetersen I think I may not expressed it well enough. Take a look at https://github.com/ansible-community/devtools/blob/main/.github/release-drafter.yml#L47-L62
The issue is that release-drafter is looping on all label-match configs and is not able to stop if one label match was found. You endup having more labels added than you want, basically due to overlapping on other match conditions, something that cannot always be avoided.
The workaround would be have something like:
autolabeler:
- label: 'foo'
...
stop_on_match: true
- label: 'bar' # that label will never be added if `foo` was already found as matching due to stop_on_match
...
Right if so why close the issue 😕
LOL, I did not want to close it.
I also found another thing that can be annoying, when creating PRs manually I often add correct label myself, so auto-labeler is not desired. Still, there is no option to tell it to avoid labeling when a label is already present.
Real life example: I created a PR to fix the CI "Fix pip-tools 6.5.0" while adding skip-changelog
label. Few seconds after creating it, auto-labeler wrongly adds bug
label because the PR title starts with fix.
Not sure how to avoid that, it seems to happen quite often for me. I did tune the title patterns a little bit but still.
@ssbarnea remove the pull request update event? and only listen for creation and closed but than again closed would also add bug.
But if it have skip-changelog it will skip it no matter if it has a bug or any other label.
I cannot remove the update event because i will lose the ability to detect when two conflicting labels are present. Like having bug
and skip-changelog
at the same time. Yes, I use a single workflow for all checks. See https://github.com/ansible-community/ansible-lint/blob/main/.github/workflows/ack.yml and https://github.com/ansible-community/devtools/blob/main/.github/workflows/ack.yml
PS. Not really a big deal but I wanted to mention it so you would eventually know what features is better to implement, or not.