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::BaseService and Issues::BaseService and their subclasses pass to execute_hooks.
  • Note types are the four types that Gitlab::DataBuilder::Note adds target data for. Notes on work items are stored as Issue.
  • Wiki page actions come from the external_action methods of the WikiPages services.

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

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.

  1. Enable the flag: Feature.enable(:ai_flow_trigger_webhook_events) in the Rails console.

  2. 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
      }
    }
  3. Check that errors is empty and the filter is saved.

  4. Run the same mutation with field: "labels.title". Check that it returns contains invalid fields for merge_request_hooks: labels.title.

  5. Update the title of a merge request in the project. Check that the trigger does not run.

  6. 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.

Merge request reports

Loading
Loading