split logic into functions

This commit is contained in:
Yuki Osaki 2021-10-31 22:55:11 +09:00
parent aed7c29509
commit 153970fb08
2 changed files with 17 additions and 5 deletions

View file

@ -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
}

View file

@ -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]
}