From 6eda4c0aabf12e7d4dbc66cde8cf0022708ab1f7 Mon Sep 17 00:00:00 2001 From: Bradly Chang Date: Fri, 10 Apr 2026 01:36:10 +0800 Subject: [PATCH] Fix case-insensitive remote URL matching for GitHub PRs 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. --- pkg/commands/git_commands/github.go | 6 ++--- pkg/commands/git_commands/github_test.go | 34 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git_commands/github.go b/pkg/commands/git_commands/github.go index 23d95f924..85893615d 100644 --- a/pkg/commands/git_commands/github.go +++ b/pkg/commands/git_commands/github.go @@ -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 { diff --git a/pkg/commands/git_commands/github_test.go b/pkg/commands/git_commands/github_test.go index 48d736386..d9d55ffd1 100644 --- a/pkg/commands/git_commands/github_test.go +++ b/pkg/commands/git_commands/github_test.go @@ -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 {