Skip to content

Commit 1d5e61b

Browse files
committed
updated the notification queue dedup key loigic
Push event (sha=abc1234) → dedup_key = github:commit:owner/repo:abc1234 → message saved to Redis
1 parent d1c33f1 commit 1d5e61b

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

web/github.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,35 +177,46 @@ function pickRoom(string $repo): string
177177

178178
function buildDedupKey(string $eventType, string $repo, array $payload): string
179179
{
180+
// Helper to extract short SHA from payload
181+
$getSha = function(array $payload, string $shaKey): string {
182+
$sha = (string)($payload[$shaKey] ?? '');
183+
return $sha !== '' ? substr($sha, 0, 7) : '';
184+
};
185+
180186
switch ($eventType) {
187+
// All events that carry a commit SHA now use github:commit:{repo}:{sha7}
188+
// This allows the consumer to group push + check_run + workflow_job for the same commit.
181189
case 'check_run':
182-
$sha = (string)($payload['check_run']['head_sha'] ?? '');
183-
return "github:checkrun:{$repo}:" . substr($sha, 0, 7);
190+
$sha = $getSha($payload['check_run'] ?? [], 'head_sha');
191+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:checkrun:{$repo}";
184192
case 'check_suite':
185-
$sha = (string)($payload['check_suite']['head_sha'] ?? '');
186-
return "github:check:{$repo}:" . substr($sha, 0, 7);
193+
$sha = $getSha($payload['check_suite'] ?? [], 'head_sha');
194+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:check:{$repo}";
187195
case 'workflow_run':
188-
$branch = (string)($payload['workflow_run']['head_branch'] ?? '');
189-
$name = (string)($payload['workflow_run']['name'] ?? 'workflow');
190-
return "github:wf:{$repo}:{$branch}:{$name}";
196+
$sha = $getSha($payload['workflow_run'] ?? [], 'head_sha');
197+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:wf:{$repo}";
191198
case 'workflow_job':
192-
$branch = (string)($payload['workflow_job']['head_branch'] ?? '');
193-
$jobName = (string)($payload['workflow_job']['name'] ?? 'job');
194-
return "github:wfjob:{$repo}:{$branch}:{$jobName}";
199+
$sha = $getSha($payload['workflow_job'] ?? [], 'head_sha');
200+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:wfjob:{$repo}";
201+
case 'push':
202+
// Use 'after' SHA (the commit that was pushed), not the branch
203+
$sha = $getSha($payload, 'after');
204+
if ($sha === '' && !empty($payload['commits'])) {
205+
$lastCommit = end($payload['commits']);
206+
$sha = substr((string)($lastCommit['id'] ?? ''), 0, 7);
207+
}
208+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:push:{$repo}";
195209
case 'issues':
196210
$num = (int)($payload['issue']['number'] ?? 0);
197211
return "github:issue:{$repo}:{$num}";
198212
case 'pull_request':
199213
$num = (int)($payload['pull_request']['number'] ?? 0);
200214
return "github:pr:{$repo}:{$num}";
201-
case 'push':
202-
$branch = isset($payload['ref']) ? str_replace('refs/heads/', '', (string)$payload['ref']) : 'unknown';
203-
return "github:push:{$repo}:{$branch}";
204215
case 'gollum':
205216
return "github:wiki:{$repo}";
206217
case 'status':
207-
$sha = (string)($payload['sha'] ?? '');
208-
return "github:status:{$repo}:" . substr($sha, 0, 7);
218+
$sha = $getSha($payload, 'sha');
219+
return $sha !== '' ? "github:commit:{$repo}:{$sha}" : "github:status:{$repo}";
209220
case 'star':
210221
case 'watch':
211222
case 'fork':

0 commit comments

Comments
 (0)