|
1 | | -function generateSlackPayload({ type, repo, issue, slackIDType, slackID }) { |
| 1 | +const generateSlackContent = (slackIDType, slackIDs) => { |
| 2 | + let content = ""; |
| 3 | + let isAssignee = false; |
| 4 | + if (slackIDType === "user") { |
| 5 | + if (slackIDs) { |
| 6 | + const slackIDsArray = slackIDs.split(","); |
| 7 | + slackIDsArray.forEach(id => { |
| 8 | + if (id.trim() !== "") { |
| 9 | + isAssignee = true; |
| 10 | + content += `<@${id.trim()}> `; |
| 11 | + } |
| 12 | + }); |
| 13 | + if (isAssignee) { |
| 14 | + content = `*Assignee:* ` + content; |
| 15 | + } |
| 16 | + } |
| 17 | + } else if (slackIDType === "group") { |
| 18 | + if (slackIDs) { |
| 19 | + const slackIDsArray = slackIDs.split(","); |
| 20 | + slackIDsArray.forEach(id => { |
| 21 | + if (id.trim() !== "") { |
| 22 | + isAssignee = true; |
| 23 | + content += `<!subteam^${id.trim()}> `; |
| 24 | + } |
| 25 | + }); |
| 26 | + if (isAssignee) { |
| 27 | + content = `*Assignee:* ` + content; |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + return content; |
| 32 | +} |
| 33 | + |
| 34 | +function generateSlackPayload({ type, repo, issue, slackIDType, slackIDs }) { |
2 | 35 | let assigneeText = ""; |
3 | 36 | const shouldDisplayAvatar = true; |
4 | 37 |
|
5 | 38 | if (type === "issue") { |
6 | | - assigneeText = |
7 | | - slackIDType === "group" |
8 | | - ? `*Assignee:* <!subteam^${slackID}>` |
9 | | - : slackIDType === "user" |
10 | | - ? `*Assignee:* <@${slackID}>` |
11 | | - : ""; |
| 39 | + assigneeText = generateSlackContent(slackIDType, slackIDs); |
12 | 40 |
|
13 | 41 | return { |
14 | 42 | text: `📈 New Issue in ${repo}: ${issue.title}`, // Fallback text for notifications |
@@ -75,12 +103,7 @@ function generateSlackPayload({ type, repo, issue, slackIDType, slackID }) { |
75 | 103 | ], |
76 | 104 | }; |
77 | 105 | } else if (type === "pr") { |
78 | | - assigneeText = |
79 | | - slackIDType === "group" |
80 | | - ? `*Reviewer:* <!subteam^${slackID}> ` |
81 | | - : slackIDType === "user" |
82 | | - ? `*Reviewer:* <@${slackID}> ` |
83 | | - : ""; |
| 106 | + assigneeText = generateSlackContent(slackIDType, slackIDs); |
84 | 107 |
|
85 | 108 | return { |
86 | 109 | text: `🚀 New Pull Request in ${repo}: ${issue.title}`, // Fallback text for notifications |
@@ -153,22 +176,41 @@ function generateSlackPayload({ type, repo, issue, slackIDType, slackID }) { |
153 | 176 | } |
154 | 177 | } |
155 | 178 |
|
| 179 | +const generateDiscordContent = (discordIDType, discordIDs) => { |
| 180 | + let content = ""; |
| 181 | + if (discordIDType === "user") { |
| 182 | + if (discordIDs) { |
| 183 | + const discordIDsArray = discordIDs.split(","); |
| 184 | + discordIDsArray.forEach(id => { |
| 185 | + if (id.trim() !== "") { |
| 186 | + content += `<@${id.trim()}> `; |
| 187 | + } |
| 188 | + }); |
| 189 | + } |
| 190 | + } else if (discordIDType === "role") { |
| 191 | + if (discordIDs) { |
| 192 | + const discordIDsArray = discordIDs.split(","); |
| 193 | + discordIDsArray.forEach(id => { |
| 194 | + if (id.trim() !== "") { |
| 195 | + content += `<@&${id.trim()}> `; |
| 196 | + } |
| 197 | + }); |
| 198 | + } |
| 199 | + } |
| 200 | + return content; |
| 201 | +} |
| 202 | + |
| 203 | + |
156 | 204 | const generateDiscordPayload = ({ |
157 | 205 | type, |
158 | 206 | repo, |
159 | 207 | issue, |
160 | 208 | discordIDType, |
161 | | - discordID, |
| 209 | + discordIDs, |
162 | 210 | }) => { |
163 | | - let content = ""; |
| 211 | + let content = generateDiscordContent(discordIDType, discordIDs); |
164 | 212 | let message = ""; |
165 | 213 |
|
166 | | - if (discordIDType === "user") { |
167 | | - content = `<@${discordID}>`; |
168 | | - } else if (discordIDType === "role") { |
169 | | - content = `<@&${discordID}>`; |
170 | | - } |
171 | | - |
172 | 214 | if (type === "issue") { |
173 | 215 | message = { |
174 | 216 | content: content, |
|
0 commit comments