-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathhost_helper.go
56 lines (48 loc) · 1.39 KB
/
host_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package helpers
import (
"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
)
// this helper just wraps our hosting_service package
type IHostHelper interface {
GetPullRequestURL(from string, to string) (string, error)
GetCommitURL(commitHash string) (string, error)
}
type HostHelper struct {
c *HelperCommon
}
func NewHostHelper(
c *HelperCommon,
) *HostHelper {
return &HostHelper{
c: c,
}
}
func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error) {
mgr, err := self.getHostingServiceMgr()
if err != nil {
return "", err
}
return mgr.GetPullRequestURL(from, to)
}
func (self *HostHelper) GetCommitURL(commitHash string) (string, error) {
mgr, err := self.getHostingServiceMgr()
if err != nil {
return "", err
}
return mgr.GetCommitURL(commitHash)
}
// getting this on every request rather than storing it in state in case our remoteURL changes
// from one invocation to the next.
func (self *HostHelper) getHostingServiceMgr() (*hosting_service.HostingServiceMgr, error) {
remotes := self.c.UserConfig().Git.PreferRemotes
var err error
var remoteUrl string
for _, remote := range remotes {
remoteUrl, err = self.c.Git().Remote.GetRemoteURL(remote)
if err == nil {
configServices := self.c.UserConfig().Services
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
}
}
return nil, err
}