summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers/helpers/host_helper.go
blob: edc0bc7ba7ddb6b8c6068069520a63d4d6cb5812 (plain)
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
package helpers

import (
	"github.com/jesseduffield/lazygit/pkg/commands"
	"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

// this helper just wraps our hosting_service package

type IHostHelper interface {
	GetPullRequestURL(from string, to string) (string, error)
	GetCommitURL(commitSha string) (string, error)
}

type HostHelper struct {
	c   *types.HelperCommon
	git *commands.GitCommand
}

func NewHostHelper(
	c *types.HelperCommon,
	git *commands.GitCommand,
) *HostHelper {
	return &HostHelper{
		c:   c,
		git: git,
	}
}

func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error) {
	return self.getHostingServiceMgr().GetPullRequestURL(from, to)
}

func (self *HostHelper) GetCommitURL(commitSha string) (string, error) {
	return self.getHostingServiceMgr().GetCommitURL(commitSha)
}

// getting this on every request rather than storing it in state in case our remoteURL changes
// from one invocation to the next. Note however that we're currently caching config
// results so we might want to invalidate the cache here if it becomes a problem.
func (self *HostHelper) getHostingServiceMgr() *hosting_service.HostingServiceMgr {
	remoteUrl := self.git.Config.GetRemoteURL()
	configServices := self.c.UserConfig.Services
	return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices)
}