mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 02:24:25 -05:00
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user