Skip to content

Commit 8b73e16

Browse files
committed
🐛 Fix changelog generator
1 parent c51d0b0 commit 8b73e16

File tree

3 files changed

+99
-92
lines changed

3 files changed

+99
-92
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* eslint-disable */
2+
import { execSync } from "child_process";
3+
4+
// 获取最近一次发布的标签
5+
const lastRelease = execSync(
6+
"git for-each-ref --sort=-creatordate --format='%(refname:short)' \"refs/tags/v*\" | head -n 1",
7+
)
8+
.toString()
9+
.trim();
10+
11+
// 获取 Git 提交记录
12+
const commits = execSync(`git log ${lastRelease}..master --pretty=format:"%s" --reverse`).toString().trim();
13+
14+
// 定义提示信息
15+
const prompt = `请严格按以下规则处理 Git 提交记录:
16+
17+
■ 绝对禁令
18+
1. 禁止任何自然语言回复
19+
2. 禁止使用"好的""以下是"等引导语
20+
3. 禁止添加标题以外的任何解释性文本
21+
4. 禁止添加任何说明
22+
5. 禁止把输出放进Markdown代码块中
23+
6. 严禁添加 [English] 和 [中文] 等语言标签
24+
25+
■ 输出格式
26+
### 🚀 新功能 Features
27+
- 模块前缀: 中文描述
28+
英文描述 (必须换行且缩进对齐)
29+
30+
### 🐞 修复 Bug Fixes
31+
- 修复中文描述
32+
英文描述 (必须换行且缩进对齐)
33+
34+
■ 执行规范 (违规将导致格式错误)
35+
1. 以###标题为起始,无空行前缀
36+
2. 摘要部分直接显示内容,删除[ ]标签
37+
3. 功能/修复条目必须严格使用两级缩进:
38+
- 首行:中文 (带模块前缀)
39+
- 次行:英文 (首字母大写,无句号)
40+
4. 全文档禁用以下词汇:
41+
└─ 用户提供/整理如下/Changelog/根据记录/以下内容
42+
43+
■ 处理流程
44+
1. 过滤无效提交 → 2. 语义聚类 → 3. 生成摘要 → 4. 格式化输出`;
45+
46+
// 发送请求到 API
47+
const response = fetch(
48+
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-lite:generateContent?key=" +
49+
process.env.GEMINI_API_KEY,
50+
{
51+
method: "POST",
52+
headers: {
53+
"Content-Type": "application/json",
54+
},
55+
body: JSON.stringify({
56+
contents: [
57+
{
58+
role: "user",
59+
parts: [{ text: prompt }],
60+
},
61+
{
62+
role: "model",
63+
parts: [{ text: "好的!请提供 Git 提交历史记录,我会帮你整理成结构化的 Changelog。" }],
64+
},
65+
{
66+
role: "user",
67+
parts: [{ text: commits }],
68+
},
69+
],
70+
generationConfig: {
71+
temperature: 1.1,
72+
maxOutputTokens: 1000,
73+
topP: 1.0,
74+
topK: 1,
75+
},
76+
}),
77+
},
78+
);
79+
80+
response
81+
.then((res) => res.json())
82+
.then((data) => {
83+
const changelog = data.candidates[0].content.parts[0].text;
84+
85+
const finalChangelog = `${changelog}
86+
87+
---
88+
89+
###### Time range / 时间范围: ${lastRelease}..master
90+
###### [View full changelog / 查看完整更新日志](https://github.com/LiRenTech/project-graph/compare/${lastRelease}...master)
91+
###### Generated by Google Gemini / 由 Google Gemini 生成
92+
`;
93+
94+
console.log(finalChangelog);
95+
})
96+
.catch((err) => {
97+
console.error(err);
98+
});

.github/scripts/generate-changelog.sh

Lines changed: 0 additions & 91 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
aur_package_name: "project-graph-bin"
4343
delete_release: false
4444
prerelease: false
45-
release_name: "v${{ github.run_number }}"
45+
release_name: "v${{ inputs.version }}"
4646
release_notes: ${{ needs.generate-changelog.outputs.changelog }}
4747
release_tag: "v${{ inputs.version }}"
4848
task_build: "tauri:build"

0 commit comments

Comments
 (0)