mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Adds a keybinding (default: 'y') in the branches panel to copy the branch's URL on the hosting service to the clipboard. Each supported hosting service has a dedicated URL template: - GitHub: /tree/<branch> - GitLab: /-/tree/<branch> - Bitbucket: /branch/<branch> - Azure DevOps: ?version=GB<branch> - Bitbucket Server: /browse?at=<branch> - Gitea/Codeberg: /src/branch/<branch> Closes #1959
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
|
|
)
|
|
|
|
// this helper just wraps our hosting_service package
|
|
|
|
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)
|
|
}
|
|
|
|
func (self *HostHelper) GetBranchURL(branchName string) (string, error) {
|
|
mgr, err := self.getHostingServiceMgr()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return mgr.GetBranchURL(branchName)
|
|
}
|
|
|
|
// 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) {
|
|
remoteUrl, err := self.c.Git().Remote.GetRemoteURL("origin")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
configServices := self.c.UserConfig().Services
|
|
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
|
|
}
|