Skip to content

Commit

Permalink
refactor: rename PluginInfo struct to Info
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jan 13, 2023
1 parent 25a96d4 commit e61d4af
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/client.go
Expand Up @@ -27,7 +27,7 @@ func KillAllPlugins() {
}
}

func StartPlugin(pluginInfo *PluginInfo) (interface{}, error) {
func StartPlugin(pluginInfo *Info) (interface{}, error) {
runningClientsMx.Lock()
defer runningClientsMx.Unlock()
logR, logW := io.Pipe()
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/discovery/discovery.go
Expand Up @@ -50,7 +50,7 @@ func New(config *config.Config) (*Discovery, error) {
}, nil
}

func (d *Discovery) fetchPlugin(pluginInfo *plugin.PluginInfo) (string, error) {
func (d *Discovery) fetchPlugin(pluginInfo *plugin.Info) (string, error) {
pluginResolver, ok := d.resolvers[pluginInfo.Resolver]
if !ok {
return "", fmt.Errorf("resolver %s not found", pluginInfo.Resolver)
Expand All @@ -64,7 +64,7 @@ func (d *Discovery) fetchPlugin(pluginInfo *plugin.PluginInfo) (string, error) {
return downloadPlugin(pluginInfo, downloadInfo, d.config.ShowProgress)
}

func (d *Discovery) FindPlugin(t, name string) (*plugin.PluginInfo, error) {
func (d *Discovery) FindPlugin(t, name string) (*plugin.Info, error) {
pInfo, err := plugin.GetPluginInfo(t, name)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/discovery/download.go
Expand Up @@ -90,7 +90,7 @@ func extractFileFromTarGz(name, inputFile, outputFile string) error {

var tgzRegexp = regexp.MustCompile(`^(.*)\.(tgz|tar\.gz)$`)

func downloadPlugin(pluginInfo *plugin.PluginInfo, downloadInfo *resolver.PluginDownloadInfo, showProgress bool) (string, error) {
func downloadPlugin(pluginInfo *plugin.Info, downloadInfo *resolver.PluginDownloadInfo, showProgress bool) (string, error) {
versionDir := path.Join(pluginInfo.PluginPath, downloadInfo.Version)
targetFile := path.Join(versionDir, downloadInfo.FileName)
req, err := grab.NewRequest(targetFile, downloadInfo.URL)
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/discovery/local.go
Expand Up @@ -16,7 +16,7 @@ const PluginDir = ".semrel"

var osArchDir = runtime.GOOS + "_" + runtime.GOARCH

func setAndEnsurePluginPath(pluginInfo *plugin.PluginInfo) error {
func setAndEnsurePluginPath(pluginInfo *plugin.Info) error {
pluginPath := path.Join(PluginDir, osArchDir, pluginInfo.NormalizedName)
if _, err := os.Stat(pluginPath); os.IsNotExist(err) {
err = os.MkdirAll(pluginPath, 0o755)
Expand All @@ -32,7 +32,7 @@ func setAndEnsurePluginPath(pluginInfo *plugin.PluginInfo) error {

var ErrPluginNotFound = errors.New("no plugin was found")

func getMatchingVersionDir(pluginInfo *plugin.PluginInfo) (string, error) {
func getMatchingVersionDir(pluginInfo *plugin.Info) (string, error) {
vDirs, err := os.ReadDir(pluginInfo.PluginPath)
if err != nil {
return "", err
Expand Down Expand Up @@ -65,7 +65,7 @@ func getMatchingVersionDir(pluginInfo *plugin.PluginInfo) (string, error) {
return "", nil
}

func findPluginLocally(pluginInfo *plugin.PluginInfo) (string, error) {
func findPluginLocally(pluginInfo *plugin.Info) (string, error) {
vPth, err := getMatchingVersionDir(pluginInfo)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/discovery/resolver/github/github.go
Expand Up @@ -119,7 +119,7 @@ func (g *Resolver) getAllValidGitHubReleases(repoOwner, repoName string) (ghRele
return ret, nil
}

func (g *Resolver) ResolvePlugin(pluginInfo *plugin.PluginInfo) (*resolver.PluginDownloadInfo, error) {
func (g *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
if pluginInfo.RepoSlug == "" {
pluginInfo.RepoSlug = knownPlugins[pluginInfo.ShortNormalizedName]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/discovery/resolver/registry/registry.go
Expand Up @@ -17,7 +17,7 @@ func NewResolver() *Resolver {
return &Resolver{}
}

func (r *Resolver) ResolvePlugin(pluginInfo *plugin.PluginInfo) (*resolver.PluginDownloadInfo, error) {
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
pluginAPIRes, err := getPluginInfo(pluginInfo.NormalizedName)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/discovery/resolver/resolver.go
Expand Up @@ -10,6 +10,6 @@ type PluginDownloadInfo struct {
}

type Resolver interface {
ResolvePlugin(*plugin.PluginInfo) (*PluginDownloadInfo, error)
ResolvePlugin(*plugin.Info) (*PluginDownloadInfo, error)
Names() []string
}
6 changes: 3 additions & 3 deletions pkg/plugin/plugin.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/go-semantic-release/semantic-release/v2/pkg/updater"
)

type PluginInfo struct {
type Info struct {
Type string
Name string
NormalizedName string
Expand Down Expand Up @@ -45,7 +45,7 @@ func normalizedPluginType(t string) string {

var nameNormalizer = strings.NewReplacer(":", "-", "/", "-")

func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
func GetPluginInfo(pluginType, pluginName string) (*Info, error) {
nPluginType := normalizedPluginType(pluginType)
if nPluginType == "" {
return nil, fmt.Errorf("invalid plugin type: %s", pluginType)
Expand Down Expand Up @@ -96,7 +96,7 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
normalizedName = strings.Join(normalizedParts[:len(normalizedParts)-1], "@")
}

return &PluginInfo{
return &Info{
Type: pluginType,
Name: name,
NormalizedName: normalizedName,
Expand Down
18 changes: 9 additions & 9 deletions pkg/plugin/plugin_test.go
Expand Up @@ -17,32 +17,32 @@ func TestGetPluginInfo(t *testing.T) {
testCases := []struct {
t string
input string
results *PluginInfo
results *Info
}{
{"provider", "git", &PluginInfo{
{"provider", "git", &Info{
Type: "provider",
Name: "git",
NormalizedName: "provider-git",
ShortNormalizedName: "provider-git",
Resolver: "default",
}},
{"provider", "github:myorg/myplugin", &PluginInfo{
{"provider", "github:myorg/myplugin", &Info{
Type: "provider",
Name: "myplugin",
NormalizedName: "provider-github-myorg-myplugin",
ShortNormalizedName: "provider-myplugin",
Resolver: "github",
RepoSlug: "myorg/myplugin",
}},
{"ci_condition", "github:myorg/myplugin", &PluginInfo{
{"ci_condition", "github:myorg/myplugin", &Info{
Type: "ci_condition",
Name: "myplugin",
NormalizedName: "condition-github-myorg-myplugin",
ShortNormalizedName: "condition-myplugin",
Resolver: "github",
RepoSlug: "myorg/myplugin",
}},
{"provider", "github:myorg/myplugin@^1.0.0", &PluginInfo{
{"provider", "github:myorg/myplugin@^1.0.0", &Info{
Type: "provider",
Name: "myplugin",
NormalizedName: "provider-github-myorg-myplugin",
Expand All @@ -51,30 +51,30 @@ func TestGetPluginInfo(t *testing.T) {
RepoSlug: "myorg/myplugin",
Constraint: parseConstraint("^1.0.0"),
}},
{"provider", "git@2.0.0", &PluginInfo{
{"provider", "git@2.0.0", &Info{
Type: "provider",
Name: "git",
NormalizedName: "provider-git",
ShortNormalizedName: "provider-git",
Resolver: "default",
Constraint: parseConstraint("2.0.0"),
}},
{"hooks", "registry:logger", &PluginInfo{
{"hooks", "registry:logger", &Info{
Type: "hooks",
Name: "logger",
NormalizedName: "hooks-registry-logger",
ShortNormalizedName: "hooks-logger",
Resolver: "registry",
}},
{"hooks", "myresolver:@myorg/myplugin", &PluginInfo{
{"hooks", "myresolver:@myorg/myplugin", &Info{
Type: "hooks",
Name: "myplugin",
NormalizedName: "hooks-myresolver-@myorg-myplugin",
ShortNormalizedName: "hooks-myplugin",
Resolver: "myresolver",
RepoSlug: "@myorg/myplugin",
}},
{"hooks", "myresolver:@myorg/myplugin@1.2.3", &PluginInfo{
{"hooks", "myresolver:@myorg/myplugin@1.2.3", &Info{
Type: "hooks",
Name: "myplugin",
NormalizedName: "hooks-myresolver-@myorg-myplugin",
Expand Down
3 changes: 2 additions & 1 deletion pkg/semrel/semrel.go
Expand Up @@ -22,7 +22,8 @@ func calculateChange(commits []*Commit, latestRelease *Release) *Change {
return change
}

func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVersions bool, forceBumpPatchVersion bool) string {
//gocyclo:ignore
func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVersions, forceBumpPatchVersion bool) string {
version := semver.MustParse(rawVersion)
change := &Change{
Major: rawChange.Major,
Expand Down

0 comments on commit e61d4af

Please sign in to comment.