Normalize repository owner casing to fix GitHub PR integration (#5495)

### PR Description

Close #5494 

Normalizes the repository owner to lowercase during the PR mapping.
This ensures that PR icons and integration features work correctly even
when the local git remote URL casing differs from the official
repository casing on GitHub.
This commit is contained in:
Stefan Haller 2026-04-10 18:49:37 +02:00 committed by GitHub
commit 38dd035e28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 3 deletions

View file

@ -283,7 +283,7 @@ func GenerateGithubPullRequestMap(
prByKey := map[prKey]models.GithubPullRequest{}
for _, pr := range prs {
key := prKey{owner: pr.UserName(), branchName: pr.BranchName()}
key := prKey{owner: strings.ToLower(pr.UserName()), branchName: pr.BranchName()}
// PRs are returned newest-first from the API, so the first one we
// see for each key is the most recent and therefore the most relevant.
if _, exists := prByKey[key]; !exists {
@ -307,7 +307,7 @@ func GenerateGithubPullRequestMap(
owner = repoInfo.Owner
}
pr, hasPr := prByKey[prKey{owner: owner, branchName: branch.UpstreamBranch}]
pr, hasPr := prByKey[prKey{owner: strings.ToLower(owner), branchName: branch.UpstreamBranch}]
if !hasPr {
continue
@ -348,7 +348,7 @@ func (self *GitHubCommands) InGithubRepo(remotes []*models.Remote) bool {
}
url := remote.Urls[0]
return strings.Contains(url, "github.com")
return strings.Contains(strings.ToLower(url), "github.com")
}
func getMainRemote(remotes []*models.Remote) *models.Remote {

View file

@ -318,6 +318,40 @@ func TestGenerateGithubPullRequestMap(t *testing.T) {
},
},
},
{
name: "matches when owner casing differs",
prs: []*models.GithubPullRequest{
{
HeadRefName: "fix-case-insensitive",
Number: 42,
Title: "Fix case insensitive",
State: "OPEN",
HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "Jesseduffield"}, // Uppercase J
},
},
branches: []*models.Branch{
{
Name: "fix-case-insensitive",
UpstreamRemote: "origin",
UpstreamBranch: "fix-case-insensitive",
},
},
remotes: []*models.Remote{
{
Name: "origin",
Urls: []string{"git@github.com:jesseduffield/lazygit.git"}, // Lowercase j
},
},
expected: map[string]*models.GithubPullRequest{
"fix-case-insensitive": {
HeadRefName: "fix-case-insensitive",
Number: 42,
Title: "Fix case insensitive",
State: "OPEN",
HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "Jesseduffield"},
},
},
},
}
for _, c := range cases {