1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00

Extract git service URL formatting to a separate method

This commit is contained in:
Denis Palashevskii 2021-04-21 13:56:14 +04:00 committed by Jesse Duffield
parent f8f596d097
commit f2645da16a

View File

@ -12,7 +12,7 @@ import (
// Service is a service that repository is on (Github, Bitbucket, ...) // Service is a service that repository is on (Github, Bitbucket, ...)
type Service struct { type Service struct {
Name string Name string
PullRequestURL string PullRequestURL func(owner string, repository string, from string, to string) string
} }
// PullRequest opens a link in browser to create new pull request // PullRequest opens a link in browser to create new pull request
@ -36,17 +36,26 @@ func NewService(typeName string, repositoryDomain string, siteDomain string) *Se
case "github": case "github":
service = &Service{ service = &Service{
Name: repositoryDomain, Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1"), PullRequestURL: func(owner string, repository string, from string, to string) string {
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1")
return fmt.Sprintf(urlFormat, owner, repository, from)
},
} }
case "bitbucket": case "bitbucket":
service = &Service{ service = &Service{
Name: repositoryDomain, Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1"), PullRequestURL: func(owner string, repository string, from string, to string) string {
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1")
return fmt.Sprintf(urlFormat, owner, repository, from)
},
} }
case "gitlab": case "gitlab":
service = &Service{ service = &Service{
Name: repositoryDomain, Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s"), PullRequestURL: func(owner string, repository string, from string, to string) string {
urlFormat := fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s")
return fmt.Sprintf(urlFormat, owner, repository, from)
},
} }
} }
@ -131,9 +140,7 @@ func (pr *PullRequest) getPullRequestURL(branch *models.Branch) (string, error)
} }
repoInfo := getRepoInfoFromURL(repoURL) repoInfo := getRepoInfoFromURL(repoURL)
pullRequestURL := fmt.Sprintf( pullRequestURL := gitService.PullRequestURL(repoInfo.Owner, repoInfo.Repository, branch.Name, "")
gitService.PullRequestURL, repoInfo.Owner, repoInfo.Repository, branch.Name,
)
return pullRequestURL, nil return pullRequestURL, nil
} }