Allow filter conditions for webhook event triggers
What does this MR do and why?
Webhook event triggers (merge_request_hooks, issue_hooks, note_hooks, wiki_page_hooks) had no filter field allowlist. The model accepted any field path, and some paths saved but never matched, because the filter evaluator can't match inside arrays.
This MR adds an ALLOWED_FILTER_FIELDS entry for each type. It lists only scalar fields that Gitlab::FilterEvaluator can match today. I checked every path in the code that builds the payload.
| Event type | Field | Allowed values |
|---|---|---|
merge_request_hooks |
object_attributes.action |
open, close, reopen, update, approval, approved, unapproval, unapproved, merge |
merge_request_hooks |
object_attributes.state |
MergeRequest.available_states (opened, closed, merged, locked) |
merge_request_hooks |
object_attributes.target_branch |
any |
merge_request_hooks |
object_attributes.source_branch |
any |
merge_request_hooks |
object_attributes.draft |
true, false (only the in operator) |
issue_hooks |
object_attributes.action |
open, close, reopen, update |
issue_hooks |
object_attributes.state |
Issue.available_states (opened, closed) |
note_hooks |
object_attributes.noteable_type |
Commit, Issue, MergeRequest, Snippet |
wiki_page_hooks |
object_attributes.action |
create, update, delete |
Where the values come from:
- Merge request and issue actions are the values that
MergeRequests::BaseServiceandIssues::BaseServiceand their subclasses pass toexecute_hooks. - Note types are the four types that
Gitlab::DataBuilder::Noteadds target data for. Notes on work items are stored asIssue. - Wiki page actions come from the
external_actionmethods of theWikiPagesservices.
AiCatalogTriggerConditionsInput now has arguments for the four types, marked as experiments. aiFlowTriggerCreate and aiFlowTriggerUpdate take the filter as JSON, so they get the new validation through the model.
Labels (labels.title, changes.labels) are not in the list. Matching inside arrays needs filter evaluator work, tracked in https://gitlab.com/gitlab-org/gitlab/-/work_items/600987.
References
- Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/644204
- Depends on !276892. This MR targets its branch, because both change
trigger_conditions_input_type.rb. Please review that one first.
How to set up and validate locally
There is no UI change. To check that a filter really limits the runs, you also need !276803 on your branch or merged, because it starts flow triggers from webhook events.
-
Enable the flag:
Feature.enable(:ai_flow_trigger_webhook_events)in the Rails console. -
In GraphiQL (
/-/graphql-explorer), create a trigger on a project where you have a service account:mutation { aiFlowTriggerCreate(input: { projectPath: "<project path>" userId: "gid://gitlab/User/<service account id>" description: "Runs on merged merge requests" eventTypes: [MERGE_REQUEST_HOOKS] configPath: ".gitlab/duo/agents.yml" filter: { merge_request_hooks: { rules: [{ field: "object_attributes.action", operator: "in", value: ["merge"] }] } } }) { aiFlowTrigger { id filter } errors } } -
Check that
errorsis empty and the filter is saved. -
Run the same mutation with
field: "labels.title". Check that it returnscontains invalid fields for merge_request_hooks: labels.title. -
Update the title of a merge request in the project. Check that the trigger does not run.
-
Merge the merge request. Check that the trigger runs.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.