|
76 | 76 | $ChatMsg = "🐛 [{$User}](https://github.com/{$User}) **{$Action}** issue [#{$Issue['number']} {$IssueTitle}]({$IssueUrl}) " |
77 | 77 | . "in [{$RepositoryName}](https://github.com/{$RepositoryName})."; |
78 | 78 |
|
| 79 | + if (!empty($Issue['labels'])) { |
| 80 | + $Labels = array_map(fn($l) => "`{$l['name']}`", $Issue['labels']); |
| 81 | + $ChatMsg .= " " . implode(' ', $Labels); |
| 82 | + } |
| 83 | + |
| 84 | + if ($Action === 'closed' && !empty($Issue['state_reason'])) { |
| 85 | + $ChatMsg .= " _(reason: {$Issue['state_reason']})_"; |
| 86 | + } |
| 87 | + |
| 88 | + if ($Action === 'edited' && !empty($Message['changes'])) { |
| 89 | + $Changed = array_keys($Message['changes']); |
| 90 | + $ChatMsg .= " _(changed: " . implode(', ', $Changed) . ")_"; |
| 91 | + } |
| 92 | + |
79 | 93 | if (!empty($Issue['body'])) { |
80 | 94 | $ChatMsg .= "\n\n> " . substr($Issue['body'], 0, 500) . (strlen($Issue['body']) > 500 ? "…" : ""); |
81 | 95 | } |
|
89 | 103 | $Action = $Message['action']; |
90 | 104 | $PRUrl = $PR['html_url']; |
91 | 105 | $PRTitle = $PR['title']; |
| 106 | + $HeadBranch = $PR['head']['ref'] ?? ''; |
| 107 | + $BaseBranch = $PR['base']['ref'] ?? ''; |
92 | 108 |
|
93 | 109 | $ChatMsg = "🔀 [{$User}](https://github.com/{$User}) **{$Action}** pull request " |
94 | 110 | . "[#{$PR['number']} {$PRTitle}]({$PRUrl}) " |
95 | | - . "in [{$RepositoryName}](https://github.com/{$RepositoryName})."; |
| 111 | + . "in [{$RepositoryName}](https://github.com/{$RepositoryName})"; |
| 112 | + |
| 113 | + if ($HeadBranch && $BaseBranch) { |
| 114 | + $ChatMsg .= " (`{$HeadBranch}` → `{$BaseBranch}`)"; |
| 115 | + } |
| 116 | + $ChatMsg .= "."; |
| 117 | + |
| 118 | + if (!empty($PR['draft'])) { |
| 119 | + $ChatMsg .= " _(draft)_"; |
| 120 | + } |
| 121 | + |
| 122 | + if ($Action === 'closed' && !empty($PR['merged'])) { |
| 123 | + $ChatMsg .= " ✅ Merged."; |
| 124 | + } |
| 125 | + |
| 126 | + if (in_array($Action, ['opened', 'reopened', 'closed']) && isset($PR['commits'])) { |
| 127 | + $Stats = []; |
| 128 | + if (!empty($PR['commits'])) { |
| 129 | + $Stats[] = "{$PR['commits']} commit" . ($PR['commits'] !== 1 ? "s" : ""); |
| 130 | + } |
| 131 | + if (isset($PR['additions'], $PR['deletions'])) { |
| 132 | + $Stats[] = "+{$PR['additions']}/-{$PR['deletions']}"; |
| 133 | + } |
| 134 | + if (!empty($PR['changed_files'])) { |
| 135 | + $Stats[] = "{$PR['changed_files']} file" . ($PR['changed_files'] !== 1 ? "s" : ""); |
| 136 | + } |
| 137 | + if (!empty($Stats)) { |
| 138 | + $ChatMsg .= " _(" . implode(', ', $Stats) . ")_"; |
| 139 | + } |
| 140 | + } |
96 | 141 |
|
97 | 142 | if (!empty($PR['body'])) { |
98 | 143 | $ChatMsg .= "\n\n> " . substr($PR['body'], 0, 500) . (strlen($PR['body']) > 500 ? "…" : ""); |
|
109 | 154 |
|
110 | 155 | if (!empty($Message['commits'])) { |
111 | 156 | foreach ($Message['commits'] as $Commit) { |
112 | | - $Commits[] = "• [".substr($Commit['id'], 0, 7)."]({$Commit['url']}) _{$Commit['message']}_ " |
113 | | - . "by {$Commit['author']['name']}"; |
| 157 | + $CommitMsg = strtok($Commit['message'], "\n"); |
| 158 | + $FileCounts = []; |
| 159 | + if (!empty($Commit['added'])) $FileCounts[] = '+' . count($Commit['added']); |
| 160 | + if (!empty($Commit['modified'])) $FileCounts[] = '~' . count($Commit['modified']); |
| 161 | + if (!empty($Commit['removed'])) $FileCounts[] = '-' . count($Commit['removed']); |
| 162 | + $FileInfo = !empty($FileCounts) ? ' _(' . implode(' ', $FileCounts) . ' files)_' : ''; |
| 163 | + $Commits[] = "• [" . substr($Commit['id'], 0, 7) . "]({$Commit['url']}) _{$CommitMsg}_ " |
| 164 | + . "by {$Commit['author']['name']}{$FileInfo}"; |
114 | 165 | } |
115 | 166 | } |
116 | 167 |
|
|
119 | 170 | . " to [{$RepositoryName}](https://github.com/{$RepositoryName}) " |
120 | 171 | . "[`{$Branch}`](https://github.com/{$RepositoryName}/tree/{$Branch})"; |
121 | 172 |
|
| 173 | + if (!empty($Message['compare'])) { |
| 174 | + $ChatMsg .= " ([compare]({$Message['compare']}))"; |
| 175 | + } |
| 176 | + |
122 | 177 | if (!empty($Commits)) { |
123 | 178 | $ChatMsg .= "\n" . implode("\n", $Commits); |
124 | 179 | } |
|
132 | 187 | $Status = $Message['check_suite']['conclusion'] ?? $Message['check_run']['conclusion'] ?? 'in_progress'; |
133 | 188 | $Name = $Message['check_suite']['app']['name'] ?? $Message['check_run']['name']; |
134 | 189 | $Url = $Message['check_suite']['url'] ?? $Message['check_run']['html_url']; |
| 190 | + $Branch = $Message['check_suite']['head_branch'] ?? $Message['check_run']['check_suite']['head_branch'] ?? ''; |
| 191 | + $CommitMsg = $Message['check_suite']['head_commit']['message'] ?? $Message['check_run']['check_suite']['head_commit']['message'] ?? ''; |
135 | 192 |
|
136 | 193 | $Emoji = $Status === 'success' ? "✅" : ($Status === 'failure' ? "❌" : "⏳"); |
137 | 194 | $ChatMsg = "{$Emoji} Check **{$Name}** {$Status} " |
138 | | - . "for [{$RepositoryName}](https://github.com/{$RepositoryName}) " |
139 | | - . "([details]({$Url}))"; |
| 195 | + . "for [{$RepositoryName}](https://github.com/{$RepositoryName})"; |
| 196 | + if ($Branch) { |
| 197 | + $ChatMsg .= " on `{$Branch}`"; |
| 198 | + } |
| 199 | + $ChatMsg .= " ([details]({$Url}))"; |
| 200 | + if ($CommitMsg) { |
| 201 | + $CommitMsg = strtok($CommitMsg, "\n"); |
| 202 | + $ChatMsg .= "\n> _{$CommitMsg}_"; |
| 203 | + } |
140 | 204 |
|
141 | 205 | $Msg['text'] = $ChatMsg; |
142 | 206 | //SendToChat('notifications', $Msg, $useRC, $useTeams); |
143 | 207 | break; |
144 | 208 |
|
145 | 209 | case 'workflow_run': |
146 | 210 | case 'workflow_job': |
147 | | - $Workflow = $Message['workflow']['name'] ?? $Message['workflow_job']['name'] ?? "Workflow"; |
148 | | - $Status = $Message['workflow_run']['conclusion'] ?? $Message['workflow_job']['conclusion'] ?? "in_progress"; |
149 | | - $Url = $Message['workflow_run']['html_url'] ?? "#"; |
150 | | - $Emoji = $Status === 'success' ? "✅" : ($Status === 'failure' ? "❌" : "⏳"); |
| 211 | + $WorkflowName = $Message['workflow_run']['name'] ?? $Message['workflow']['name'] ?? $Message['workflow_job']['workflow_name'] ?? $Message['workflow_job']['name'] ?? "Workflow"; |
| 212 | + $Status = $Message['workflow_run']['conclusion'] ?? $Message['workflow_job']['conclusion'] ?? $Message['workflow_run']['status'] ?? $Message['workflow_job']['status'] ?? "in_progress"; |
| 213 | + $Url = $Message['workflow_run']['html_url'] ?? $Message['workflow_job']['html_url'] ?? "#"; |
| 214 | + $Branch = $Message['workflow_run']['head_branch'] ?? $Message['workflow_job']['head_branch'] ?? ''; |
| 215 | + $Emoji = $Status === 'success' ? "✅" : ($Status === 'failure' ? "❌" : ($Status === 'in_progress' ? "⏳" : "🔄")); |
151 | 216 |
|
152 | | - $ChatMsg = "{$Emoji} Workflow **{$Workflow}** {$Status} " |
153 | | - . "for [{$RepositoryName}](https://github.com/{$RepositoryName}) " |
154 | | - . "([view run]({$Url}))"; |
| 217 | + $ChatMsg = "{$Emoji} Workflow **{$WorkflowName}** {$Status} " |
| 218 | + . "for [{$RepositoryName}](https://github.com/{$RepositoryName})"; |
| 219 | + if ($Branch) { |
| 220 | + $ChatMsg .= " on `{$Branch}`"; |
| 221 | + } |
| 222 | + $ChatMsg .= " ([view run]({$Url}))"; |
| 223 | + |
| 224 | + if ($EventType === 'workflow_run' && !empty($Message['workflow_run']['head_commit']['message'])) { |
| 225 | + $HeadCommitMsg = strtok($Message['workflow_run']['head_commit']['message'], "\n"); |
| 226 | + $ChatMsg .= "\n> _{$HeadCommitMsg}_"; |
| 227 | + } |
| 228 | + |
| 229 | + if ($EventType === 'workflow_job' && !empty($Message['workflow_job']['steps'])) { |
| 230 | + foreach ($Message['workflow_job']['steps'] as $Step) { |
| 231 | + if ($Step['status'] === 'in_progress') { |
| 232 | + $ChatMsg .= "\n> Step: _{$Step['name']}_"; |
| 233 | + break; |
| 234 | + } |
| 235 | + } |
| 236 | + } |
155 | 237 |
|
156 | 238 | $Msg['text'] = $ChatMsg; |
157 | 239 | //SendToChat('notifications', $Msg, $useRC, $useTeams); |
158 | 240 | break; |
159 | 241 | case 'gollum': |
160 | | - $ChatMsg = "ℹ️ {$Msg['alias']} triggered a **{$EventType}** event " |
161 | | - . (isset($Message['data']['pages'][0]['action']) ? "({$Message['data']['pages'][0]['action']} [{$Message['data']['pages'][0]['title']}]({$Message['data']['pages'][0]['html_url']})) " : "") |
162 | | - . "on [{$RepositoryName}](https://github.com/{$RepositoryName})."; |
| 242 | + $Pages = $Message['pages'] ?? []; |
| 243 | + if (!empty($Pages)) { |
| 244 | + $PageLines = []; |
| 245 | + foreach ($Pages as $Page) { |
| 246 | + $PageAction = $Page['action'] ?? 'updated'; |
| 247 | + $PageTitle = $Page['title'] ?? 'Unknown'; |
| 248 | + $PageUrl = $Page['html_url'] ?? ''; |
| 249 | + $Summary = !empty($Page['summary']) ? " — {$Page['summary']}" : ''; |
| 250 | + $PageLines[] = "• **{$PageAction}** [{$PageTitle}]({$PageUrl}){$Summary}"; |
| 251 | + } |
| 252 | + $PageCount = count($Pages); |
| 253 | + $ChatMsg = "📝 [{$User}](https://github.com/{$User}) updated {$PageCount} wiki " |
| 254 | + . ($PageCount === 1 ? "page" : "pages") |
| 255 | + . " on [{$RepositoryName}](https://github.com/{$RepositoryName}):\n" |
| 256 | + . implode("\n", $PageLines); |
| 257 | + } else { |
| 258 | + $ChatMsg = "📝 [{$User}](https://github.com/{$User}) updated the wiki " |
| 259 | + . "on [{$RepositoryName}](https://github.com/{$RepositoryName})."; |
| 260 | + } |
163 | 261 | $Msg['text'] = $ChatMsg; |
164 | 262 | SendToChat('notifications', $Msg, $useRC, $useTeams); |
165 | 263 | break; |
|
0 commit comments