8000
Skip to content
8000

fix: correctly list pull request branch candidates - #3711

Open
Navaneeth92 wants to merge 1 commit into
harness:mainfrom
Navaneeth92:fix/pr-banner-default-branch
Open

fix: correctly list pull request branch candidates#3711
Navaneeth92 wants to merge 1 commit into
harness:mainfrom
Navaneeth92:fix/pr-banner-default-branch

Conversation

@Navaneeth92
Copy link
Copy Markdown

Summary

This PR fixes the PR banner candidate selection logic so that:

  • Newly created branches correctly appear as PR candidates before any pull request is created.
  • Branches with an open pull request are excluded.
  • Branches whose latest commit has already been used to create a pull request are excluded.
  • The default branch no longer depends on a corresponding row in the branches table.

Problem

The existing implementation fetched the default branch metadata from the branches table before querying PR banner candidates.

For newly created repositories, the default branch may already exist in Git while its metadata has not yet been persisted in the branches table. In that situation, the endpoint:

GET /api/v1/repos/{repo}/+/pullreq/candidates

returned 404 (Not Found), preventing the UI from displaying the "Compare & Pull Request" banner.

Additionally, the previous SQL query relied on joins involving branch_last_created_pullreq_id, which could lead to incorrect banner behaviour in certain scenarios.


Root Cause

Candidate lookup depended on:

  • Looking up the default branch SHA from the database.
  • Joining against the latest recorded pull request.

If the default branch record was missing, candidate lookup failed entirely.

The join-based query also made it difficult to reliably distinguish between:

  • branches with an open PR,
  • branches whose current commit already has a PR, and
  • branches that genuinely require a new PR.

Solution

This PR simplifies the candidate selection logic by:

  • Passing the default branch name instead of its SHA.
  • Excluding the default branch directly in the SQL query.
  • Replacing the previous join with a NOT EXISTS query that filters branches where:
    • an open pull request already exists, or
    • a pull request has already been created for the current branch SHA.

This removes the dependency on the default branch metadata while preserving the intended banner behaviour.


Testing

Verified manually using a fresh database.

Scenarios Tested

  • ✅ New repository
  • ✅ First feature branch immediately displays the PR banner
  • ✅ Creating a pull request removes the banner
  • ✅ Merging or closing the pull request keeps the banner hidden for the same commit
  • ✅ Pushing new commits to the branch shows the banner again
  • ✅ Multiple repositories
  • ✅ Regression test for the original false-banner issue (banner no longer persists after PR creation)

Notes

This change is intentionally scoped to the backend candidate selection logic and does not introduce any UI changes.

@CLAassistant
CLAassistant commented Aug 2, 2026
Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Navaneeth Ananthakrishnan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Navaneeth92
Navaneeth92 force-pushed the fix/pr-banner-default-branch branch from a912732 to 592ea12 Compare August 2, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0