Skip to content

Fix new PR title to match github.com when branch has multiple commits#8773

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/add-dvt-setup
Open

Fix new PR title to match github.com when branch has multiple commits#8773
Copilot wants to merge 3 commits into
mainfrom
copilot/add-dvt-setup

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Creating a new PR via the extension always used the last commit's title, even when the branch had multiple commits — github.com uses the branch name in that case.

CreatePullRequestViewProvider.getTitleAndDescription already intended to mirror github.com (branch name for >1 commits, commit title for 1), but its commit count came solely from the GitHub compareCommits API via getTotalGitHubCommits. That call returns undefined when the compare branch has no upstream, the head GitHub repo can't be resolved by remote name, or the API otherwise fails, at which point the code set useBranchName = false unconditionally and fell back to the tip commit's title.

Changes

  • src/github/createPRViewProvider.ts: when the GitHub commit count is unavailable, fall back to a local git log via this.model.gitCommits() (already runs git log <baseRemote>/<base>..<compare>), filter out merge commits, and feed that count into the existing branch-name-vs-commit-title decision. If both sources fail, behavior is unchanged (uses tip commit). Description logic keyed off !useBranchName benefits automatically.
let totalNonMergeCommitsCount: number | undefined =
    totalCommits?.filter(c => c.parents.length < 2).length;

if (totalNonMergeCommitsCount === undefined) {
    try {
        const localCommits = await this.model.gitCommits();
        totalNonMergeCommitsCount = localCommits.filter(c => c.parents.length < 2).length;
    } catch (e) {
        Logger.debug(`Failed to retrieve local git commits as fallback for PR title for branch ${name}: ${e}`, CreatePullRequestViewProvider.ID);
    }
}

Copilot AI linked an issue Jun 8, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits June 8, 2026 10:44
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PR title mismatch between extension and GitHub Fix new PR title to match github.com when branch has multiple commits Jun 8, 2026
Copilot AI requested a review from alexr00 June 8, 2026 10:46
@alexr00 alexr00 marked this pull request as ready for review June 9, 2026 10:49
Copilot AI review requested due to automatic review settings June 9, 2026 10:49
@alexr00 alexr00 enabled auto-merge (squash) June 9, 2026 10:49
@alexr00 alexr00 disabled auto-merge June 9, 2026 10:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes default pull request title selection when creating a PR from a branch with multiple commits, ensuring the extension matches github.com behavior even when the GitHub compare API can’t provide a commit count (e.g., no upstream).

Changes:

  • Switch from tracking a non-merge commit array to a non-merge commit count for determining whether to use branch name vs. commit title.
  • When the GitHub commit list is unavailable, fall back to a local git log via this.model.gitCommits(), filtering out merge commits, to decide whether there is more than one commit.
Show a summary per file
File Description
src/github/createPRViewProvider.ts Adds local git log fallback logic to determine non-merge commit count for PR title/description defaults when GitHub commit count is unavailable.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/github/createPRViewProvider.ts
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.

New PR title doesn't match behavior on github.com

4 participants