mergeable
mergeable copied to clipboard
Tagging new issues with labels based upon regex
Love this project but struggling to find a way on how to assign a tag to a new issue based upon a given string found in the issue body. I'm trying to search for a given Markdown heading and the value thereafter and assign a tag in a 1-to-1 fashion based on that value (ex., find AKS assign tag K8s-AKS; find GKE assign tag K8s-GKE; etc.) but it seems like multiple items in the mergeable[] array which trigger on the same when event aren't getting the job done. If I comment out the second entry, the first works fine. How do I go about mapping strings to labels such that I can have any number of them searched for and assigned in a new issue? This is what I have so far and would greatly appreciate any help:
---
version: 2
mergeable:
- when: issues.opened
validate:
- do: description
must_include:
regex: '(?<=### Kubernetes Platform\n\n)AKS'
pass:
- do: labels
add: AKS
- when: issues.opened
validate:
- do: description
must_include:
regex: '(?<=### Kubernetes Platform\n\n)GKE'
pass:
- do: labels
add: GKE
After experimenting around with this some more, it seems like this manifest should and does work most of the time.
version: 2
mergeable:
- when: issues.opened
name: Label validate
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nValidate'
pass:
- do: labels
add: validation
- when: issues.opened
name: Label mutate
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nMutate'
The problem I'm seeing is Mergeable is sometimes not assigning a label, almost like certain issue open events get blackholed and it misses them. The result is some issues get labeled and some don't. The ones that get labeled are done correctly.
Is anyone else seeing this behavior?
@shine2lay do you have any idea of what might cause this? Is it a problem with the way the mergeable manifest is written or something external?
hey @chipzoller ,
I think you are missing the pass case for the second recipe, each recipe has it's own pass fail and error they don't share
pass:
- do: labels
add: validation
Hey @shine2lay apologies, I did a fubar copy job. This is what I have:
version: 2
mergeable:
- when: issues.opened
name: Label validate
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nValidate'
pass:
- do: labels
add: validation
- when: issues.opened
name: Label mutate
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nMutate'
pass:
- do: labels
add: mutation
- when: issues.opened
name: Label generate
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nGenerate'
pass:
- do: labels
add: generation
- when: issues.opened
name: Label imageVerify
validate:
- do: description
must_include:
regex: '### Kyverno Rule Type\n\nimageVerify'
pass:
- do: labels
add: imageVerify
I'm still finding is that the labels are being applied inconsistently. I'll create an issue, it'll get labeled properly. I'll create another issue with the same string in the regex match and it won't. I don't understand what might cause this since the logic seems to work otherwise.
Yeah that does seems off, would you mind giving me the org/repo name (if it's public), I can check the logs
Yeah most definitely. It's https://github.com/chipzoller/kyverno-pss which I'm just using for some temporary development work (including trying to see if we can use Mergeable in the Kyverno project). Appreciate you checking on this.
BTW, you're more than welcome to open whatever issues you want in that repo to test it out for yourself. I'll just unsubscribe from notifications.
@chipzoller so I think there is indeed a bug, from logs, I am seeing that sometimes, only the first validate is being ran, while other times, all 4 is ran properly. I am not quite sure about what is causing it yet. It'll take more investigation
Edit: all 4 recipes are being recognized for sure. it's just someone only the first validate is ran
Ok, I kind of suspected it was something out of my control. Please let me know what assistance I can provide.
Thanks for catching this bug, I don't think I'll have time in the near future to fix it. If you want to tackle it, I'll do my best to help you out.
Description of the bug (based on logs):
When the event is received, it goes thru the action_before_validate is ran properly for all 4 recipe but occasionally only one validate_process is reported for the same event_id where it should be 4 validate_process since there are 4 different recipes.
Thanks for investigating and confirming it as a bug, @shine2lay. I probably don't possess the technical ability to fix this bug myself, so I'll have to see what else I might be able to leverage for now.
@chipzoller no worries, Thanks for catching the bug. When this issue is fixed, you'll notified through comments.