Skip to content

Commit c63ae98

Browse files
committed
feat: implement JSX transformation core and bundling
1 parent 48ef191 commit c63ae98

File tree

1 file changed

+143
-73
lines changed

1 file changed

+143
-73
lines changed

.github/workflows/commit-summary.yml

Lines changed: 143 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
push:
55
branches: [master]
66
paths-ignore:
7-
- 'notes-react/commit_summary.md'
7+
- 'notes-react/commit_summary.md'
8+
- 'notes-react/ai-notes/**'
89

910
jobs:
1011
summarize:
@@ -14,96 +15,165 @@ jobs:
1415
with:
1516
fetch-depth: 0
1617

17-
- name: Run GPT Commit Summarizer
18-
uses: KanHarI/gpt-commit-summarizer@master
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
1920
with:
20-
openai-api-key: ${{ secrets.DEEPSEEK_API_KEY }}
21-
openai-base-url: 'https://api.deepseek.com'
22-
mode: "commit"
23-
output-file: "notes-react/commit_notes.md"
24-
max-commits: 1
25-
exclude-merge: true
26-
27-
custom-prompt: |
28-
我正在手写 React 源码来深入学习 React 的内部实现原理。请分析这次提交,生成有助于理解 React 源码的学习笔记:
29-
30-
## 🔧 技术实现
31-
- 具体实现了React 源码中什么功能或特性
32-
- 涉及了哪些重要的 React 概念
33-
34-
## 💡 设计思路
35-
- 为什么选择这种实现方式
36-
- 有实现什么优化
37-
38-
## 📚 源码学习收获
39-
- 通过手写这部分代码,对 React 内部机制有了什么新的理解?
40-
- 这个实现帮助理解了 React 的哪些工作原理?
41-
- 发现了哪些之前不知道的 React 内部细节?
42-
- 这个知识点如何连接到 React 的整体架构中?
43-
44-
45-
请用中文回答,重点突出对 React 源码理解的帮助,内容要深入且实用。
21+
node-version: '18'
4622

47-
- name: Format and Commit Notes
23+
- name: Install dependencies
4824
run: |
49-
git config user.name "github-actions"
50-
git config user.email "actions@github.com"
51-
52-
# 检查是否生成了新的总结
53-
if [[ -f "notes-react/commit_notes.md" ]]; then
54-
55-
# 获取提交信息
56-
COMMIT_HASH=$(git rev-parse HEAD | cut -c1-8)
57-
COMMIT_MSG=$(git log -1 --pretty=%s)
58-
COMMIT_DATE=$(date +"%Y-%m-%d %H:%M")
59-
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
60-
61-
# 创建格式化的笔记条目
62-
cat > temp_note.md << EOF
63-
25+
npm install openai dayjs
26+
27+
- name: Create AI commit analysis script
28+
run: |
29+
cat > analyze-commit.js << 'EOF'
30+
import fs from 'fs';
31+
import { execSync } from 'child_process';
32+
import dayjs from 'dayjs';
33+
import OpenAI from 'openai';
34+
35+
const openai = new OpenAI({
36+
baseURL: 'https://api.deepseek.com',
37+
apiKey: process.env.DEEPSEEK_API_KEY
38+
});
39+
40+
async function analyzeCommit() {
41+
try {
42+
// 获取最新提交的信息
43+
const commitHash = execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
44+
const commitMsg = execSync('git log -1 --pretty=%s', { encoding: 'utf-8' }).trim();
45+
const commitAuthor = execSync('git log -1 --pretty=%an', { encoding: 'utf-8' }).trim();
46+
const commitDate = dayjs().format('YYYY-MM-DD HH:mm:ss');
47+
48+
// 获取提交的文件变更
49+
const changedFiles = execSync('git diff-tree --no-commit-id --name-only -r HEAD', { encoding: 'utf-8' })
50+
.trim().split('\n').filter(f => f);
51+
52+
// 获取提交的差异(限制长度)
53+
const diff = execSync('git show HEAD --format="" --no-color', { encoding: 'utf-8' }).substring(0, 8000);
54+
55+
// 构建 AI 分析提示
56+
const prompt = `
57+
我正在手写 React 源码来深入学习 React 的内部实现原理。请分析这次提交,生成有助于理解 React 源码的学习笔记:
58+
59+
## 📝 提交信息
60+
**提交**: ${commitHash.substring(0, 8)}
61+
**消息**: ${commitMsg}
62+
**作者**: ${commitAuthor}
63+
**时间**: ${commitDate}
64+
**变更文件**: ${changedFiles.join(', ')}
65+
66+
## 💻 代码变更
67+
\`\`\`diff
68+
${diff}
69+
\`\`\`
70+
71+
请生成详细的学习总结,包含以下内容:
72+
73+
## 🔧 技术实现
74+
- 具体实现了React 源码中什么功能或特性
75+
- 涉及了哪些重要的 React 概念
76+
77+
## 💡 设计思路
78+
- 为什么选择这种实现方式
79+
- 有实现什么优化
80+
81+
## 📚 源码学习收获
82+
- 通过手写这部分代码,对 React 内部机制有了什么新的理解?
83+
- 这个实现帮助理解了 React 的哪些工作原理?
84+
- 发现了哪些之前不知道的 React 内部细节?
85+
- 这个知识点如何连接到 React 的整体架构中?
86+
87+
请用中文回答,重点突出对 React 源码理解的帮助,内容要深入且实用。
88+
`;
89+
90+
// 调用 AI 生成分析
91+
const response = await openai.chat.completions.create({
92+
model: 'deepseek-chat',
93+
messages: [{ role: 'user', content: prompt }],
94+
temperature: 0.7,
95+
max_tokens: 4000
96+
});
97+
98+
const analysis = response.choices[0].message.content.trim();
99+
100+
// 创建格式化的总结
101+
const summary = `
64102
============================================================
65-
📅 ${COMMIT_DATE} - 提交 ${COMMIT_HASH}
103+
📅 ${commitDate} - 提交 ${commitHash.substring(0, 8)}
66104
============================================================
67-
68-
# 📝 ${COMMIT_MSG}
69-
70-
> **提交**: \`${COMMIT_HASH}\` | **时间**: ${COMMIT_DATE} | **作者**: ${COMMIT_AUTHOR}
71-
72-
$(cat notes-react/commit_notes.md)
73-
105+
106+
# 📝 ${commitMsg}
107+
108+
> **提交**: \`${commitHash.substring(0, 8)}\` | **时间**: ${commitDate} | **作者**: ${commitAuthor}
109+
110+
${analysis}
111+
74112
------------------------------------------------------------
75-
76-
EOF
77-
78-
# 如果是第一次创建文件,添加专门的头部
79-
if [[ ! -f "notes-react/commit_summary.md" ]]; then
80-
cat > notes-react/commit_summary.md << EOF
81-
# 🤖 React 源码学习笔记
82-
113+
114+
`;
115+
116+
// 确保目录存在
117+
if (!fs.existsSync('notes-react')) {
118+
fs.mkdirSync('notes-react', { recursive: true });
119+
}
120+
121+
// 如果是第一次创建文件,添加头部
122+
if (!fs.existsSync('notes-react/commit_summary.md')) {
123+
const header = `# 🤖 React 源码学习笔记
124+
83125
> 手写 React 源码的学习记录,专注于理解 React 内部实现原理
84126
>
85127
> **学习目标**: 深入理解 React 的核心机制、设计思路和架构原理
86-
128+
129+
`;
130+
fs.writeFileSync('notes-react/commit_summary.md', header, 'utf-8');
131+
}
132+
133+
// 将新总结添加到文件开头
134+
const existingContent = fs.readFileSync('notes-react/commit_summary.md', 'utf-8');
135+
const newContent = existingContent.replace(
136+
/(# 🤖 React 源码学习笔记[\s\S]*?\n\n)/,
137+
`$1${summary}`
138+
);
139+
140+
fs.writeFileSync('notes-react/commit_summary.md', newContent, 'utf-8');
141+
142+
console.log('✅ Commit analysis completed and saved to notes-react/commit_summary.md');
143+
144+
} catch (error) {
145+
console.error('❌ Error analyzing commit:', error.message);
146+
process.exit(1);
147+
}
148+
}
149+
150+
analyzeCommit();
87151
EOF
88-
fi
89-
90-
# 将新笔记追加到总结文件开头(最新的在上面)
91-
cat temp_note.md notes-react/commit_summary.md > temp_combined.md
92-
mv temp_combined.md notes-react/commit_summary.md
93-
94-
# 清理临时文件
95-
rm -f temp_note.md notes-react/commit_notes.md
96-
97-
# 提交更新
152+
153+
- name: Run commit analysis
154+
env:
155+
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
156+
run: |
157+
node analyze-commit.js
158+
159+
- name: Commit and Push Summary
160+
run: |
161+
git config user.name "github-actions"
162+
git config user.email "actions@github.com"
163+
164+
# 检查是否有变更需要提交
165+
if [[ -f "notes-react/commit_summary.md" ]]; then
98166
git add notes-react/commit_summary.md
99167
100168
if ! git diff --staged --quiet; then
169+
COMMIT_HASH=$(git rev-parse HEAD | cut -c1-8)
170+
COMMIT_MSG=$(git log -1 --pretty=%s)
101171
git commit -m "📝 React源码学习: ${COMMIT_MSG} (${COMMIT_HASH}) [skip ci]"
102172
git push
103173
echo "✅ Commit summary updated and pushed"
104174
else
105175
echo "ℹ️ No changes to commit"
106176
fi
107177
else
108-
echo "❌ commit_notes.md not found"
178+
echo "❌ commit_summary.md not found"
109179
fi

0 commit comments

Comments
 (0)