diff --git a/pkg/commands/github.go b/pkg/commands/github.go index 3dce49f7f..823624cf5 100644 --- a/pkg/commands/github.go +++ b/pkg/commands/github.go @@ -2,7 +2,6 @@ package commands import ( "encoding/json" - "strings" "github.com/jesseduffield/lazygit/pkg/commands/models" ) @@ -47,13 +46,12 @@ func (c *GitCommand) GenerateGithubPullRequestMap(prs []*models.GithubPullReques continue } - remoteAndName := strings.SplitN(branch.UpstreamName, "/", 2) - owner, foundRemoteOwner := remotesToOwnersMap[remoteAndName[0]] - if len(remoteAndName) != 2 || !foundRemoteOwner { + owner, foundRemoteOwner := remotesToOwnersMap[branch.RemoteName()] + if branch.BranchName() == "" || !foundRemoteOwner { continue } - pr, hasPr := prWithStringKey[owner+":"+remoteAndName[1]] + pr, hasPr := prWithStringKey[owner+":"+branch.BranchName()] if !hasPr { continue } diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go index 3b8268bff..df7e54903 100644 --- a/pkg/commands/models/branch.go +++ b/pkg/commands/models/branch.go @@ -1,5 +1,7 @@ package models +import "strings" + // Branch : A git branch // duplicating this for now type Branch struct { @@ -47,3 +49,15 @@ func (b *Branch) HasCommitsToPull() bool { func (b *Branch) IsRealBranch() bool { return b.Pushables != "" && b.Pullables != "" } +func (b *Branch) RemoteName() string { + return strings.SplitN(b.UpstreamName, "/", 2)[0] +} + +func (b *Branch) BranchName() string { + remoteAndBranch := strings.SplitN(b.UpstreamName, "/", 2) + if len(remoteAndBranch) != 2 { + return "" + } + + return strings.SplitN(b.UpstreamName, "/", 2)[1] +}