-
Notifications
You must be signed in to change notification settings - Fork 750
170 lines (143 loc) · 7.45 KB
/
release-comment-handler.yml
File metadata and controls
170 lines (143 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Release Comment Handler
on:
issues:
types:
- labeled
jobs:
comment_on_label:
if: github.event.label.name == 'prerelease' || github.event.label.name == 'fixed'
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Gather participants
id: participants
uses: actions/github-script@v7
with:
script: |
console.log("=== WORKFLOW START ===");
const issue_number = context.payload.issue.number;
const repo = context.repo;
console.log(`Processing issue #${issue_number} in ${repo.owner}/${repo.repo}`);
// Get issue details (for author)
const issue = context.payload.issue;
const author = issue.user.login;
console.log(`Issue author: ${author}`);
// Use a Set to track all unique participants (normalized to lowercase for deduplication)
const all_participants = new Set();
// Add the issue author
all_participants.add(author.toLowerCase());
console.log(`Added author to participants: ${author.toLowerCase()}`);
// Get all comments and add commenters
console.log("=== FETCHING COMMENTS ===");
const comments = await github.paginate(
github.rest.issues.listComments,
{ ...repo, issue_number }
);
console.log(`Found ${comments.length} comments`);
if (comments.length === 0) {
console.log("❌ NO COMMENTS FOUND - This might be why no users are tagged");
}
comments.forEach((c, index) => {
const commenter = c.user.login.toLowerCase();
all_participants.add(commenter);
console.log(`Comment #${index + 1}: Added commenter: ${commenter} (original: ${c.user.login})`);
});
// Get all reactions from comments
let totalCommentReactions = 0;
for (const comment of comments) {
const reactions = await github.paginate(
github.rest.reactions.listForIssueComment,
{ ...repo, comment_id: comment.id }
);
totalCommentReactions += reactions.length;
reactions.forEach(r => {
const reactor = r.user.login.toLowerCase();
all_participants.add(reactor);
console.log(`Added comment reactor: ${reactor}`);
});
}
console.log(`Processed ${totalCommentReactions} reactions from comments`);
// Get reactions on main issue body
const issue_reactions = await github.paginate(
github.rest.reactions.listForIssue,
{ ...repo, issue_number }
);
console.log(`Found ${issue_reactions.length} reactions on issue body`);
issue_reactions.forEach(r => {
const reactor = r.user.login.toLowerCase();
all_participants.add(reactor);
console.log(`Added issue reactor: ${reactor}`);
});
console.log(`Total unique participants before bot filtering: ${all_participants.size}`);
console.log(`Participants: ${Array.from(all_participants).join(', ')}`);
// Filter out bot users
const isBotUser = (username) => {
const lowerUsername = username.toLowerCase();
return lowerUsername.endsWith('[bot]') ||
lowerUsername === 'dependabot' ||
lowerUsername === 'renovate' ||
lowerUsername === 'greenkeeper' ||
lowerUsername === 'codecov' ||
lowerUsername === 'coveralls' ||
lowerUsername.startsWith('dependabot[') ||
lowerUsername.includes('-bot') ||
lowerUsername.includes('_bot');
};
// Convert Set to array and filter out bots
const all_users = Array.from(all_participants).filter(user => !isBotUser(user));
const filteredBots = Array.from(all_participants).filter(user => isBotUser(user));
console.log(`Filtered out ${filteredBots.length} bot users: ${filteredBots.join(', ')}`);
console.log(`Final participants count: ${all_users.length}`);
console.log(`Final participants: ${all_users.join(', ')}`);
if (all_users.length === 0) {
console.log("No participants to mention after filtering");
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_ENV, 'MENTIONS=\n');
return;
}
const mentions = all_users.map(u => `@${u}`).join(' ');
console.log(`Generated mentions: ${mentions}`);
console.log(`Setting environment variable 'MENTIONS' to: "${mentions}"`);
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_ENV, `MENTIONS=${mentions}\n`);
return { mentions: mentions };
result-encoding: string
- name: Add label comment
uses: actions/github-script@v7
with:
script: |
console.log("=== STEP 2: ADD COMMENT ===");
console.log("Environment variable access:");
console.log("process.env.MENTIONS:", process.env.MENTIONS);
const mentions = process.env.MENTIONS || '';
const labelName = context.payload.label.name;
console.log(`Processing label: ${labelName}`);
console.log(`Mentions received: "${mentions}"`);
console.log(`Mentions length: ${mentions.length}`);
console.log(`Mentions trimmed length: ${mentions.trim().length}`);
let message;
if (labelName === 'prerelease') {
console.log("Processing prerelease label");
if (mentions.trim() === "") {
console.log("No participants to mention for prerelease. Skipping comment creation.");
return;
}
message = `${mentions}\n\nA fix for this issue is now available in the next pre-releases of C#DK/C#. If you'd like to try out the fix, please see [these instructions](https://github.com/microsoft/vscode-dotnettools/wiki/Installing-and-updating-pre%E2%80%90release-versions-of-C%23-Dev-Kit-and-C%23-Extension) to update or try pre-release versions.`;
console.log("Generated prerelease message");
} else if (labelName === 'fixed') {
console.log("Processing fixed label");
message = mentions.trim() !== ""
? `${mentions}\n\nThis issue has been fixed! Please update to the latest versions of VS Code, C# Dev Kit, and the C# extension.`
: `This issue has been fixed! Please update to the latest versions of VS Code, C# Dev Kit, and the C# extension.`;
console.log(`Generated fixed message ${mentions.trim() !== "" ? "with" : "without"} mentions`);
}
console.log(`Final message length: ${message.length}`);
console.log(`Creating comment on issue #${context.payload.issue.number}`);
await github.rest.issues.createComment({
...context.repo,
issue_number: context.payload.issue.number,
body: message
});
console.log("Comment created successfully");