diff options
author | William Wagner Moraes Artero <williamwmoraes@gmail.com> | 2019-12-06 15:39:24 +0100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-01 10:57:12 +1100 |
commit | 6ea25bd259f1252dce2011cc93501e75b9398cb6 (patch) | |
tree | 34fa1fd9142576f06c87610adf3f0d6deade00c8 /pkg/commands | |
parent | fe5f087f9c29fd6e11429ac5f412a8107ffb902d (diff) |
feat: flexible service configuration
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/pull_request.go | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/pkg/commands/pull_request.go b/pkg/commands/pull_request.go index a6b6bc8f7..d4eb36c08 100644 --- a/pkg/commands/pull_request.go +++ b/pkg/commands/pull_request.go @@ -27,29 +27,43 @@ type RepoInformation struct { 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 { services := []*Service{ - { - Name: "github.com", - PullRequestURL: "https://github.com/%s/%s/compare/%s?expand=1", - }, - { - 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", - }, + NewService("github", "github.com", "github.com"), + NewService("bitbucket", "bitbucket.org", "bitbucket.org"), + NewService("gitlab", "gitlab.com", "gitlab.com"), } configServices := config.GetUserConfig().GetStringMapString("services") - for name, prURL := range configServices { - services = append(services, &Service{ - Name: name, - PullRequestURL: prURL, - }) + for repoDomain, typeAndDomain := range configServices { + splitData := strings.Split(typeAndDomain, ":") + if len(splitData) == 2 { + services = append(services, NewService(splitData[0], repoDomain, splitData[1])) + } } return services |