Implementing AI Code Review with GitLab Commit API and Feishu Bot Notifications

This tutorial walks through upgrading Git on a GitLab server, using the Commit API to fetch recent changes, invoking an AI model for automated code review, posting the review as a commit comment, and notifying the team via a Feishu custom‑bot webhook.

Ubiquitous Tech
Ubiquitous Tech
Ubiquitous Tech
Implementing AI Code Review with GitLab Commit API and Feishu Bot Notifications

Upgrade Git version on the GitLab server

The default Git version (1.8 series) can cause errors in CI pipelines. Upgrade with:

yum install -y https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm</code>
<code>yum -y install git

Verify the new version after installation.

Retrieve the latest commit via GitLab Commit API

Use the Commit API documented at https://docs.gitlab.com/ee/api/commits.html#list-repository-commits. Filter by branch name to obtain the most recent commit:

http://<em>gitlab-host</em>:<em>port</em>/api/v4/projects/1/repository/commits?ref_name=feature/20240803-gitlab-ci-demo

In the CI job, fetch the commit list with curl and extract the first object's sha and message using jq:

curl ... | jq '.[0] | {sha, message}'

Obtain diff information for the commit

With the commit SHA, call the diff endpoint (e.g., /repository/commits/<em>SHA</em>/diff) to receive a JSON array where each element describes a file diff.

Run AI review and post the result as a GitLab comment

Iterate over the diff file list, send each file to an AI large‑model endpoint, and post the review text to the comment API:

$GITLAB_API/projects/$CI_PROJECT_ID/repository/commits/$COMMIT_SHA/comments

The CI script adds this logic after the existing steps, triggering the AI review for each changed file and writing the review into the commit’s comment section.

Configure a Feishu custom‑bot webhook

Create a custom bot in a Feishu group, obtain the webhook URL, and store it securely (e.g., as a CI/CD variable). The webhook URL format is similar to:

https://open.feishu.cn/open-apis/bot/v2/hook/ your‑webhook‑id

Send a Feishu notification from the CI pipeline

Construct a message containing the project name and a link to the commit, then POST it to the webhook:

WEB_URL="https://gitlabserver:port/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/-/commit/${COMMIT_SHA}"</code>
<code>curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"${CI_PROJECT_NAME} project CI pipeline completed. Check the commit at ${WEB_URL}"}}' $FEISHU_WEBHOOK

The webhook URL is referenced via the CI/CD variable $FEISHU_WEBHOOK to avoid exposure.

Result

After pushing code, the pipeline automatically:

Retrieves the latest commit and its diff.

Sends each changed file to the AI model for review.

Writes the AI review as a comment on the commit.

Sends a Feishu message with the commit link.

Screenshots in the original article show the CI job execution, the comment added to the commit, and the Feishu notification.

Further improvements

Move mutable values (AI model URL, API key, model name, system prompt) into GitLab CI/CD variables. This enables the same pipeline to work with different providers such as Zhipu AI, OpenAI, or Ollama by adjusting only the variable values.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdAutomationfeishuGitLabAI code reviewwebhookcommit api
Ubiquitous Tech
Written by

Ubiquitous Tech

A ubiquitous public account for pirate enthusiasts, regularly sharing curated experiences, tech learning, and growth insights. Currently publishing articles on AI RAG customer service, AI MCP technology, and open-source design. Personal free Knowledge Planet: Awakening New World Programmer.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.