/
processor_factory.go
57 lines (49 loc) · 1.15 KB
/
processor_factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"net/url"
changelog "github.com/rivy-go/git-changelog/internal/changelog"
)
// ProcessorFactory ...
type ProcessorFactory struct {
hostRegistry map[string]string
}
// NewProcessorFactory ...
func NewProcessorFactory() *ProcessorFactory {
return &ProcessorFactory{
hostRegistry: map[string]string{
"github": "github.com",
"gitlab": "gitlab.com",
"bitbucket": "bitbucket.org",
},
}
}
// Create ...
func (factory *ProcessorFactory) Create(config *Config) (changelog.Processor, error) {
obj, err := url.Parse(config.Info.RepositoryURL)
if err != nil {
return nil, err
}
host := obj.Host
if config.Style != "" {
if styleHost, ok := factory.hostRegistry[config.Style]; ok {
host = styleHost
}
}
switch host {
case "github.com":
return &changelog.GitHubProcessor{
Host: fmt.Sprintf("%s://%s", obj.Scheme, obj.Host),
}, nil
case "gitlab.com":
return &changelog.GitLabProcessor{
Host: fmt.Sprintf("%s://%s", obj.Scheme, obj.Host),
}, nil
case "bitbucket.org":
return &changelog.BitbucketProcessor{
Host: fmt.Sprintf("%s://%s", obj.Scheme, obj.Host),
}, nil
default:
return nil, nil
}
}