slub icon indicating copy to clipboard operation
slub copied to clipboard

Fix: Prevent duplicate CI failure notifications on branch updates

Open souhailmerroun opened this issue 2 months ago • 0 comments

Problem

When pushing new commits or updating a branch, users receive duplicate "CI Failed" notifications in Slack for the old failure, not the new commit.

Root Cause: When a PR transitions to PENDING (new commit pushed), the previous build link was cleared. GitHub then sends a webhook with the old failure status, and the bot treats it as a new failure.

Solution

1. Preserve build link when going PENDING (PR.php:272-276)

$previousBuildLink = $this->CIStatus->buildLink();
$this->CIStatus = CIStatus::endedWith(BuildResult::pending(), $previousBuildLink);

2. Detect and ignore stale webhooks (PR.php:254-255)

if ($this->CIStatus->isPendingWithLink($buildLink)) {
    return; // Stale webhook from old CI run - ignore it
}

3. Added helper methods (CIStatus.php)

  • isPendingWithLink() – Check if PENDING with specific build link
  • buildLink() – Getter for build link
  • Fixed isRedWithLink() – Now checks both status and link

🧪 Test Coverage

Added 3 tests in PRTest.php:

  1. Duplicate RED with same link (line 363–377)
  2. Different build links create new events (line 382–399)
  3. Stale webhook scenario – the bug fix (line 404–421)

souhailmerroun avatar Nov 12 '25 16:11 souhailmerroun