You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB

2 days ago
# -*- coding: utf-8 -*-
"""票 06 补刀:HEAD 有错误码节而 worklist 备注漏标的 6 文件,同法回捞。"""
from __future__ import annotations
import io
import re
import subprocess
import sys
from pathlib import Path
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
DOCS = Path('D:/code/crm-api-docs')
A4 = DOCS / 'A4 客户管理'
FILES = [
'我的客户/workspace 列表分页.bru',
'我的客户/快速创建客户.bru',
'战略协议/战略协议详情.bru',
'战略协议/战略协议页签列表.bru',
'我的客户/客户导入/任务结果.bru',
'我的客户/客户导入/失败疑似重复明细.bru',
]
for rel in FILES:
wt = A4 / rel
txt = wt.read_text(encoding='utf-8')
if '## 错误码' in txt:
print(f'跳过(已有): {rel}')
continue
proc = subprocess.run(['git', '-C', str(DOCS), 'show', f'HEAD:A4 客户管理/{rel}'],
capture_output=True)
head = proc.stdout.decode('utf-8', errors='replace')
lines = head.splitlines()
try:
start = next(i for i, l in enumerate(lines) if re.match(r'^\s*## 错误码', l))
except StopIteration:
print(f'⚠ HEAD 无节: {rel}')
continue
end = start + 1
while end < len(lines) and not re.match(r'^\s*## ', lines[end]):
end += 1
sec = lines[start:end]
while sec and sec[-1].strip() == '':
sec.pop()
codes = sorted(set(re.findall(r'\b\d{5}\b', '\n'.join(sec))))
anchor = ' ## 响应示例'
if anchor not in txt:
print(f'⚠ 无锚点: {rel}')
continue
txt = txt.replace(anchor, '\n' + '\n'.join(sec) + '\n\n' + anchor, 1)
wt.write_text(txt, encoding='utf-8', newline='')
print(f'回捞 {len(sec)} 行 codes={codes}: {rel}')
n_ec = sum(1 for f in A4.rglob('*.bru') if f.name != 'folder.bru' and '## 错误码' in f.read_text(encoding='utf-8'))
print(f'全仓含错误码节 = {n_ec}')