Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
provider-gitlab
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
provider-gitlab
Commits
a8eab7a2
Unverified
Commit
a8eab7a2
authored
3 years ago
by
Mathieu St-Vincent
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add `strip_v_tag_prefix` config option
parent
77df67b8
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/provider/gitlab.go
+20
-9
20 additions, 9 deletions
pkg/provider/gitlab.go
pkg/provider/gitlab_test.go
+31
-4
31 additions, 4 deletions
pkg/provider/gitlab_test.go
with
51 additions
and
13 deletions
pkg/provider/gitlab.go
+
20
−
9
View file @
a8eab7a2
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
"strconv"
"github.com/Masterminds/semver/v3"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
...
...
@@ -17,6 +18,7 @@ var PVERSION = "dev"
type
GitLabRepository
struct
{
projectID
string
branch
string
stripVTagPrefix
bool
client
*
gitlab
.
Client
}
...
...
@@ -47,14 +49,18 @@ func (repo *GitLabRepository) Init(config map[string]string) error {
return
fmt
.
Errorf
(
"gitlab_projectid is required"
)
}
var
err
error
stripVTagPrefix
:=
config
[
"strip_v_tag_prefix"
]
repo
.
stripVTagPrefix
,
err
=
strconv
.
ParseBool
(
stripVTagPrefix
)
if
stripVTagPrefix
!=
""
&&
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to set property strip_v_tag_prefix: %w"
,
err
)
}
repo
.
projectID
=
projectID
repo
.
branch
=
branch
var
(
client
*
gitlab
.
Client
err
error
)
var
client
*
gitlab
.
Client
if
gitlabBaseUrl
!=
""
{
client
,
err
=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
gitlabBaseUrl
))
}
else
{
...
...
@@ -166,7 +172,12 @@ func (repo *GitLabRepository) GetReleases(rawRe string) ([]*semrel.Release, erro
}
func
(
repo
*
GitLabRepository
)
CreateRelease
(
release
*
provider
.
CreateReleaseConfig
)
error
{
tag
:=
fmt
.
Sprintf
(
"v%s"
,
release
.
NewVersion
)
prefix
:=
"v"
if
repo
.
stripVTagPrefix
{
prefix
=
""
}
tag
:=
prefix
+
release
.
NewVersion
// Gitlab does not have any notion of pre-releases
_
,
_
,
err
:=
repo
.
client
.
Releases
.
CreateRelease
(
repo
.
projectID
,
&
gitlab
.
CreateReleaseOptions
{
...
...
This diff is collapsed.
Click to expand it.
pkg/provider/gitlab_test.go
+
31
−
4
View file @
a8eab7a2
...
...
@@ -14,6 +14,11 @@ import (
"github.com/xanzy/go-gitlab"
)
var
validTags
=
map
[
string
]
bool
{
"v2.0.0"
:
true
,
"2.0.0"
:
true
,
}
func
TestNewGitlabRepository
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
...
...
@@ -34,6 +39,7 @@ func TestNewGitlabRepository(t *testing.T) {
"gitlab_baseurl"
:
"https://mygitlab.com"
,
"token"
:
"token"
,
"gitlab_projectid"
:
"1"
,
"strip_v_tag_prefix"
:
"true"
,
})
require
.
NoError
(
err
)
require
.
Equal
(
"https://mygitlab.com/api/v4/"
,
repo
.
client
.
BaseURL
()
.
String
(),
"invalid custom instance initialization"
)
...
...
@@ -102,10 +108,12 @@ func GitlabHandler(w http.ResponseWriter, r *http.Request) {
var
data
map
[
string
]
string
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
data
)
r
.
Body
.
Close
()
if
data
[
"tag_name"
]
!=
"v2.0.0"
{
if
_
,
ok
:=
validTags
[
data
[
"tag_name"
]];
!
ok
{
http
.
Error
(
w
,
"invalid tag name"
,
http
.
StatusBadRequest
)
return
}
fmt
.
Fprint
(
w
,
"{}"
)
return
}
...
...
@@ -184,3 +192,22 @@ func TestGitlabCreateRelease(t *testing.T) {
err
:=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
"deadbeef"
})
require
.
NoError
(
t
,
err
)
}
func
TestGitlabStripVTagRelease
(
t
*
testing
.
T
)
{
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
GitlabHandler
))
defer
ts
.
Close
()
repo
:=
&
GitLabRepository
{}
err
:=
repo
.
Init
(
map
[
string
]
string
{
"gitlab_baseurl"
:
ts
.
URL
,
"token"
:
"gitlab-examples-ci"
,
"gitlab_branch"
:
""
,
"gitlab_projectid"
:
strconv
.
Itoa
(
GITLAB_PROJECT_ID
),
"strip_v_tag_prefix"
:
"true"
,
})
require
.
NoError
(
t
,
err
)
err
=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
"deadbeef"
})
require
.
NoError
(
t
,
err
)
}
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