Prioritize repo account for generating commit messages#21644
Prioritize repo account for generating commit messages#21644sergiou87 merged 2 commits intodevelopmentfrom
Conversation
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.
app/src/lib/stores/app-store.ts
Outdated
| 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) |
There was a problem hiding this comment.
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)There was a problem hiding this comment.
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).
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