pr-agent icon indicating copy to clipboard operation
pr-agent copied to clipboard

Add Online Commenting to GitLab via Webhook Triggering the Pipeline

Open dst03106 opened this issue 11 months ago • 3 comments

Feature request

I’m considering implementing an online commenting feature in GitLab, using a webhook to trigger the pipeline. I’d appreciate your feedback on whether this approach makes sense.

Flow

Image

I would like to propose adding an online commenting trigger to GitLab CI/CD, controlled by the configuration value enable_online_commenting(gitlab) in configuration.toml. When enable_online_commenting is set to true, the following flow will be applied:

  1. During the pipeline, GitLab CI/CD will use the GitLab API to check whether a webhook with the required configuration already exists.
  2. If no such webhook exists, it will create a new webhook that triggers the CI/CD pipeline.
    • Trigger Event: comment event
    • Webhook URL: API endpoint that triggers the CI/CD pipeline

When a comment is made, the webhook triggers the CI/CD pipeline, which runs pr-agent using the payload as $TRIGGER_PAYLOAD.

Please let me know if you have any feedback or suggestions on this approach. Thank you!

Reference

Motivation

  • Add online commenting functionality to GitLab. #1443
  • This approach eliminates the need for a dedicated server or serverless solutions like AWS Lambda to process webhook events, since all handling occurs within the pipeline itself.

dst03106 avatar May 14 '25 08:05 dst03106

:bulb: Auto-generated documentation-based answer:

The documentation describes two main ways to enable online commenting and trigger Qodo Merge tools in GitLab:

  1. GitLab Pipeline Triggering: You can configure your .gitlab-ci.yml to run Qodo Merge tools (like describe, review, improve) in response to merge request events. However, standard GitLab pipelines do not natively trigger on comments—only on merge request events (like open, update). To trigger on comments, you would need a webhook that listens for comment events and then triggers the pipeline, as your feature request suggests.

  2. GitLab Webhook Server: The documentation provides a method to run a webhook server that listens for GitLab events (including comments) and triggers Qodo Merge accordingly. This is the recommended approach for supporting online commenting (i.e., triggering Qodo Merge tools via PR/MR comments).

Regarding your proposal:

  • The approach of using a webhook to listen for comment events and trigger the pipeline is valid and aligns with the webhook-based method described in the docs.
  • The documentation does not mention a specific enable_online_commenting(gitlab) configuration, but it does describe how to set up a webhook and the necessary configuration to enable comment-based triggers.
  • The webhook server approach is already supported and documented, and it allows Qodo Merge to respond to MR comments without needing a dedicated serverless function.

Summary:

  • Your proposed flow is supported by the current documentation, though you may need to implement the webhook server as described.
  • There is no explicit enable_online_commenting flag, but enabling the webhook and setting the correct triggers achieves the same result.
  • See the referenced documentation sections for setup details.

If you need a pure CI/CD pipeline solution without a persistent webhook server, you would need to ensure your pipeline can be triggered by comment events, which may require custom scripting or additional integration, as GitLab pipelines do not natively support comment triggers.

References:

Relevant Sources:

  • https://qodo-merge-docs.qodo.ai//installation/gitlab#run-a-gitlab-webhook-server
  • https://qodo-merge-docs.qodo.ai//usage-guide/automations_and_usage#gitlab-webhook
  • https://qodo-merge-docs.qodo.ai//usage-guide/automations_and_usage#online-usage

Hi @dst03106

I am not sure i fully understand the suggestion (and to be honest, I am not an expert to gitlab ci/cd)

When I developed this https://qodo-merge-docs.qodo.ai/installation/gitlab/ I thought that similar to github, gitlab would enable to trigger pipelines on comments. to my surprises, it cannot currently (and I would be happy to learn otherwise. But it seems its the truth.)

We can generate a webhook on comments. But someone needs to catch the webook. a server.

And if you are already initiating a server that catches webhooks (which needs more initial work), why not just use this: https://qodo-merge-docs.qodo.ai/installation/gitlab/#run-a-gitlab-webhook-server https://github.com/qodo-ai/pr-agent/blob/main/pr_agent/servers/gitlab_webhook.py ?

mrT23 avatar May 16 '25 13:05 mrT23

Hi @mrT23, thank you for the feedback!

A notable benefit of this implementation is that it doesn't require users to manage a separate server.

In a way, the Gitlab CI/CD pipeline functions similarly to a Lambda - it can be triggered through a webhook URL, as shown in the below link.

dst03106 avatar May 20 '25 13:05 dst03106