-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enhance branch matching with regex #1457
feat: enhance branch matching with regex #1457
Conversation
hey @alfespa17 would you know why in the previous behavior we were returning true if the branch matched the workspace default branch ? |
I the beginning we only supported push events in one single branch the default one, but that behavior changed some time ago |
Okay ! So do you think we can merge that PR ? |
I will check the logic later |
It's not strictly required, but I believe that's the same thinking behind the below codes.
If you are going to change the behaviour here, it's probably good to make it consistent for the above item 1? This PR greatly enhances the flexibility to match different branches, but since you've already gone down the path of some regex matching, should we use a similar behaviour as the file matching? Or make them consistent?
|
hey @stanleyz ! I think you're right ! It seems like the code is already matching with regex folder paths ! Maybe we should just remove the behavior of returning true if it matches workspace's default files ? To me it seems like enough |
hey @stanleyz @alfespa17 ! I just changed the behavior to use regex for branches as well so everyone is using the same logic. I also remove the workspace default path matching for the file finding so we have much more freedoms when designing webhooks ! thanks ! |
I added some comments @BenjaminDecreusefond, I think you only need to leave this part |
Hi @alfespa17 ! I'm not seeing your comments unfortunately ! :/
What do you think ? |
You can do this with the existing code, the default branch will trigger the default template and in the webhook branches you can put "feat,fix" and that should work. |
thanks @alfespa17 ! Hmmm I think since there is already a webhook created by the workspace by default which matches its default branch master and then another webhook which matches for instance
will not break the current logic ? |
If you remove this part changes in any directory will trigger a job inside Terrakube, for example if we have 10 folders managed inside Terrakube we only want to trigger the workspace execution for changes inside 1 particular folder. if (file.startsWith(workspaceFolder)) {
log.info("Changed file {} in set workspace path {}", file, workspaceFolder);
return true;
} But if you have like several terraform modules and your workspace depends on that particular module you can also have changes trigger a job for some expression like this "modules/my-dependency-module/*" this is why you see this in the current code: for (String file : files) {
if (file.startsWith(workspaceFolder)) {
log.info("Changed file {} in set workspace path {}", file, workspaceFolder);
return true;
}
for (int i = 0; i < triggeredPath.length; i++) {
if (file.matches(triggeredPath[i])) {
log.info("Changed file {} matches set trigger pattern {}", file, triggeredPath[i]);
return true;
}
}
} The issue behind that logic was this one |
What I don't understand from what you're saying is that how can it trigger a job in terrakube whatever the directory we edit since we use a regex matching just after in the code ? Maybe i'm silly and I'm missing smth ? 🤔 |
@alfespa17 I updated the PR ! |
Hi @alfespa17 !
Following our discussion on this topic I'd like to propose a new way to do the matching for the branch list. The idea is as follow
The only thing is that I do not automatically return
True
when the branch is the same as the workspace's default branch. I don't know if this is an issue ?It's just a proposal for us to be able to achieve our goals ! Lemme know if you approve it :)
Regards