-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
124eecd
commit 9a75641
Showing
5 changed files
with
98 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,30 @@ | ||
package registry | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"runtime" | ||
"sort" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/go-semantic-release/plugin-registry/pkg/client" | ||
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin" | ||
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver" | ||
) | ||
|
||
type Resolver struct{} | ||
const DefaultEndpoint = "https://registry-staging.go-semantic-release.xyz/api/v2" | ||
|
||
func NewResolver() *Resolver { | ||
return &Resolver{} | ||
type Resolver struct { | ||
client *client.Client | ||
} | ||
|
||
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) { | ||
pluginAPIRes, err := getPluginInfo(pluginInfo.NormalizedName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
foundVersion := "" | ||
if pluginInfo.Constraint == nil { | ||
foundVersion = pluginAPIRes.LatestRelease | ||
} else { | ||
versions := make(semver.Collection, 0) | ||
for v := range pluginAPIRes.Versions { | ||
pv, err := semver.NewVersion(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
versions = append(versions, pv) | ||
} | ||
sort.Sort(sort.Reverse(versions)) | ||
for _, v := range versions { | ||
if pluginInfo.Constraint.Check(v) { | ||
foundVersion = v.String() | ||
break | ||
} | ||
} | ||
} | ||
|
||
if foundVersion == "" { | ||
return nil, errors.New("version not found") | ||
func NewResolver() *Resolver { | ||
return &Resolver{ | ||
client: client.New(DefaultEndpoint), | ||
} | ||
} | ||
|
||
releaseAsset := pluginAPIRes.Versions[foundVersion].getMatchingAsset() | ||
if releaseAsset == nil { | ||
return nil, fmt.Errorf("a matching plugin was not found for %s/%s", runtime.GOOS, runtime.GOARCH) | ||
} | ||
return &resolver.PluginDownloadInfo{ | ||
URL: releaseAsset.URL, | ||
Checksum: releaseAsset.Checksum, | ||
FileName: releaseAsset.FileName, | ||
Version: foundVersion, | ||
}, nil | ||
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) { | ||
return nil, fmt.Errorf("not implemented") | ||
} | ||
|
||
func (r *Resolver) Names() []string { | ||
return []string{"registry"} | ||
// TODO: this should be registry when the registry is ready | ||
return []string{"registry-beta"} | ||
} |
2 changes: 1 addition & 1 deletion
2
...plugin/discovery/resolver/registry/api.go → ...ugin/discovery/resolver/registryV1/api.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package registry | ||
package registryV1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package registryV1 | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"runtime" | ||
"sort" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin" | ||
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver" | ||
) | ||
|
||
type Resolver struct{} | ||
|
||
func NewResolver() *Resolver { | ||
return &Resolver{} | ||
} | ||
|
||
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) { | ||
pluginAPIRes, err := getPluginInfo(pluginInfo.NormalizedName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
foundVersion := "" | ||
if pluginInfo.Constraint == nil { | ||
foundVersion = pluginAPIRes.LatestRelease | ||
} else { | ||
versions := make(semver.Collection, 0) | ||
for v := range pluginAPIRes.Versions { | ||
pv, err := semver.NewVersion(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
versions = append(versions, pv) | ||
} | ||
sort.Sort(sort.Reverse(versions)) | ||
for _, v := range versions { | ||
if pluginInfo.Constraint.Check(v) { | ||
foundVersion = v.String() | ||
break | ||
} | ||
} | ||
} | ||
|
||
if foundVersion == "" { | ||
return nil, errors.New("version not found") | ||
} | ||
|
||
releaseAsset := pluginAPIRes.Versions[foundVersion].getMatchingAsset() | ||
if releaseAsset == nil { | ||
return nil, fmt.Errorf("a matching plugin was not found for %s/%s", runtime.GOOS, runtime.GOARCH) | ||
} | ||
return &resolver.PluginDownloadInfo{ | ||
URL: releaseAsset.URL, | ||
Checksum: releaseAsset.Checksum, | ||
FileName: releaseAsset.FileName, | ||
Version: foundVersion, | ||
}, nil | ||
} | ||
|
||
func (r *Resolver) Names() []string { | ||
return []string{"registry"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters