Skip to content

TRT-2799: syncPRStatus: Fix SHA mismatch bug (MergeCommitSHA vs Head.SHA)#3821

Open
openshift-trt-agent[bot] wants to merge 1 commit into
openshift:mainfrom
openshift-trt:trt-2799
Open

TRT-2799: syncPRStatus: Fix SHA mismatch bug (MergeCommitSHA vs Head.SHA)#3821
openshift-trt-agent[bot] wants to merge 1 commit into
openshift:mainfrom
openshift-trt:trt-2799

Conversation

@openshift-trt-agent

Copy link
Copy Markdown

Summary

Fixes the SHA mismatch bug in syncPRStatus (TRT-2799).

Since January 2023 (commit d4932de0b), syncPRStatus compared MergeCommitSHA (the merge commit GitHub creates when merging a PR) against prow_pull_requests.SHA (the PR head commit from prow job specs). These are fundamentally different commits and almost never match, so merged_at was never set via this code path. This left 82% of prow_pull_requests rows with merged_at IS NULL.

Changes

  • pkg/dataloader/prowloader/github/github.go: Added MergedPR type and ListRecentlyMergedPRs method that returns recently merged PRs with Head.SHA (the correct PR head commit SHA) instead of MergeCommitSHA. Uses the same lazy closedCache population as the existing IsPrRecentlyMerged.

  • pkg/dataloader/prowloader/prow.go: Rewrote syncPRStatus from a per-PR loop with per-row DB saves to a batch pipeline:

    1. Query distinct (org, repo) from prow_pull_requests WHERE merged_at IS NULL
    2. For each repo, call ListRecentlyMergedPRs to get merged PRs with Head.SHA
    3. COPY all merged PR data to a temp table via CopyToTempTable
    4. Bulk UPDATE prow_pull_requests SET merged_at where sha matches
    5. Bulk DELETE FROM pull_request_comments for merged PRs (risk analysis cleanup)
  • pkg/dataloader/prowloader/github/github_test.go: Added TestClient_ListRecentlyMergedPRs verifying that the method returns Head.SHA (not MergeCommitSHA), filters out unmerged and headless PRs, and uses the cache on subsequent calls.

Test plan

  • go vet ./pkg/dataloader/prowloader/... passes
  • go test ./pkg/... passes (all Go unit tests)
  • TestClient_ListRecentlyMergedPRs verifies Head.SHA is returned, not MergeCommitSHA
  • golangci-lint reports 0 issues
  • gofmt -w applied to all changed files

Generated with Claude Code

syncPRStatus compared MergeCommitSHA (the merge commit GitHub creates)
against prow_pull_requests.SHA (the PR head commit from prow job specs).
These are different commits so the comparison never matched, leaving
merged_at NULL on 82% of rows.

Replace the per-PR loop with a batch pipeline that uses Head.SHA from
the GitHub PR objects (matching the original correct GetPRSHAMerged
behavior). The new implementation queries distinct repos, fetches
recently merged PRs via ListRecentlyMergedPRs, then uses CopyToTempTable
for a bulk UPDATE and bulk DELETE instead of per-row DB round-trips.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 24, 2026
@openshift-ci openshift-ci Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Jul 24, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 24, 2026

Copy link
Copy Markdown

@openshift-trt-agent[bot]: This pull request references TRT-2799 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

Fixes the SHA mismatch bug in syncPRStatus (TRT-2799).

Since January 2023 (commit d4932de0b), syncPRStatus compared MergeCommitSHA (the merge commit GitHub creates when merging a PR) against prow_pull_requests.SHA (the PR head commit from prow job specs). These are fundamentally different commits and almost never match, so merged_at was never set via this code path. This left 82% of prow_pull_requests rows with merged_at IS NULL.

Changes

  • pkg/dataloader/prowloader/github/github.go: Added MergedPR type and ListRecentlyMergedPRs method that returns recently merged PRs with Head.SHA (the correct PR head commit SHA) instead of MergeCommitSHA. Uses the same lazy closedCache population as the existing IsPrRecentlyMerged.

  • pkg/dataloader/prowloader/prow.go: Rewrote syncPRStatus from a per-PR loop with per-row DB saves to a batch pipeline:

  1. Query distinct (org, repo) from prow_pull_requests WHERE merged_at IS NULL
  2. For each repo, call ListRecentlyMergedPRs to get merged PRs with Head.SHA
  3. COPY all merged PR data to a temp table via CopyToTempTable
  4. Bulk UPDATE prow_pull_requests SET merged_at where sha matches
  5. Bulk DELETE FROM pull_request_comments for merged PRs (risk analysis cleanup)
  • pkg/dataloader/prowloader/github/github_test.go: Added TestClient_ListRecentlyMergedPRs verifying that the method returns Head.SHA (not MergeCommitSHA), filters out unmerged and headless PRs, and uses the cache on subsequent calls.

Test plan

  • go vet ./pkg/dataloader/prowloader/... passes
  • go test ./pkg/... passes (all Go unit tests)
  • TestClient_ListRecentlyMergedPRs verifies Head.SHA is returned, not MergeCommitSHA
  • golangci-lint reports 0 issues
  • gofmt -w applied to all changed files

Generated with Claude Code

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from deads2k and dgoodwin July 24, 2026 12:49
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: openshift-trt-agent[bot]
Once this PR has been reviewed and has the lgtm label, please assign deepsm007 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 24, 2026
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Hi @openshift-trt-agent[bot]. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant