1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00

feat: flexible service configuration

This commit is contained in:
William Wagner Moraes Artero 2019-12-06 15:39:24 +01:00 committed by Jesse Duffield
parent fe5f087f9c
commit 6ea25bd259

@ -27,29 +27,43 @@ type RepoInformation struct {
Repository string Repository string
} }
// NewService builds a Service based on the host type
func NewService(typeName string, repositoryDomain string, siteDomain string) *Service {
switch typeName {
case "github":
return &Service{
Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%%s?expand=1"),
}
case "bitbucket":
return &Service{
Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1"),
}
case "gitlab":
return &Service{
Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s"),
}
}
return nil
}
func getServices(config config.AppConfigurer) []*Service { func getServices(config config.AppConfigurer) []*Service {
services := []*Service{ services := []*Service{
{ NewService("github", "github.com", "github.com"),
Name: "github.com", NewService("bitbucket", "bitbucket.org", "bitbucket.org"),
PullRequestURL: "https://github.com/%s/%s/compare/%s?expand=1", NewService("gitlab", "gitlab.com", "gitlab.com"),
},
{
Name: "bitbucket.org",
PullRequestURL: "https://bitbucket.org/%s/%s/pull-requests/new?source=%s&t=1",
},
{
Name: "gitlab.com",
PullRequestURL: "https://gitlab.com/%s/%s/merge_requests/new?merge_request[source_branch]=%s",
},
} }
configServices := config.GetUserConfig().GetStringMapString("services") configServices := config.GetUserConfig().GetStringMapString("services")
for name, prURL := range configServices { for repoDomain, typeAndDomain := range configServices {
services = append(services, &Service{ splitData := strings.Split(typeAndDomain, ":")
Name: name, if len(splitData) == 2 {
PullRequestURL: prURL, services = append(services, NewService(splitData[0], repoDomain, splitData[1]))
}) }
} }
return services return services