Skip to content

Commit b73f2ee

Browse files
authored
Merge pull request #11 from LangMem/feat/ci_3
feat: add automatic summary comments for workflow results in issues
2 parents 7e03894 + 5f7cd18 commit b73f2ee

File tree

4 files changed

+325
-10
lines changed

4 files changed

+325
-10
lines changed

.github/workflows/auto-comment-for-clarity.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
steps:
3232
- name: Checkout repository
3333
uses: actions/checkout@v4
34-
34+
3535
- name: Create clarity prompt
3636
run: |
3737
mkdir -p /tmp/claude-prompts
3838
cat > /tmp/claude-prompts/clarity-prompt.txt << 'EOF'
3939
你是一个专业的社区助手。请分析以下 GitHub issue/discussion 的内容质量。
40-
40+
4141
任务:
4242
1. 使用 mcp__github__get_issue 获取内容详情
4343
2. 分析内容是否包含足够的信息:
@@ -46,23 +46,67 @@ jobs:
4646
- 是否包含期望行为
4747
- 是否包含环境信息
4848
3. 如果信息不足,使用 mcp__github__create_comment 添加友好的评论,要求补充信息
49-
49+
5050
评论模板:
5151
感谢您提交这个 issue/discussion!为了更好地帮助您,请补充以下信息:
5252
- [ ] 详细的问题描述
5353
- [ ] 重现步骤(如适用)
5454
- [ ] 期望的行为
5555
- [ ] 实际的行为
5656
- [ ] 环境信息(版本、操作系统等)
57-
57+
5858
请编辑您的原始 issue/discussion 来添加这些信息。
5959
EOF
60-
60+
6161
- name: Run Claude Code for Auto Comment
62+
id: claude_analysis
6263
uses: anthropics/claude-code-action@v1
6364
with:
6465
prompt: $(cat /tmp/claude-prompts/clarity-prompt.txt)
6566
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
6667
claude_args: |
6768
--allowedTools mcp__github__get_issue,mcp__github__create_comment
6869
--system-prompt "你是一个经验丰富的开源项目维护者,擅长识别高质量的 issue 报告"
70+
71+
- name: Post analysis summary as comment
72+
if: always()
73+
uses: actions/github-script@v7
74+
with:
75+
github-token: ${{ secrets.GITHUB_TOKEN }}
76+
script: |
77+
const issue_number = context.issue.number;
78+
const owner = context.repo.owner;
79+
const repo = context.repo.repo;
80+
81+
// Get Claude's analysis result
82+
const stepOutputs = ${{ toJson(steps.claude_analysis.outputs) }};
83+
const analysisResult = stepOutputs.response || stepOutputs.result || stepOutputs.output || '';
84+
85+
// Get workflow run URL
86+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${{ github.run_id }}`;
87+
88+
let commentBody = `## 🤖 Auto Comment Analysis Summary\n\n`;
89+
90+
if (analysisResult && analysisResult.trim() !== '') {
91+
commentBody += `**Claude Analysis Result:**\n\`\`\`\n${analysisResult}\n\`\`\`\n\n`;
92+
} else {
93+
commentBody += `**Status:** Analysis completed successfully.\n\n`;
94+
}
95+
96+
commentBody += `**Workflow Run:** [View Details](${runUrl})\n`;
97+
commentBody += `**Triggered by:** Issue #${issue_number}\n`;
98+
commentBody += `**Time:** ${new Date().toISOString()}\n\n`;
99+
commentBody += `---\n*This comment was automatically generated by the Auto Comment for Clarity workflow.*`;
100+
101+
// Only post if this is an issue event (not discussion)
102+
if (context.eventName === 'issues') {
103+
await github.rest.issues.createComment({
104+
owner,
105+
repo,
106+
issue_number,
107+
body: commentBody
108+
});
109+
console.log('Posted analysis summary to issue #' + issue_number);
110+
} else {
111+
console.log('Skipped posting comment - not an issue event');
112+
}

.github/workflows/claude.yml

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,30 @@ jobs:
3030
permissions:
3131
contents: read
3232
pull-requests: read
33-
issues: read
33+
issues: write
3434
id-token: write
3535
steps:
36-
- uses: anthropics/claude-code-action@v1
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 1
40+
41+
- name: Run Claude Assistant
42+
id: claude_assistant
43+
uses: anthropics/claude-code-action@v1
3744
with:
3845
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
3946
# Or use OAuth token instead:
4047
# claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
41-
48+
4249
# Optional: provide a prompt for automation workflows
4350
# prompt: "Review this PR for security issues"
44-
51+
4552
# Optional: pass advanced arguments to Claude CLI
4653
# claude_args: |
4754
# --max-turns 10
4855
# --model claude-4-0-sonnet-20250805
49-
56+
5057
# Optional: add custom trigger phrase (default: @claude)
5158
# trigger_phrase: "/claude"
5259
# Optional: add assignee trigger for issues
@@ -58,3 +65,51 @@ jobs:
5865
# actions: read
5966
# Optional: allow bot users to trigger the action
6067
# allowed_bots: "dependabot[bot],renovate[bot]"
68+
69+
- name: Post Claude assistant summary
70+
if: always() && (github.event_name == 'issues' || github.event_name == 'issue_comment')
71+
uses: actions/github-script@v7
72+
with:
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
74+
script: |
75+
const owner = context.repo.owner;
76+
const repo = context.repo.repo;
77+
78+
// Get issue number from different event types
79+
let issue_number;
80+
if (context.eventName === 'issues') {
81+
issue_number = context.issue.number;
82+
} else if (context.eventName === 'issue_comment') {
83+
issue_number = context.payload.issue.number;
84+
} else {
85+
console.log('Event type not supported for issue comments');
86+
return;
87+
}
88+
89+
// Get Claude's response
90+
const stepOutputs = ${{ toJson(steps.claude_assistant.outputs) }};
91+
const claudeResponse = stepOutputs.response || stepOutputs.result || stepOutputs.output || '';
92+
93+
// Get workflow run URL
94+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${{ github.run_id }}`;
95+
96+
let commentBody = `## 🤖 Claude Assistant Summary\n\n`;
97+
98+
if (claudeResponse && claudeResponse.trim() !== '') {
99+
commentBody += `**Claude Response:**\n\`\`\`\n${claudeResponse}\n\`\`\`\n\n`;
100+
} else {
101+
commentBody += `**Status:** Claude assistant completed processing.\n\n`;
102+
}
103+
104+
commentBody += `**Workflow Run:** [View Details](${runUrl})\n`;
105+
commentBody += `**Triggered by:** ${context.eventName}\n`;
106+
commentBody += `**Time:** ${new Date().toISOString()}\n\n`;
107+
commentBody += `---\n*This comment was automatically generated by the Claude Assistant workflow.*`;
108+
109+
await github.rest.issues.createComment({
110+
owner,
111+
repo,
112+
issue_number,
113+
body: commentBody
114+
});
115+
console.log('Posted Claude assistant summary to issue #' + issue_number);
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Copyright 2024-2026 the original author or authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Bidirectional Issue Translation and Update
16+
17+
on:
18+
issues:
19+
types: [opened]
20+
env:
21+
ANTHROPIC_BASE_URL: "https://open.bigmodel.cn/api/anthropic"
22+
jobs:
23+
translate_and_update:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
issues: write
28+
id-token: write
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 1
34+
35+
- name: Translate issue body with Claude (auto detect)
36+
id: translate
37+
uses: anthropics/claude-code-action@v1
38+
with:
39+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
40+
prompt: |
41+
你是一名专业的双语翻译。请自动检测下面文本的主要语言(只会是中文或英文):
42+
- 如果主要语言是中文,请将其准确、地道地翻译为英文,只返回英文翻译。
43+
- 如果主要语言是英文,请将其准确、地道地翻译为中文,只返回中文翻译。
44+
- 不要解释,不要输出原文,只返回翻译内容。
45+
---
46+
${{ github.event.issue.body }}
47+
48+
- name: Update issue body with original and translation
49+
uses: actions/github-script@v7
50+
with:
51+
github-token: ${{ secrets.GITHUB_TOKEN }}
52+
script: |
53+
const issue_number = context.issue.number;
54+
const owner = context.repo.owner;
55+
const repo = context.repo.repo;
56+
const orig = context.payload.issue.body || '';
57+
58+
// Get the translation from the previous step
59+
// Note: The exact output property may vary, trying common ones
60+
const stepOutputs = ${{ toJson(steps.translate.outputs) }};
61+
const translated = (stepOutputs.response || stepOutputs.result || stepOutputs.output || '').trim();
62+
63+
// Only update if we have a translation and it's different from original
64+
if (translated && translated !== orig && translated !== 'undefined') {
65+
const newBody = `## 原文 / Original\n${orig}\n\n## 翻译 / Translation\n${translated}`;
66+
await github.rest.issues.update({
67+
owner,
68+
repo,
69+
issue_number,
70+
body: newBody,
71+
});
72+
console.log('Successfully updated issue with translation');
73+
} else {
74+
console.log('No valid translation received or translation same as original');
75+
}
76+
77+
- name: Post translation workflow summary
78+
if: always()
79+
uses: actions/github-script@v7
80+
with:
81+
github-token: ${{ secrets.GITHUB_TOKEN }}
82+
script: |
83+
const issue_number = context.issue.number;
84+
const owner = context.repo.owner;
85+
const repo = context.repo.repo;
86+
87+
// Get translation result
88+
const stepOutputs = ${{ toJson(steps.translate.outputs) }};
89+
const translated = (stepOutputs.response || stepOutputs.result || stepOutputs.output || '').trim();
90+
const original = context.payload.issue.body || '';
91+
92+
// Get workflow run URL
93+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${{ github.run_id }}`;
94+
95+
let commentBody = `## 🌐 Translation Workflow Summary\n\n`;
96+
97+
if (translated && translated !== original && translated !== 'undefined') {
98+
// Detect language
99+
const isChineseOriginal = /[\u4e00-\u9fff]/.test(original);
100+
const targetLang = isChineseOriginal ? 'English' : 'Chinese';
101+
commentBody += `✅ **Translation completed successfully**\n`;
102+
commentBody += `- **Source language:** ${isChineseOriginal ? 'Chinese' : 'English'}\n`;
103+
commentBody += `- **Target language:** ${targetLang}\n`;
104+
commentBody += `- **Issue body has been updated** with both original and translated content\n\n`;
105+
} else {
106+
commentBody += `ℹ️ **Translation skipped**\n`;
107+
commentBody += `- Reason: Translation same as original or no valid translation received\n\n`;
108+
}
109+
110+
commentBody += `**Workflow Run:** [View Details](${runUrl})\n`;
111+
commentBody += `**Time:** ${new Date().toISOString()}\n\n`;
112+
commentBody += `---\n*This comment was automatically generated by the Translation workflow.*`;
113+
114+
await github.rest.issues.createComment({
115+
owner,
116+
repo,
117+
issue_number,
118+
body: commentBody
119+
});
120+
console.log('Posted translation summary to issue #' + issue_number);

WORKFLOW_SUMMARY_FEATURE.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Workflow Summary Feature
2+
3+
## 概述
4+
5+
我们已经为三个主要的 GitHub Actions 工作流添加了自动发布工作流运行结果摘要到 GitHub issue 评论的功能。
6+
7+
## 修改的工作流
8+
9+
### 1. `auto-comment-for-clarity.yml`
10+
11+
- **功能**: 分析 issue 质量并要求补充信息
12+
- **新增**: 发布 Claude 分析结果摘要到 issue 评论
13+
- **触发**: 当 issue 被创建时
14+
15+
### 2. `issue-translation.yml`
16+
17+
- **功能**: 自动检测语言并翻译 issue 内容
18+
- **新增**: 发布翻译工作流摘要到 issue 评论
19+
- **触发**: 当 issue 被创建时
20+
21+
### 3. `claude.yml`
22+
23+
- **功能**: Claude 助手响应评论和 issue
24+
- **新增**: 发布 Claude 助手摘要到 issue 评论
25+
- **触发**: issue 评论、PR 评论、issue 状态变化等
26+
27+
## 功能特性
28+
29+
### 自动摘要评论包含:
30+
31+
- ✅ 工作流执行状态
32+
- 📊 主要结果内容
33+
- 🔗 工作流运行详情链接
34+
- ⏰ 执行时间戳
35+
- 🏷️ 触发事件信息
36+
37+
### 条件执行:
38+
39+
- 使用 `if: always()` 确保即使前面步骤失败也会发布摘要
40+
- 智能检测事件类型,只在相关的 issue 上发布评论
41+
- 避免在 discussion 或 PR 事件上误发评论
42+
43+
## 示例评论格式
44+
45+
### Translation Workflow Summary
46+
47+
```markdown
48+
## 🌐 Translation Workflow Summary
49+
50+
✅ **Translation completed successfully**
51+
52+
- **Source language:** Chinese
53+
- **Target language:** English
54+
- **Issue body has been updated** with both original and translated content
55+
56+
**Workflow Run:** [View Details](https://github.com/LangMem/mem4j/actions/runs/12345)
57+
**Time:** 2025-09-05T06:50:00.000Z
58+
59+
---
60+
61+
_This comment was automatically generated by the Translation workflow._
62+
```
63+
64+
### Auto Comment Analysis Summary
65+
66+
```markdown
67+
## 🤖 Auto Comment Analysis Summary
68+
69+
**Claude Analysis Result:**
70+
```
71+
72+
Issue quality analysis completed. Additional information requested from user.
73+
74+
```
75+
76+
**Workflow Run:** [View Details](https://github.com/LangMem/mem4j/actions/runs/12346)
77+
**Triggered by:** Issue #10
78+
**Time:** 2025-09-05T06:50:00.000Z
79+
80+
---
81+
*This comment was automatically generated by the Auto Comment for Clarity workflow.*
82+
```
83+
84+
## 技术实现
85+
86+
1. **步骤标识**: 为 Claude 步骤添加了 `id` 属性以捕获输出
87+
2. **输出捕获**: 使用 `${{ toJson(steps.step_id.outputs) }}` 获取执行结果
88+
3. **条件执行**: 使用 `if: always()` 和事件类型检查
89+
4. **权限更新**: 确保工作流有 `issues: write` 权限
90+
91+
## 好处
92+
93+
- 🔍 **透明度**: 用户可以直接在 issue 中看到自动化工作流的执行结果
94+
- 📋 **审计**: 完整的执行历史记录和链接
95+
- 🚀 **效率**: 减少需要手动检查 Actions 页面的需求
96+
- 🤝 **用户体验**: 更好的社区交互和反馈

0 commit comments

Comments
 (0)