Skip to content

Commit b2ec6fb

Browse files
refactor: cleanup start plugin methods
1 parent 03a7023 commit b2ec6fb

File tree

2 files changed

+13
-67
lines changed

2 files changed

+13
-67
lines changed

pkg/plugin/client.go

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import (
1010
"strings"
1111
"sync"
1212

13-
"github.com/go-semantic-release/semantic-release/v2/pkg/analyzer"
14-
"github.com/go-semantic-release/semantic-release/v2/pkg/condition"
15-
"github.com/go-semantic-release/semantic-release/v2/pkg/generator"
16-
"github.com/go-semantic-release/semantic-release/v2/pkg/hooks"
17-
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
18-
"github.com/go-semantic-release/semantic-release/v2/pkg/updater"
1913
"github.com/hashicorp/go-hclog"
2014
"github.com/hashicorp/go-plugin"
2115
)
@@ -37,7 +31,7 @@ func KillAllPlugins() {
3731
}
3832
}
3933

40-
func startPlugin(opts *PluginOpts) (interface{}, error) {
34+
func StartPlugin(opts *PluginOpts) (interface{}, error) {
4135
runningClientsMx.Lock()
4236
defer runningClientsMx.Unlock()
4337
logR, logW := io.Pipe()
@@ -81,51 +75,3 @@ func startPlugin(opts *PluginOpts) (interface{}, error) {
8175
runningClients = append(runningClients, client)
8276
return raw, nil
8377
}
84-
85-
func StartCommitAnalyzerPlugin(opts *PluginOpts) (analyzer.CommitAnalyzer, error) {
86-
raw, err := startPlugin(opts)
87-
if err != nil {
88-
return nil, err
89-
}
90-
return raw.(analyzer.CommitAnalyzer), nil
91-
}
92-
93-
func StartCIConditionPlugin(opts *PluginOpts) (condition.CICondition, error) {
94-
raw, err := startPlugin(opts)
95-
if err != nil {
96-
return nil, err
97-
}
98-
return raw.(condition.CICondition), nil
99-
}
100-
101-
func StartChangelogGeneratorPlugin(opts *PluginOpts) (generator.ChangelogGenerator, error) {
102-
raw, err := startPlugin(opts)
103-
if err != nil {
104-
return nil, err
105-
}
106-
return raw.(generator.ChangelogGenerator), nil
107-
}
108-
109-
func StartProviderPlugin(opts *PluginOpts) (provider.Provider, error) {
110-
raw, err := startPlugin(opts)
111-
if err != nil {
112-
return nil, err
113-
}
114-
return raw.(provider.Provider), nil
115-
}
116-
117-
func StartFilesUpdaterPlugin(opts *PluginOpts) (updater.FilesUpdater, error) {
118-
raw, err := startPlugin(opts)
119-
if err != nil {
120-
return nil, err
121-
}
122-
return raw.(updater.FilesUpdater), nil
123-
}
124-
125-
func StartHooksPlugin(opts *PluginOpts) (hooks.Hooks, error) {
126-
raw, err := startPlugin(opts)
127-
if err != nil {
128-
return nil, err
129-
}
130-
return raw.(hooks.Hooks), nil
131-
}

pkg/plugin/manager/manager.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func (m *PluginManager) GetCICondition() (condition.CICondition, error) {
3434
return nil, err
3535
}
3636

37-
cic, err := plugin.StartCIConditionPlugin(opts)
37+
cic, err := plugin.StartPlugin(opts)
3838
if err != nil {
3939
return nil, err
4040
}
41-
return cic, nil
41+
return cic.(condition.CICondition), nil
4242
}
4343

4444
func (m *PluginManager) GetProvider() (provider.Provider, error) {
@@ -47,11 +47,11 @@ func (m *PluginManager) GetProvider() (provider.Provider, error) {
4747
return nil, err
4848
}
4949

50-
provider, err := plugin.StartProviderPlugin(opts)
50+
prov, err := plugin.StartPlugin(opts)
5151
if err != nil {
5252
return nil, err
5353
}
54-
return provider, nil
54+
return prov.(provider.Provider), nil
5555
}
5656

5757
func (m *PluginManager) GetCommitAnalyzer() (analyzer.CommitAnalyzer, error) {
@@ -60,11 +60,11 @@ func (m *PluginManager) GetCommitAnalyzer() (analyzer.CommitAnalyzer, error) {
6060
return nil, err
6161
}
6262

63-
ca, err := plugin.StartCommitAnalyzerPlugin(opts)
63+
ca, err := plugin.StartPlugin(opts)
6464
if err != nil {
6565
return nil, err
6666
}
67-
return ca, nil
67+
return ca.(analyzer.CommitAnalyzer), nil
6868
}
6969

7070
func (m *PluginManager) GetChangelogGenerator() (generator.ChangelogGenerator, error) {
@@ -73,11 +73,11 @@ func (m *PluginManager) GetChangelogGenerator() (generator.ChangelogGenerator, e
7373
return nil, err
7474
}
7575

76-
cg, err := plugin.StartChangelogGeneratorPlugin(opts)
76+
cg, err := plugin.StartPlugin(opts)
7777
if err != nil {
7878
return nil, err
7979
}
80-
return cg, nil
80+
return cg.(generator.ChangelogGenerator), nil
8181
}
8282

8383
func (m *PluginManager) GetChainedUpdater() (*updater.ChainedUpdater, error) {
@@ -88,11 +88,11 @@ func (m *PluginManager) GetChainedUpdater() (*updater.ChainedUpdater, error) {
8888
return nil, err
8989
}
9090

91-
upd, err := plugin.StartFilesUpdaterPlugin(opts)
91+
upd, err := plugin.StartPlugin(opts)
9292
if err != nil {
9393
return nil, err
9494
}
95-
updaters = append(updaters, upd)
95+
updaters = append(updaters, upd.(updater.FilesUpdater))
9696
}
9797

9898
updater := &updater.ChainedUpdater{
@@ -109,11 +109,11 @@ func (m *PluginManager) GetChainedHooksExecutor() (*hooks.ChainedHooksExecutor,
109109
return nil, err
110110
}
111111

112-
hp, err := plugin.StartHooksPlugin(opts)
112+
hp, err := plugin.StartPlugin(opts)
113113
if err != nil {
114114
return nil, err
115115
}
116-
hooksChain = append(hooksChain, hp)
116+
hooksChain = append(hooksChain, hp.(hooks.Hooks))
117117
}
118118

119119
return &hooks.ChainedHooksExecutor{

0 commit comments

Comments
 (0)