Skip to content

fix(ai): add clusterId column to ModelServiceInstanceVO#3358

Open
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/ZSTAC-81566
Open

fix(ai): add clusterId column to ModelServiceInstanceVO#3358
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/ZSTAC-81566

Conversation

@MatheMatrix
Copy link
Owner

Resolves: ZSTAC-81566

Target: 5.5.6

sync from gitlab !9188

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

总览

新增Git预推送钩子脚本,对fix/和feature/分支执行强制验证。脚本执行:分支名称格式检查、远程URL合理性检查、最新提交Change-Id验证、fix分支ZSTAC工单引用验证、仓库身份一致性检查。任何检查失败将阻止推送,成功时输出提示消息。

变更

分支/文件 摘要
Git钩子脚本
.gitconfig/hooks/pre-push
新增预推送钩子,实现fix/feature分支多层验证逻辑,包括分支命名规范检查、远程URL检查、Change-Id验证、ZSTAC工单号检查及仓库身份验证。使用彩色输出提供反馈并在失败时阻止推送。

诗歌

🐰 一份钩子来把关,
fix与feature要规范,
ZSTAC工单必写全,
Change-Id不能缺,
推送验证守护栏,
代码质量有保障!

代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)
Check name Status Explanation Resolution
Title check ❌ Error PR标题与实际变更不符。标题声称添加clusterId列到ModelServiceInstanceVO,但实际变更是添加Git pre-push钩子脚本用于分支验证。 更新PR标题以准确反映实际变更,例如:'feat(git): add pre-push hook for branch validation',确保标题与.gitconfig/hooks/pre-push文件的更改相符。
Description check ⚠️ Warning PR描述内容与实际变更完全不相关。描述提及ZSTAC-81566和ModelServiceInstanceVO,但实际变更是添加Git预推送钩子脚本。 重写PR描述以准确说明变更内容,包括新Git钩子的目的和功能,即对fix/和feature/分支进行验证检查。
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into 5.5.6
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/ye.zou/fix/ZSTAC-81566

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@conf/db/upgrade/V5.5.6__schema.sql`:
- Around line 183-186: The SQL UPDATE uses unquoted identifiers which can break
on MySQL/GreatSQL reserved words; update the statement to wrap all table and
column names in backticks—specifically reference the tables
ModelServiceInstanceVO and PodVO and the columns vmInstanceUuid, uuid, and
clusterId—so change the UPDATE/INNER JOIN/SET/WHERE identifiers to use backticks
around `ModelServiceInstanceVO`, `msi`, `PodVO`, `p`, `vmInstanceUuid`, `uuid`,
and `clusterId`.

Comment on lines 183 to 186
UPDATE ModelServiceInstanceVO msi
INNER JOIN PodVO p ON msi.vmInstanceUuid = p.uuid
SET msi.clusterId = p.clusterId
WHERE msi.clusterId IS NULL AND p.clusterId IS NOT NULL;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

表名和列名需要使用反引号包裹。

根据编码规范,所有表名和列名必须使用反引号包裹,以避免 MySQL 8.0 / GreatSQL 保留关键字冲突导致的语法错误。例如 uuid 在某些数据库版本中可能是保留字。

♻️ 建议修改
-UPDATE ModelServiceInstanceVO msi
-INNER JOIN PodVO p ON msi.vmInstanceUuid = p.uuid
-SET msi.clusterId = p.clusterId
-WHERE msi.clusterId IS NULL AND p.clusterId IS NOT NULL;
+UPDATE `ModelServiceInstanceVO` `msi`
+INNER JOIN `PodVO` `p` ON `msi`.`vmInstanceUuid` = `p`.`uuid`
+SET `msi`.`clusterId` = `p`.`clusterId`
+WHERE `msi`.`clusterId` IS NULL AND `p`.`clusterId` IS NOT NULL;

As per coding guidelines: "所有表名和列名必须使用反引号包裹(例如:WHERE `system` = 1),以避免 MySQL 8.0 / GreatSQL 保留关键字冲突导致的语法错误"

🤖 Prompt for AI Agents
In `@conf/db/upgrade/V5.5.6__schema.sql` around lines 183 - 186, The SQL UPDATE
uses unquoted identifiers which can break on MySQL/GreatSQL reserved words;
update the statement to wrap all table and column names in
backticks—specifically reference the tables ModelServiceInstanceVO and PodVO and
the columns vmInstanceUuid, uuid, and clusterId—so change the UPDATE/INNER
JOIN/SET/WHERE identifiers to use backticks around `ModelServiceInstanceVO`,
`msi`, `PodVO`, `p`, `vmInstanceUuid`, `uuid`, and `clusterId`.

Resolves: ZSTAC-81903

Change-Id: Ia7cc6d756cf62b60b6eda2f4d4daeeee982c02d7
@MatheMatrix MatheMatrix force-pushed the sync/ye.zou/fix/ZSTAC-81566 branch from 2137d18 to abac4af Compare February 14, 2026 08:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.gitconfig/hooks/pre-push:
- Around line 65-71: The branch-name check using [[ "$BRANCH" =~ premium ]] is
too loose and will match "premium" anywhere; update the conditional that
references the BRANCH variable to use a stricter pattern (e.g., a regex that
matches whole segment names like (^|/)(premium)(/|$|-) or similar) so only
branches whose final/segment name is exactly "premium" (or clearly intended
premium branches) trigger the error; modify the if that uses BRANCH and
REPO_NAME to apply this tighter match logic.
🧹 Nitpick comments (3)
.gitconfig/hooks/pre-push (3)

13-14: URL 变量已定义但未使用

第 14 行定义的 URL 变量从未被引用。脚本在第 35 行通过 git remote get-url "$REMOTE" 重新获取远程 URL。建议直接使用传入的 $2 参数,或者移除未使用的变量。

♻️ 建议的修复方案

方案 1:移除未使用的变量

 REMOTE="$1"
-URL="$2"
+# URL is available as $2 but we fetch it via git remote get-url for validation

方案 2:使用传入的 URL 参数

 REMOTE="$1"
 URL="$2"
 
 BRANCH=$(git branch --show-current)
 ...
 # --- Check 2: Remote URL sanity ---
-REMOTE_URL=$(git remote get-url "$REMOTE" 2>/dev/null)
-if [ -z "$REMOTE_URL" ]; then
+if [ -z "$URL" ]; then
     echo -e "${RED}[pre-push] Cannot resolve remote '$REMOTE'${NC}"
     ERRORS=$((ERRORS + 1))
 fi
 
 # Warn if pushing to upstream (zstackio) directly — usually want to push to fork (origin)
-if echo "$REMOTE_URL" | grep -q "zstackio/" && [ "$REMOTE" = "upstream" ]; then
+if echo "$URL" | grep -q "zstackio/" && [ "$REMOTE" = "upstream" ]; then
     echo -e "${YELLOW}[pre-push] WARNING: Pushing directly to upstream (zstackio). Are you sure?${NC}"
-    echo -e "${YELLOW}  Remote URL: $REMOTE_URL${NC}"
+    echo -e "${YELLOW}  Remote URL: $URL${NC}"

57-63: 大小写校验不一致

第 27 行对分支名称强制要求大写 ZSTAC,但第 59 行对提交信息使用了 -i(忽略大小写)。这可能导致分支名为 fix/ZSTAC-12345 但提交信息中写成 zstac-12345 的情况。

如果这是有意为之(对提交信息更宽松),可以忽略;否则建议保持一致:

♻️ 建议统一为大小写敏感
 if [[ "$BRANCH" =~ ^fix/ ]]; then
-    if ! echo "$LAST_COMMIT_MSG" | grep -qi "ZSTAC-[0-9]\+"; then
+    if ! echo "$LAST_COMMIT_MSG" | grep -q "ZSTAC-[0-9]\+"; then
         echo -e "${RED}[pre-push] Latest commit does not reference a ZSTAC ticket${NC}"
         ERRORS=$((ERRORS + 1))
     fi
 fi

1-7: 建议添加 set -u 提高脚本健壮性

考虑在脚本开头添加 set -u 以捕获未定义变量的使用,这在 shell 脚本中是一个良好的防御性编程实践。

♻️ 建议的修改
 #!/bin/bash
+set -u  # Exit on undefined variable
 # Pre-push hook: validate remote, branch name, and commit before pushing

Comment on lines +65 to +71
# --- Check 5: Confirm repo identity (main vs premium) ---
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
REPO_NAME=$(basename "$TOPLEVEL")
if [[ "$BRANCH" =~ premium ]] && [[ "$REPO_NAME" != "premium" ]]; then
echo -e "${RED}[pre-push] Branch name suggests premium but you're in repo '$REPO_NAME'${NC}"
ERRORS=$((ERRORS + 1))
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

premium 匹配规则过于宽松,可能导致误报

当前检查 [[ "$BRANCH" =~ premium ]] 会匹配分支名中任意位置出现的 "premium"。例如,在主仓库中创建的 fix/ZSTAC-12345-premium-bugfix 分支会被误判为 premium 仓库的分支而报错。

建议使用更精确的匹配模式:

🐛 建议的修复方案
 # --- Check 5: Confirm repo identity (main vs premium) ---
 TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
 REPO_NAME=$(basename "$TOPLEVEL")
-if [[ "$BRANCH" =~ premium ]] && [[ "$REPO_NAME" != "premium" ]]; then
+# Only check branches explicitly targeting premium (e.g., premium/*, */premium/*)
+if [[ "$BRANCH" =~ ^premium/ || "$BRANCH" =~ /premium/ ]] && [[ "$REPO_NAME" != "premium" ]]; then
     echo -e "${RED}[pre-push] Branch name suggests premium but you're in repo '$REPO_NAME'${NC}"
     ERRORS=$((ERRORS + 1))
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# --- Check 5: Confirm repo identity (main vs premium) ---
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
REPO_NAME=$(basename "$TOPLEVEL")
if [[ "$BRANCH" =~ premium ]] && [[ "$REPO_NAME" != "premium" ]]; then
echo -e "${RED}[pre-push] Branch name suggests premium but you're in repo '$REPO_NAME'${NC}"
ERRORS=$((ERRORS + 1))
fi
# --- Check 5: Confirm repo identity (main vs premium) ---
TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null)
REPO_NAME=$(basename "$TOPLEVEL")
# Only check branches explicitly targeting premium (e.g., premium/*, */premium/*)
if [[ "$BRANCH" =~ ^premium/ || "$BRANCH" =~ /premium/ ]] && [[ "$REPO_NAME" != "premium" ]]; then
echo -e "${RED}[pre-push] Branch name suggests premium but you're in repo '$REPO_NAME'${NC}"
ERRORS=$((ERRORS + 1))
fi
🤖 Prompt for AI Agents
In @.gitconfig/hooks/pre-push around lines 65 - 71, The branch-name check using
[[ "$BRANCH" =~ premium ]] is too loose and will match "premium" anywhere;
update the conditional that references the BRANCH variable to use a stricter
pattern (e.g., a regex that matches whole segment names like
(^|/)(premium)(/|$|-) or similar) so only branches whose final/segment name is
exactly "premium" (or clearly intended premium branches) trigger the error;
modify the if that uses BRANCH and REPO_NAME to apply this tighter match logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants