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 {