1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

chore: keeping coverage up :D

This commit is contained in:
William Wagner Moraes Artero
2020-02-25 20:18:22 +01:00
committed by Jesse Duffield
parent a79182e50d
commit 3ce2b9b79a
2 changed files with 24 additions and 6 deletions

View File

@ -29,25 +29,27 @@ type RepoInformation struct {
// NewService builds a Service based on the host type // NewService builds a Service based on the host type
func NewService(typeName string, repositoryDomain string, siteDomain string) *Service { func NewService(typeName string, repositoryDomain string, siteDomain string) *Service {
var service *Service
switch typeName { switch typeName {
case "github": case "github":
return &Service{ service = &Service{
Name: repositoryDomain, Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1"), PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/compare/%s?expand=1"),
} }
case "bitbucket": case "bitbucket":
return &Service{ service = &Service{
Name: repositoryDomain, Name: repositoryDomain,
PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1"), PullRequestURL: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/pull-requests/new?source=%s&t=1"),
} }
case "gitlab": case "gitlab":
return &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: fmt.Sprintf("https://%s%s", siteDomain, "/%s/%s/merge_requests/new?merge_request[source_branch]=%s"),
} }
} }
return nil return service
} }
func getServices(config config.AppConfigurer) []*Service { func getServices(config config.AppConfigurer) []*Service {
@ -61,9 +63,18 @@ func getServices(config config.AppConfigurer) []*Service {
for repoDomain, typeAndDomain := range configServices { for repoDomain, typeAndDomain := range configServices {
splitData := strings.Split(typeAndDomain, ":") splitData := strings.Split(typeAndDomain, ":")
if len(splitData) == 2 { if len(splitData) != 2 {
services = append(services, NewService(splitData[0], repoDomain, splitData[1])) // TODO log this misconfiguration
continue
} }
service := NewService(splitData[0], repoDomain, splitData[1])
if service == nil {
// TODO log this unsupported service
continue
}
services = append(services, service)
} }
return services return services

View File

@ -147,6 +147,13 @@ func TestCreatePullRequest(t *testing.T) {
gitCommand := NewDummyGitCommand() gitCommand := NewDummyGitCommand()
gitCommand.OSCommand.command = s.command gitCommand.OSCommand.command = s.command
gitCommand.OSCommand.Config.GetUserConfig().Set("os.openLinkCommand", "open {{link}}") gitCommand.OSCommand.Config.GetUserConfig().Set("os.openLinkCommand", "open {{link}}")
gitCommand.Config.GetUserConfig().Set("services", map[string]string{
// valid configuration for a custom service URL
"git.work.com": "gitlab:code.work.com",
// invalid configurations for a custom service URL
"invalid.work.com": "noservice:invalid.work.com",
"noservice.work.com": "noservice.work.com",
})
dummyPullRequest := NewPullRequest(gitCommand) dummyPullRequest := NewPullRequest(gitCommand)
s.test(dummyPullRequest.Create(s.branch)) s.test(dummyPullRequest.Create(s.branch))
}) })