@unifan/pi-unifan-zh 1.0.41 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -84,11 +84,19 @@ export async function generateCommitMessage(
|
|
|
84
84
|
const text = response.content.map((c) => c.type === "text" ? c.text : "").join("").trim()
|
|
85
85
|
.replace(/^```[a-zA-Z]*\r?\n?/, "").replace(/\r?\n?```$/, "").trim();
|
|
86
86
|
if (!text) throw new Error("模型返回了空的提交信息。");
|
|
87
|
-
|
|
87
|
+
const lines = text.split(/\r?\n/);
|
|
88
|
+
const normalizedTitle = lines[0].replace(
|
|
89
|
+
/^(feat|fix|perf|refactor|ci|build|chore|docs|test|style|revert)(?:\(([^()\r\n]+)\)|(([^()\r\n]+)))?\s*[::]\s*(.+)$/,
|
|
90
|
+
(_match, type: string, scope: string | undefined, fullWidthScope: string | undefined, description: string) =>
|
|
91
|
+
`${type}${scope || fullWidthScope ? `(${scope || fullWidthScope})` : ""}: ${description.trim()}`,
|
|
92
|
+
);
|
|
93
|
+
lines[0] = normalizedTitle;
|
|
94
|
+
const normalizedText = lines.join("\n").trim();
|
|
95
|
+
if (!/^(feat|fix|perf|refactor|ci|build|chore|docs|test|style|revert)(\([^()\r\n]+\))?: [^\r\n]+$/.test(normalizedTitle))
|
|
88
96
|
throw new Error("模型返回的提交标题不符合约定格式,请重试或补充修改说明。");
|
|
89
|
-
if (
|
|
97
|
+
if (normalizedText.includes("更新代码与相关配置"))
|
|
90
98
|
throw new Error("模型返回了无具体业务含义的通用提交信息,请补充修改说明后重试。");
|
|
91
|
-
return
|
|
99
|
+
return normalizedText;
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
export default function (pi: ExtensionAPI) {
|
|
@@ -100,6 +100,15 @@ test('提供方或认证缺失时停止生成', async () => {
|
|
|
100
100
|
await assert.rejects(generateCommitMessage(ctx, 'diff', []), /提供方不可用/);
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
test('规范化模型返回的全角提交格式', async () => {
|
|
104
|
+
const result = await generateCommitMessage(
|
|
105
|
+
context(async () => response('fix(character):修复角色Renderer收集遗漏')),
|
|
106
|
+
'diff',
|
|
107
|
+
['角色.cs'],
|
|
108
|
+
);
|
|
109
|
+
assert.equal(result, 'fix(character): 修复角色Renderer收集遗漏');
|
|
110
|
+
});
|
|
111
|
+
|
|
103
112
|
test('拒绝空结果、异常完成、截断、非法格式和通用文案', async () => {
|
|
104
113
|
for (const result of [response(''), response('fix: 修复残留', 'error'), response('fix: 修复残留', 'length'), response('说明文字'), response('chore(GameClient): 更新代码与相关配置')]) {
|
|
105
114
|
await assert.rejects(generateCommitMessage(context(async () => result), 'diff', ['角色.cs']));
|