@@ -16,6 +16,8 @@ name: Auto Comment for Clarity
16
16
on :
17
17
issues :
18
18
types : [opened]
19
+ discussions :
20
+ types : [created]
19
21
jobs :
20
22
auto-comment :
21
23
runs-on : ubuntu-latest
@@ -33,27 +35,44 @@ jobs:
33
35
with :
34
36
github-token : ${{ secrets.GITHUB_TOKEN }}
35
37
script : |
36
- const issue_number = context.issue.number;
37
38
const owner = context.repo.owner;
38
39
const repo = context.repo.repo;
40
+
41
+ // Handle both issues and discussions
42
+ let title, body, number, targetType, targetUrl;
43
+
44
+ if (context.eventName === 'issues') {
45
+ number = context.issue.number;
46
+ title = context.payload.issue.title || '';
47
+ body = context.payload.issue.body || '';
48
+ targetType = 'issue';
49
+ targetUrl = context.payload.issue.html_url;
50
+ } else if (context.eventName === 'discussions') {
51
+ number = context.payload.discussion.number;
52
+ title = context.payload.discussion.title || '';
53
+ body = context.payload.discussion.body || '';
54
+ targetType = 'discussion';
55
+ targetUrl = context.payload.discussion.html_url;
56
+ } else {
57
+ console.log('Unsupported event type:', context.eventName);
58
+ return;
59
+ }
39
60
40
- // Get issue details
41
- const issueTitle = context.payload.issue.title || '';
42
- const issueBody = context.payload.issue.body || '';
43
-
44
- console.log('Issue Title:', issueTitle);
45
- console.log('Issue Body:', issueBody);
61
+ console.log('Target Type:', targetType);
62
+ console.log('Target Number:', number);
63
+ console.log('Title:', title);
64
+ console.log('Body:', body);
46
65
47
66
// Analyze what's missing specifically
48
- const hasDetailedDescription = issueBody .length > 50 && !issueBody .includes('No response');
49
- const hasStepsToReproduce = issueBody .toLowerCase().includes('步骤') || issueBody .toLowerCase().includes('重现') || issueBody .toLowerCase().includes('reproduce');
50
- const hasEnvironmentInfo = issueBody .toLowerCase().includes('环境') || issueBody .toLowerCase().includes('版本') || issueBody .toLowerCase().includes('version');
51
- const hasExpectedBehavior = issueBody .toLowerCase().includes('期望') || issueBody .toLowerCase().includes('expected');
52
- const hasErrorDetails = issueBody .toLowerCase().includes('错误') || issueBody .toLowerCase().includes('error') || issueBody .toLowerCase().includes('异常');
67
+ const hasDetailedDescription = body .length > 50 && !body .includes('No response');
68
+ const hasStepsToReproduce = body .toLowerCase().includes('步骤') || body .toLowerCase().includes('重现') || body .toLowerCase().includes('reproduce');
69
+ const hasEnvironmentInfo = body .toLowerCase().includes('环境') || body .toLowerCase().includes('版本') || body .toLowerCase().includes('version');
70
+ const hasExpectedBehavior = body .toLowerCase().includes('期望') || body .toLowerCase().includes('expected');
71
+ const hasErrorDetails = body .toLowerCase().includes('错误') || body .toLowerCase().includes('error') || body .toLowerCase().includes('异常');
53
72
54
73
// Check if this looks like a bug report that needs more info
55
- const isBugReport = issueTitle .toLowerCase().includes('bug') || issueTitle .toLowerCase().includes('错误');
56
- const hasVeryShortDescription = issueBody .trim().length < 30 || issueBody === 'No response' || issueBody .includes('这个怎么用') || issueBody .includes('不知道为什么');
74
+ const isBugReport = title .toLowerCase().includes('bug') || title .toLowerCase().includes('错误');
75
+ const hasVeryShortDescription = body .trim().length < 30 || body === 'No response' || body .includes('这个怎么用') || body .includes('不知道为什么');
57
76
58
77
// Generate dynamic comment based on what's missing
59
78
const missingItems = [];
87
106
// Only comment if there are missing items
88
107
if (missingItems.length > 0) {
89
108
let commentLines = [
90
- '👋 感谢您提交这个 issue!',
109
+ '👋 感谢您提交这个 ' + (targetType === ' issue' ? 'issue' : 'discussion') + ' !',
91
110
'',
92
111
'为了更好地帮助您解决问题,我发现以下信息需要补充:',
93
112
''
@@ -99,21 +118,32 @@ jobs:
99
118
});
100
119
101
120
commentLines.push('');
102
- commentLines.push('请编辑您的原始 issue 来添加这些信息,这将帮助我们更快地定位和解决问题。🙏');
121
+ commentLines.push('请编辑您的原始' + (targetType === ' issue' ? 'issue' : 'discussion') + ' 来添加这些信息,这将帮助我们更快地定位和解决问题。🙏');
103
122
commentLines.push('');
104
123
commentLines.push('---');
105
- commentLines.push('*这是一个自动生成的提醒,旨在提高 issue 的质量和解决效率。*');
124
+ commentLines.push('*这是一个自动生成的提醒,旨在提高' + (targetType === ' issue' ? 'issue' : 'discussion') + ' 的质量和解决效率。*');
106
125
107
126
const commentBody = commentLines.join('\n');
108
127
109
- await github.rest.issues.createComment({
110
- owner,
111
- repo,
112
- issue_number,
113
- body: commentBody
114
- });
115
- console.log('Posted targeted clarity request comment to issue #' + issue_number);
128
+ // Create comment based on target type
129
+ if (targetType === 'issue') {
130
+ await github.rest.issues.createComment({
131
+ owner,
132
+ repo,
133
+ issue_number: number,
134
+ body: commentBody
135
+ });
136
+ } else if (targetType === 'discussion') {
137
+ await github.rest.repos.createDiscussionComment({
138
+ owner,
139
+ repo,
140
+ discussion_number: number,
141
+ body: commentBody
142
+ });
143
+ }
144
+
145
+ console.log('Posted targeted clarity request comment to ' + targetType + ' #' + number);
116
146
console.log('Missing items:', missingItems.join(', '));
117
147
} else {
118
- console.log('Issue has sufficient information, no comment needed');
148
+ console.log(targetType + ' has sufficient information, no comment needed');
119
149
}
0 commit comments