Skip to content

Prioritize repo account for generating commit messages#21644

Merged
sergiou87 merged 2 commits intodevelopmentfrom
use-right-copilot-account
Feb 19, 2026
Merged

Prioritize repo account for generating commit messages#21644
sergiou87 merged 2 commits intodevelopmentfrom
use-right-copilot-account

Conversation

@sergiou87
Copy link
Member

Closes #21484

Description

Sort accounts to prefer the one associated with the current repository before selecting an account for commit message generation. Uses getAccountForRepository to identify the repository-specific account and moves it to the front of the list so enableCommitMessageGeneration will pick it when available, avoiding selection of an unrelated account.

Release notes

Notes: [Fixed] Choose the best account for the current repository to generate commit messages

Sort accounts to prefer the one associated with the current repository before selecting an account for commit message generation. Uses getAccountForRepository to identify the repository-specific account and moves it to the front of the list so enableCommitMessageGeneration will pick it when available, avoiding selection of an unrelated account.
tidy-dev
tidy-dev previously approved these changes Feb 18, 2026
Comment on lines +5607 to +5617
const repositoryAccount = getAccountForRepository(this.accounts, repository)
const accounts = Array.from(this.getState().accounts).sort((a, b) => {
if (a === repositoryAccount) {
return -1
} else if (b === repositoryAccount) {
return 1
} else {
return 0
}
})
const account = accounts.find(enableCommitMessageGeneration)
Copy link
Member

Choose a reason for hiding this comment

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

Let me preface this by saying that I'm happy with this change and you can absolutely go ahead an merge but curiosity got the best of me here. Do we really need to sort? Right now chances are low that there's more than one account and even with multiple enterprise accounts there'd be few. When we do support multiple accounts for real I imagine it'd still be super rare to have more than a couple of accounts. Feels like we could just check if the repo account works no?

// prefer the account that is associated to this repository.
const repositoryAccount = getAccountForRepository(this.accounts, repository)
    const account =
      repositoryAccount && enableCommitMessageGeneration(repositoryAccount)
        ? repositoryAccount
        : this.accounts.find(enableCommitMessageGeneration)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a great question! Since I was changing this code, I just wanted to make it as generic and future-proof as possible, but agree this might be too much 😂 I'm gonna go ahead with your suggestion instead!

Remove unnecessary sorting of accounts and simplify selection logic: check the repository-associated account first and use it if it supports commit message generation; otherwise fall back to finding any account that does. This reduces allocation and improves readability while preserving behavior (returns false if no account enables generation).
@sergiou87 sergiou87 merged commit a84a3f9 into development Feb 19, 2026
7 checks passed
@sergiou87 sergiou87 deleted the use-right-copilot-account branch February 19, 2026 10:28
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.

Using personal account for Copilot when I selected enterprise account for a repo

3 participants