Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
semantic-release
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
go-semantic-release
semantic-release
Commits
c58af0bf
Commit
c58af0bf
authored
3 years ago
by
Christoph Witzko
Browse files
Options
Downloads
Patches
Plain Diff
feat: add slug to plugin info
parent
feb827a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/plugin/plugin.go
+20
-8
20 additions, 8 deletions
pkg/plugin/plugin.go
pkg/plugin/plugin_test.go
+20
-0
20 additions, 0 deletions
pkg/plugin/plugin_test.go
with
40 additions
and
8 deletions
pkg/plugin/plugin.go
+
20
−
8
View file @
c58af0bf
...
@@ -20,6 +20,7 @@ type PluginInfo struct {
...
@@ -20,6 +20,7 @@ type PluginInfo struct {
ShortNormalizedName
string
ShortNormalizedName
string
Constraint
*
semver
.
Constraints
Constraint
*
semver
.
Constraints
Resolver
string
Resolver
string
RepoSlug
string
PluginPath
string
PluginPath
string
BinPath
string
BinPath
string
}
}
...
@@ -42,14 +43,17 @@ func normalizedPluginType(t string) string {
...
@@ -42,14 +43,17 @@ func normalizedPluginType(t string) string {
return
""
return
""
}
}
var
nameNormalizer
=
strings
.
NewReplacer
(
":"
,
"-"
,
"/"
,
"-"
)
func
GetPluginInfo
(
pluginType
,
pluginName
string
)
(
*
PluginInfo
,
error
)
{
func
GetPluginInfo
(
pluginType
,
pluginName
string
)
(
*
PluginInfo
,
error
)
{
nPluginType
:=
normalizedPluginType
(
pluginType
)
nPluginType
:=
normalizedPluginType
(
pluginType
)
if
nPluginType
==
""
{
if
nPluginType
==
""
{
return
nil
,
fmt
.
Errorf
(
"invalid plugin type: %s"
,
pluginType
)
return
nil
,
fmt
.
Errorf
(
"invalid plugin type: %s"
,
pluginType
)
}
}
resolver
:=
"default"
resolver
:=
"default"
repoSlug
:=
""
name
:=
pluginName
name
:=
pluginName
normalizedName
:=
fmt
.
Sprintf
(
"%s-%s"
,
nPluginType
,
pluginName
)
normalizedName
:=
nameNormalizer
.
Replace
(
fmt
.
Sprintf
(
"%s-%s"
,
nPluginType
,
pluginName
)
)
if
strings
.
Contains
(
name
,
":"
)
{
if
strings
.
Contains
(
name
,
":"
)
{
parts
:=
strings
.
Split
(
name
,
":"
)
parts
:=
strings
.
Split
(
name
,
":"
)
...
@@ -58,16 +62,20 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
...
@@ -58,16 +62,20 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
}
}
resolver
=
parts
[
0
]
resolver
=
parts
[
0
]
name
=
parts
[
1
]
name
=
parts
[
1
]
normalizedName
=
strings
.
ReplaceAll
(
normalizedName
,
":"
,
"-"
)
}
}
if
strings
.
Contains
(
name
,
"/"
)
{
if
strings
.
Contains
(
name
,
"/"
)
{
parts
:=
strings
.
Split
(
name
,
"/"
)
slashParts
:=
strings
.
Split
(
name
,
"/"
)
if
len
(
parts
)
!=
2
{
pName
:=
slashParts
[
len
(
slashParts
)
-
1
]
return
nil
,
fmt
.
Errorf
(
"invalid plugin name format"
)
// remove version constraint from the slug
if
strings
.
Contains
(
pName
,
"@"
)
{
nameWithoutVersion
,
_
,
_
:=
strings
.
Cut
(
pName
,
"@"
)
repoSlug
=
strings
.
Join
(
slashParts
[
:
len
(
slashParts
)
-
1
],
"/"
)
+
"/"
+
nameWithoutVersion
}
else
{
repoSlug
=
name
}
}
name
=
parts
[
1
]
// the last part is the plugin name
n
ormalizedName
=
strings
.
ReplaceAll
(
normalizedName
,
"/"
,
"-"
)
n
ame
=
pName
}
}
var
constraint
*
semver
.
Constraints
var
constraint
*
semver
.
Constraints
...
@@ -82,7 +90,10 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
...
@@ -82,7 +90,10 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
}
}
name
=
parts
[
0
]
name
=
parts
[
0
]
constraint
=
v
constraint
=
v
normalizedName
,
_
,
_
=
strings
.
Cut
(
normalizedName
,
"@"
)
// remove version constraint from the normalized name
normalizedParts
:=
strings
.
Split
(
normalizedName
,
"@"
)
normalizedName
=
strings
.
Join
(
normalizedParts
[
:
len
(
normalizedParts
)
-
1
],
"@"
)
}
}
return
&
PluginInfo
{
return
&
PluginInfo
{
...
@@ -92,5 +103,6 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
...
@@ -92,5 +103,6 @@ func GetPluginInfo(pluginType, pluginName string) (*PluginInfo, error) {
ShortNormalizedName
:
fmt
.
Sprintf
(
"%s-%s"
,
nPluginType
,
name
),
ShortNormalizedName
:
fmt
.
Sprintf
(
"%s-%s"
,
nPluginType
,
name
),
Constraint
:
constraint
,
Constraint
:
constraint
,
Resolver
:
resolver
,
Resolver
:
resolver
,
RepoSlug
:
repoSlug
,
},
nil
},
nil
}
}
This diff is collapsed.
Click to expand it.
pkg/plugin/plugin_test.go
+
20
−
0
View file @
c58af0bf
...
@@ -32,6 +32,7 @@ func TestGetPluginInfo(t *testing.T) {
...
@@ -32,6 +32,7 @@ func TestGetPluginInfo(t *testing.T) {
NormalizedName
:
"provider-github-myorg-myplugin"
,
NormalizedName
:
"provider-github-myorg-myplugin"
,
ShortNormalizedName
:
"provider-myplugin"
,
ShortNormalizedName
:
"provider-myplugin"
,
Resolver
:
"github"
,
Resolver
:
"github"
,
RepoSlug
:
"myorg/myplugin"
,
}},
}},
{
"ci_condition"
,
"github:myorg/myplugin"
,
&
PluginInfo
{
{
"ci_condition"
,
"github:myorg/myplugin"
,
&
PluginInfo
{
Type
:
"ci_condition"
,
Type
:
"ci_condition"
,
...
@@ -39,6 +40,7 @@ func TestGetPluginInfo(t *testing.T) {
...
@@ -39,6 +40,7 @@ func TestGetPluginInfo(t *testing.T) {
NormalizedName
:
"condition-github-myorg-myplugin"
,
NormalizedName
:
"condition-github-myorg-myplugin"
,
ShortNormalizedName
:
"condition-myplugin"
,
ShortNormalizedName
:
"condition-myplugin"
,
Resolver
:
"github"
,
Resolver
:
"github"
,
RepoSlug
:
"myorg/myplugin"
,
}},
}},
{
"provider"
,
"github:myorg/myplugin@^1.0.0"
,
&
PluginInfo
{
{
"provider"
,
"github:myorg/myplugin@^1.0.0"
,
&
PluginInfo
{
Type
:
"provider"
,
Type
:
"provider"
,
...
@@ -46,6 +48,7 @@ func TestGetPluginInfo(t *testing.T) {
...
@@ -46,6 +48,7 @@ func TestGetPluginInfo(t *testing.T) {
NormalizedName
:
"provider-github-myorg-myplugin"
,
NormalizedName
:
"provider-github-myorg-myplugin"
,
ShortNormalizedName
:
"provider-myplugin"
,
ShortNormalizedName
:
"provider-myplugin"
,
Resolver
:
"github"
,
Resolver
:
"github"
,
RepoSlug
:
"myorg/myplugin"
,
Constraint
:
parseConstraint
(
"^1.0.0"
),
Constraint
:
parseConstraint
(
"^1.0.0"
),
}},
}},
{
"provider"
,
"git@2.0.0"
,
&
PluginInfo
{
{
"provider"
,
"git@2.0.0"
,
&
PluginInfo
{
...
@@ -63,6 +66,23 @@ func TestGetPluginInfo(t *testing.T) {
...
@@ -63,6 +66,23 @@ func TestGetPluginInfo(t *testing.T) {
ShortNormalizedName
:
"hooks-logger"
,
ShortNormalizedName
:
"hooks-logger"
,
Resolver
:
"registry"
,
Resolver
:
"registry"
,
}},
}},
{
"hooks"
,
"myresolver:@myorg/myplugin"
,
&
PluginInfo
{
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
{
Type
:
"hooks"
,
Name
:
"myplugin"
,
NormalizedName
:
"hooks-myresolver-@myorg-myplugin"
,
ShortNormalizedName
:
"hooks-myplugin"
,
Resolver
:
"myresolver"
,
RepoSlug
:
"@myorg/myplugin"
,
Constraint
:
parseConstraint
(
"1.2.3"
),
}},
}
}
for
_
,
testCase
:=
range
testCases
{
for
_
,
testCase
:=
range
testCases
{
results
,
err
:=
GetPluginInfo
(
testCase
.
t
,
testCase
.
input
)
results
,
err
:=
GetPluginInfo
(
testCase
.
t
,
testCase
.
input
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment