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
68b29a0a
Commit
68b29a0a
authored
2 years ago
by
Christoph Witzko
Browse files
Options
Downloads
Patches
Plain Diff
style: add .golangci.yaml
parent
fc53e33d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.golangci.yaml
+25
-0
25 additions, 0 deletions
.golangci.yaml
pkg/provider/gitlab.go
+5
-7
5 additions, 7 deletions
pkg/provider/gitlab.go
pkg/provider/gitlab_test.go
+37
-34
37 additions, 34 deletions
pkg/provider/gitlab_test.go
with
67 additions
and
41 deletions
.golangci.yaml
0 → 100644
+
25
−
0
View file @
68b29a0a
linters
:
enable
:
-
errorlint
-
forbidigo
-
gochecknoinits
-
gocritic
-
goconst
-
gocyclo
-
gofumpt
-
goimports
-
misspell
-
revive
-
unconvert
-
unparam
-
wastedassign
linters-settings
:
gocyclo
:
min-complexity
:
12
gofumpt
:
extra-rules
:
true
govet
:
enable-all
:
true
disable
:
-
fieldalignment
This diff is collapsed.
Click to expand it.
pkg/provider/gitlab.go
+
5
−
7
View file @
68b29a0a
...
...
@@ -23,9 +23,9 @@ type GitLabRepository struct {
}
func
(
repo
*
GitLabRepository
)
Init
(
config
map
[
string
]
string
)
error
{
gitlabBaseU
rl
:=
config
[
"gitlab_baseurl"
]
if
gitlabBaseU
rl
==
""
{
gitlabBaseU
rl
=
os
.
Getenv
(
"CI_SERVER_URL"
)
gitlabBaseU
RL
:=
config
[
"gitlab_baseurl"
]
if
gitlabBaseU
RL
==
""
{
gitlabBaseU
RL
=
os
.
Getenv
(
"CI_SERVER_URL"
)
}
token
:=
config
[
"token"
]
...
...
@@ -61,8 +61,8 @@ func (repo *GitLabRepository) Init(config map[string]string) error {
repo
.
branch
=
branch
var
client
*
gitlab
.
Client
if
gitlabBaseU
rl
!=
""
{
client
,
err
=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
gitlabBaseU
rl
))
if
gitlabBaseU
RL
!=
""
{
client
,
err
=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
gitlabBaseU
RL
))
}
else
{
client
,
err
=
gitlab
.
NewClient
(
token
)
}
...
...
@@ -77,7 +77,6 @@ func (repo *GitLabRepository) Init(config map[string]string) error {
func
(
repo
*
GitLabRepository
)
GetInfo
()
(
*
provider
.
RepositoryInfo
,
error
)
{
project
,
_
,
err
:=
repo
.
client
.
Projects
.
GetProject
(
repo
.
projectID
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -103,7 +102,6 @@ func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCo
for
{
commits
,
resp
,
err
:=
repo
.
client
.
Commits
.
ListCommits
(
repo
.
projectID
,
opts
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
pkg/provider/gitlab_test.go
+
37
−
34
View file @
68b29a0a
...
...
@@ -49,37 +49,40 @@ func createGitlabCommit(sha, message string) *gitlab.Commit {
return
&
gitlab
.
Commit
{
ID
:
sha
,
Message
:
message
}
}
func
createGitlabTag
(
name
,
sha
string
)
*
gitlab
.
Tag
{
var
testSHA
=
"deadbeef"
func
createGitlabTag
(
name
string
)
*
gitlab
.
Tag
{
return
&
gitlab
.
Tag
{
Name
:
name
,
Commit
:
&
gitlab
.
Commit
{
ID
:
sha
,
ID
:
testSHA
,
}}
}
var
(
GITLAB_PROJECT_
ID
=
12324322
GITLAB_DEFAULTBRANCH
=
"master"
GITLAB_PROJECT
=
gitlab
.
Project
{
DefaultBranch
:
GITLAB_DEFAULTBRANCH
,
Visibility
:
gitlab
.
PrivateVisibility
,
ID
:
GITLAB_PROJECT_
ID
}
GITLAB_COMMITS
=
[]
*
gitlab
.
Commit
{
gitlabProject
ID
=
12324322
gitlabDefaultBranch
=
"master"
gitlabProjects
=
gitlab
.
Project
{
DefaultBranch
:
gitlabDefaultBranch
,
Visibility
:
gitlab
.
PrivateVisibility
,
ID
:
gitlabProject
ID
}
gitlabCommits
=
[]
*
gitlab
.
Commit
{
createGitlabCommit
(
"abcd"
,
"feat(app): new feature"
),
createGitlabCommit
(
"dcba"
,
"Fix: bug"
),
createGitlabCommit
(
"cdba"
,
"Initial commit"
),
createGitlabCommit
(
"efcd"
,
"chore: break
\n
BREAKING CHANGE: breaks everything"
),
}
GITLAB_TAGS
=
[]
*
gitlab
.
Tag
{
createGitlabTag
(
"test-tag"
,
"deadbeef"
),
createGitlabTag
(
"v1.0.0"
,
"deadbeef"
),
createGitlabTag
(
"v2.0.0"
,
"deadbeef"
),
createGitlabTag
(
"v2.1.0-beta"
,
"deadbeef"
),
createGitlabTag
(
"v3.0.0-beta.2"
,
"deadbeef"
),
createGitlabTag
(
"v3.0.0-beta.1"
,
"deadbeef"
),
createGitlabTag
(
"2020.04.19"
,
"deadbeef"
),
gitlabTags
=
[]
*
gitlab
.
Tag
{
createGitlabTag
(
"test-tag"
),
createGitlabTag
(
"v1.0.0"
),
createGitlabTag
(
"v2.0.0"
),
createGitlabTag
(
"v2.1.0-beta"
),
createGitlabTag
(
"v3.0.0-beta.2"
),
createGitlabTag
(
"v3.0.0-beta.1"
),
createGitlabTag
(
"2020.04.19"
),
}
)
//nolint:errcheck
//gocyclo:ignore
func
GitlabHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// Rate Limit headers
if
r
.
Method
==
"GET"
&&
r
.
URL
.
Path
==
"/api/v4/"
{
if
r
.
Method
==
http
.
MethodGet
&&
r
.
URL
.
Path
==
"/api/v4/"
{
json
.
NewEncoder
(
w
)
.
Encode
(
struct
{}{})
return
}
...
...
@@ -89,22 +92,22 @@ func GitlabHandler(w http.ResponseWriter, r *http.Request) {
return
}
if
r
.
Method
==
"GET"
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d"
,
GITLAB_PROJECT_
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
GITLAB_PROJECT
)
if
r
.
Method
==
http
.
MethodGet
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d"
,
gitlabProject
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
gitlabProjects
)
return
}
if
r
.
Method
==
"GET"
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/repository/commits"
,
GITLAB_PROJECT_
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
GITLAB_COMMITS
)
if
r
.
Method
==
http
.
MethodGet
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/repository/commits"
,
gitlabProject
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
gitlabCommits
)
return
}
if
r
.
Method
==
"GET"
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/repository/tags"
,
GITLAB_PROJECT_
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
GITLAB_TAGS
)
if
r
.
Method
==
http
.
MethodGet
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/repository/tags"
,
gitlabProject
ID
)
{
json
.
NewEncoder
(
w
)
.
Encode
(
gitlabTags
)
return
}
if
r
.
Method
==
"POST"
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/releases"
,
GITLAB_PROJECT_
ID
)
{
if
r
.
Method
==
http
.
MethodPost
&&
r
.
URL
.
Path
==
fmt
.
Sprintf
(
"/api/v4/projects/%d/releases"
,
gitlabProject
ID
)
{
var
data
map
[
string
]
string
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
data
)
r
.
Body
.
Close
()
...
...
@@ -128,7 +131,7 @@ func getNewGitlabTestRepo(t *testing.T) (*GitLabRepository, *httptest.Server) {
"gitlab_baseurl"
:
ts
.
URL
,
"token"
:
"gitlab-examples-ci"
,
"gitlab_branch"
:
""
,
"gitlab_projectid"
:
strconv
.
Itoa
(
GITLAB_PROJECT_
ID
),
"gitlab_projectid"
:
strconv
.
Itoa
(
gitlabProject
ID
),
})
require
.
NoError
(
t
,
err
)
...
...
@@ -140,7 +143,7 @@ func TestGitlabGetInfo(t *testing.T) {
defer
ts
.
Close
()
repoInfo
,
err
:=
repo
.
GetInfo
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
GITLAB_DEFAULTBRANCH
,
repoInfo
.
DefaultBranch
)
require
.
Equal
(
t
,
gitlabDefaultBranch
,
repoInfo
.
DefaultBranch
)
require
.
True
(
t
,
repoInfo
.
Private
)
}
...
...
@@ -152,8 +155,8 @@ func TestGitlabGetCommits(t *testing.T) {
require
.
Len
(
t
,
commits
,
4
)
for
i
,
c
:=
range
commits
{
require
.
Equal
(
t
,
c
.
SHA
,
GITLAB_COMMITS
[
i
]
.
ID
)
require
.
Equal
(
t
,
c
.
RawMessage
,
GITLAB_COMMITS
[
i
]
.
Message
)
require
.
Equal
(
t
,
c
.
SHA
,
gitlabCommits
[
i
]
.
ID
)
require
.
Equal
(
t
,
c
.
RawMessage
,
gitlabCommits
[
i
]
.
Message
)
}
}
...
...
@@ -167,11 +170,11 @@ func TestGitlabGetReleases(t *testing.T) {
expectedSHA
string
expectedVersion
string
}{
{
""
,
""
,
"deadbeef"
,
"2020.4.19"
},
{
""
,
"^v[0-9]*"
,
"deadbeef"
,
"2.0.0"
},
{
"2-beta"
,
""
,
"deadbeef"
,
"2.1.0-beta"
},
{
"3-beta"
,
""
,
"deadbeef"
,
"3.0.0-beta.2"
},
{
"4-beta"
,
""
,
"deadbeef"
,
"4.0.0-beta"
},
{
""
,
""
,
testSHA
,
"2020.4.19"
},
{
""
,
"^v[0-9]*"
,
testSHA
,
"2.0.0"
},
{
"2-beta"
,
""
,
testSHA
,
"2.1.0-beta"
},
{
"3-beta"
,
""
,
testSHA
,
"3.0.0-beta.2"
},
{
"4-beta"
,
""
,
testSHA
,
"4.0.0-beta"
},
}
for
_
,
tc
:=
range
testCases
{
...
...
@@ -189,7 +192,7 @@ func TestGitlabGetReleases(t *testing.T) {
func
TestGitlabCreateRelease
(
t
*
testing
.
T
)
{
repo
,
ts
:=
getNewGitlabTestRepo
(
t
)
defer
ts
.
Close
()
err
:=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
"deadbeef"
})
err
:=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
testSHA
})
require
.
NoError
(
t
,
err
)
}
...
...
@@ -202,12 +205,12 @@ func TestGitlabStripVTagRelease(t *testing.T) {
"gitlab_baseurl"
:
ts
.
URL
,
"token"
:
"gitlab-examples-ci"
,
"gitlab_branch"
:
""
,
"gitlab_projectid"
:
strconv
.
Itoa
(
GITLAB_PROJECT_
ID
),
"gitlab_projectid"
:
strconv
.
Itoa
(
gitlabProject
ID
),
"strip_v_tag_prefix"
:
"true"
,
})
require
.
NoError
(
t
,
err
)
err
=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
"deadbeef"
})
err
=
repo
.
CreateRelease
(
&
provider
.
CreateReleaseConfig
{
NewVersion
:
"2.0.0"
,
SHA
:
testSHA
})
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