Skip to content

Commit c9e6dc0

Browse files
fix: fallback to create when GitHub check run update returns 404 (#710)
* Initial plan * Initial exploration: Understand the issue with GitHub Checks API 404 handling Co-authored-by: crenshaw-dev <[email protected]> * feat: add 404 fallback for GitHub Checks API update operations When a CommitStatus was created using the legacy Commit Status API instead of the Checks API, it may have an invalid check run ID. When attempting to update such a check run, GitHub returns a 404 error. This change detects 404 errors and falls back to creating a new check run instead, allowing the transition from Commit Status API to Checks API to work seamlessly. Co-authored-by: crenshaw-dev <[email protected]> * chore: revert unrelated package-lock.json changes Restored package-lock.json files to their original state before the PR. These changes were not related to the GitHub Checks API fix. Co-authored-by: crenshaw-dev <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: crenshaw-dev <[email protected]>
1 parent 82fa8f5 commit c9e6dc0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/scms/github/commit_status.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package github
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"net/http"
68
"strconv"
79
"time"
810

@@ -158,6 +160,16 @@ func (cs *CommitStatus) updateCheckRun(ctx context.Context, commitStatus *promot
158160
start := time.Now()
159161
checkRun, response, err := cs.client.Checks.UpdateCheckRun(ctx, gitRepo.Spec.GitHub.Owner, gitRepo.Spec.GitHub.Name, checkRunID, updateOpts)
160162
if err != nil {
163+
// Check if the error is a 404 (check run not found)
164+
// This can happen when a CommitStatus was created using the legacy Commit Status API
165+
// instead of the Checks API, resulting in an invalid check run ID
166+
var ghErr *github.ErrorResponse
167+
if errors.As(err, &ghErr) && ghErr.Response != nil && ghErr.Response.StatusCode == http.StatusNotFound {
168+
logger := log.FromContext(ctx)
169+
logger.Info("Check run not found (404), falling back to create operation", "checkRunId", commitStatus.Status.Id)
170+
// Fall back to creating a new check run
171+
return cs.createCheckRun(ctx, commitStatus)
172+
}
161173
return nil, fmt.Errorf("failed to update check run: %w", err)
162174
}
163175
return cs.handleCheckRunResponse(ctx, metrics.SCMOperationUpdate, start, commitStatus, gitRepo, checkRun, response)

0 commit comments

Comments
 (0)