fix(template): 同步 total_commits<=0 口径与 U-5 记录
This commit is contained in:
@@ -173,3 +173,5 @@
|
||||
**顺序口径(模板注释里也钉住了)**:`最小 bootstrap → 仓内脚本 → 环境 → 门禁入口 → 权威门禁 → 核对报告 → 预览 → 上报`。
|
||||
**不能在检出前依赖仓内文件**;预览仍然排在"报告核对"之后。
|
||||
|
||||
| U-5 | **把 `total_commits` 当声明条数**:真实新分支推送时 Gitea 给 `total_commits=0`、列表被截断(5 条),Git 范围 12 条 ⇒ 严判让门禁在真实 CI 首跑就红(与代码质量无关) | **Git 范围是唯一权威**:`total_commits > 0` 才交叉核对;`<=0`/缺失视为"未声明",以 Git 范围为准并把"负载条数不可信"写进来源;`--self-test` 加 `total_commits=0` 分支 | 真实 run #16(`ci-trial-20261012`);自检 15 分支 |
|
||||
|
||||
|
||||
+29
-7
@@ -189,6 +189,12 @@ def resolve_scope(explicit="", env=None, cwd=None):
|
||||
declared = int(declared_raw)
|
||||
except (TypeError, ValueError):
|
||||
return [], src, f"事件负载 total_commits 不是整数:{declared_raw!r}"
|
||||
# ⚠️ 实测(真实 Runner):**新分支推送时 Gitea 会给 `total_commits=0`** ——
|
||||
# 那不是"声明 0 条",而是"这次没声明条数"。只有当它 > 0 时才拿来跟 Git 范围比对;
|
||||
# 否则以 Git 范围为准(并把"负载没声明/列表被截断"写进来源里)。
|
||||
if declared <= 0:
|
||||
declared = None
|
||||
if declared is not None:
|
||||
if declared != len(commits):
|
||||
return [], src, (
|
||||
f"事件声明 {declared} 条提交,但 Git 范围算出 {len(commits)} 条"
|
||||
@@ -200,8 +206,8 @@ def resolve_scope(explicit="", env=None, cwd=None):
|
||||
else:
|
||||
src += "(与事件列表一致)"
|
||||
elif len(listed) != len(commits):
|
||||
src += (f"(⚠️ 事件列表 {len(listed)} 条、Git 范围 {len(commits)} 条"
|
||||
f" ⇒ 以 Git 范围为准)")
|
||||
src += (f"(⚠️ 事件负载没有可靠的条数声明(total_commits={declared_raw!r}),"
|
||||
f"列表给了 {len(listed)} 条、Git 范围 {len(commits)} 条 ⇒ 以 Git 范围为准)")
|
||||
return commits, src, ""
|
||||
|
||||
# ── ② 负载里有 commits 但没有 before:用列表,但**没有 Git 范围可交叉核对**,要写明 ──
|
||||
@@ -216,7 +222,9 @@ def resolve_scope(explicit="", env=None, cwd=None):
|
||||
declared = int(declared_raw)
|
||||
except (TypeError, ValueError):
|
||||
return [], "", f"事件负载 total_commits 不是整数:{declared_raw!r}"
|
||||
if declared != len(listed):
|
||||
if declared <= 0:
|
||||
declared = None # 与推送路径同一条口径:<=0 是"没声明",不是"声明 0 条"
|
||||
elif declared != len(listed):
|
||||
return [], "", (f"事件声明 {declared} 条提交、列表只给 {len(listed)} 条,"
|
||||
f"而这次又没有 before 可以算 Git 范围 —— 列表被截断且无法交叉核对,"
|
||||
f"不许拿截断后的列表去核")
|
||||
@@ -376,6 +384,20 @@ def self_test() -> int:
|
||||
if err or len(commits) != 1 or "commits[]" not in src:
|
||||
problems.append(f"事件负载正常时没有按 commits[] 取:{err or (len(commits), src)}")
|
||||
|
||||
# ⑫a **真实事件形状**:新分支推送时 Gitea 给 total_commits=0、列表被截断,
|
||||
# 必须以 Git 范围为准通过(真实 Runner 上就是这里红的)
|
||||
with open(evf, "w", encoding="utf-8") as fh:
|
||||
json.dump({"before": "0" * 40, "after": good2, "total_commits": 0,
|
||||
"commits": [{"id": good2, "message": "fix(b): 第三条合规"}],
|
||||
"repository": {"default_branch": "main"}}, fh)
|
||||
git("update-ref", "refs/remotes/origin/main", good1, cwd=d)
|
||||
commits, src, err = resolve_scope(env={"GITHUB_EVENT_PATH": evf, "GITHUB_ACTIONS": "true"}, cwd=d)
|
||||
if err or len(commits) != 2:
|
||||
problems.append(f"total_commits=0(真实新分支事件形状)时没有以 Git 范围为准:{err or len(commits)}")
|
||||
elif "没有可靠的条数声明" not in src:
|
||||
problems.append(f"没有写明负载条数不可信:{src}")
|
||||
git("update-ref", "-d", "refs/remotes/origin/main", cwd=d)
|
||||
|
||||
# ⑫ 本地一个远端都没有 ⇒ 只核 HEAD,并写明(不许退化成"整部历史")
|
||||
commits, src, err = resolve_scope(env={}, cwd=d)
|
||||
if err or len(commits) != 1 or "只核 HEAD" not in src:
|
||||
@@ -448,10 +470,10 @@ def self_test() -> int:
|
||||
for p in problems:
|
||||
print(f" · {p}", file=sys.stderr)
|
||||
return 1
|
||||
print("✅ 提交闸门自检通过:范围取法 14 个分支(显式范围 / Git 范围 before..after / "
|
||||
"负载声明与列表不一致 / 列表截断仍以 Git 为准 / 空范围拒绝 / 新分支 / 无 before 的列表 / "
|
||||
"列表提交不在检出里 / after 与 HEAD 核对 / 手工运行只核 HEAD 并写明 / "
|
||||
"无远端只核 HEAD / 新分支以默认分支为基准(含同名分支回归)/ 未推送提交)")
|
||||
print("✅ 提交闸门自检通过:范围取法 15 个分支(显式范围 / Git 范围 before..after / "
|
||||
"负载声明与列表不一致 / 列表截断仍以 Git 为准 / **total_commits=0 的真实事件形状** / "
|
||||
"空范围拒绝 / 新分支以默认分支为基准(含同名分支回归)/ 列表提交不在检出里 / "
|
||||
"after 与 HEAD 核对 / 手工运行与无远端时只核 HEAD 并写明 / 未推送提交)")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user