Skip to content

Commit 38dd035

Browse files
authored
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.
2 parents 8f258a3 + 6eda4c0 commit 38dd035

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

pkg/commands/git_commands/github.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func GenerateGithubPullRequestMap(
283283
prByKey := map[prKey]models.GithubPullRequest{}
284284

285285
for _, pr := range prs {
286-
key := prKey{owner: pr.UserName(), branchName: pr.BranchName()}
286+
key := prKey{owner: strings.ToLower(pr.UserName()), branchName: pr.BranchName()}
287287
// PRs are returned newest-first from the API, so the first one we
288288
// see for each key is the most recent and therefore the most relevant.
289289
if _, exists := prByKey[key]; !exists {
@@ -307,7 +307,7 @@ func GenerateGithubPullRequestMap(
307307
owner = repoInfo.Owner
308308
}
309309

310-
pr, hasPr := prByKey[prKey{owner: owner, branchName: branch.UpstreamBranch}]
310+
pr, hasPr := prByKey[prKey{owner: strings.ToLower(owner), branchName: branch.UpstreamBranch}]
311311

312312
if !hasPr {
313313
continue
@@ -348,7 +348,7 @@ func (self *GitHubCommands) InGithubRepo(remotes []*models.Remote) bool {
348348
}
349349

350350
url := remote.Urls[0]
351-
return strings.Contains(url, "github.com")
351+
return strings.Contains(strings.ToLower(url), "github.com")
352352
}
353353

354354
func getMainRemote(remotes []*models.Remote) *models.Remote {

pkg/commands/git_commands/github_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,40 @@ func TestGenerateGithubPullRequestMap(t *testing.T) {
318318
},
319319
},
320320
},
321+
{
322+
name: "matches when owner casing differs",
323+
prs: []*models.GithubPullRequest{
324+
{
325+
HeadRefName: "fix-case-insensitive",
326+
Number: 42,
327+
Title: "Fix case insensitive",
328+
State: "OPEN",
329+
HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "Jesseduffield"}, // Uppercase J
330+
},
331+
},
332+
branches: []*models.Branch{
333+
{
334+
Name: "fix-case-insensitive",
335+
UpstreamRemote: "origin",
336+
UpstreamBranch: "fix-case-insensitive",
337+
},
338+
},
339+
remotes: []*models.Remote{
340+
{
341+
Name: "origin",
342+
Urls: []string{"git@github.com:jesseduffield/lazygit.git"}, // Lowercase j
343+
},
344+
},
345+
expected: map[string]*models.GithubPullRequest{
346+
"fix-case-insensitive": {
347+
HeadRefName: "fix-case-insensitive",
348+
Number: 42,
349+
Title: "Fix case insensitive",
350+
State: "OPEN",
351+
HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "Jesseduffield"},
352+
},
353+
},
354+
},
321355
}
322356

323357
for _, c := range cases {

0 commit comments

Comments
 (0)