Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
provider-git
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-git
Commits
c70d912c
Commit
c70d912c
authored
4 years ago
by
Christoph Witzko
Browse files
Options
Downloads
Patches
Plain Diff
test: improve tests
parent
1e2978df
Branches
Branches containing commit
Tags
v1.1.0
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.github/workflows/ci.yml
+1
-0
1 addition, 0 deletions
.github/workflows/ci.yml
pkg/provider/git.go
+38
-1
38 additions, 1 deletion
pkg/provider/git.go
pkg/provider/git_test.go
+65
-27
65 additions, 27 deletions
pkg/provider/git_test.go
with
104 additions
and
28 deletions
.github/workflows/ci.yml
+
1
−
0
View file @
c70d912c
...
...
@@ -29,6 +29,7 @@ jobs:
with
:
go-version
:
1.15
-
run
:
go build ./cmd/provider-git/
-
run
:
./scripts/start-gitea.sh
-
run
:
go test -v ./...
release
:
runs-on
:
ubuntu-latest
...
...
This diff is collapsed.
Click to expand it.
pkg/provider/git.go
+
38
−
1
View file @
c70d912c
...
...
@@ -8,9 +8,13 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
)
...
...
@@ -21,6 +25,8 @@ type Repository struct {
defaultBranch
string
taggerName
string
taggerEmail
string
remoteName
string
auth
transport
.
AuthMethod
repo
*
git
.
Repository
}
...
...
@@ -40,6 +46,30 @@ func (repo *Repository) Init(config map[string]string) error {
repo
.
taggerEmail
=
"git@go-semantic-release.xyz"
}
repo
.
remoteName
=
config
[
"remote_name"
]
if
repo
.
remoteName
==
""
{
repo
.
remoteName
=
"origin"
}
if
config
[
"auth_username"
]
==
""
{
config
[
"auth_username"
]
=
"git"
}
if
config
[
"auth"
]
==
"basic"
{
repo
.
auth
=
&
http
.
BasicAuth
{
Username
:
config
[
"auth_username"
],
Password
:
config
[
"auth_password"
],
}
}
else
if
config
[
"auth"
]
==
"ssh"
{
auth
,
err
:=
ssh
.
NewPublicKeysFromFile
(
config
[
"auth_username"
],
config
[
"auth_private_key"
],
config
[
"auth_password"
])
if
err
!=
nil
{
return
err
}
repo
.
auth
=
auth
}
else
{
repo
.
auth
=
nil
}
gitPath
:=
config
[
"git_path"
]
if
gitPath
==
""
{
gitPath
=
"."
...
...
@@ -144,7 +174,14 @@ func (repo *Repository) CreateRelease(release *provider.CreateReleaseConfig) err
if
err
!=
nil
{
return
err
}
return
nil
err
=
repo
.
repo
.
Push
(
&
git
.
PushOptions
{
RemoteName
:
repo
.
remoteName
,
RefSpecs
:
[]
config
.
RefSpec
{
config
.
RefSpec
(
fmt
.
Sprintf
(
"refs/tags/%s:refs/tags/%s"
,
tag
,
tag
)),
},
Auth
:
repo
.
auth
,
})
return
err
}
func
(
repo
*
Repository
)
Name
()
string
{
...
...
This diff is collapsed.
Click to expand it.
pkg/provider/git_test.go
+
65
−
27
View file @
c70d912c
...
...
@@ -8,32 +8,49 @@ import (
"time"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-semantic-release/semantic-release/v2/pkg/provider"
"github.com/stretchr/testify/require"
)
func
TestNewRepository
(
t
*
testing
.
T
)
{
var
testGitPath
string
func
TestGit
(
t
*
testing
.
T
)
{
var
err
error
testGitPath
,
err
=
setupRepo
()
require
.
NoError
(
t
,
err
)
t
.
Run
(
"NewRepository"
,
newRepository
)
t
.
Run
(
"GetInfo"
,
getInfo
)
t
.
Run
(
"GetReleases"
,
getReleases
)
t
.
Run
(
"GetCommits"
,
getCommits
)
t
.
Run
(
"CreateRelease"
,
createRelease
)
}
func
newRepository
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
repo
:=
&
Repository
{}
err
:=
repo
.
Init
(
map
[
string
]
string
{})
require
.
EqualError
(
err
,
"repository does not exist"
)
gitPath
,
err
:=
setupRepo
()
require
.
NoError
(
err
)
repo
=
&
Repository
{}
err
=
repo
.
Init
(
map
[
string
]
string
{
"git_path"
:
g
itPath
,
"git_path"
:
testG
itPath
,
"default_branch"
:
"development"
,
"tagger_name"
:
"test"
,
"tagger_email"
:
"test@test.com"
,
"auth"
:
"basic"
,
"auth_username"
:
"test"
,
"auth_password"
:
"test"
,
})
require
.
NoError
(
err
)
require
.
Equal
(
repo
.
defaultBranch
,
"development"
)
require
.
Equal
(
repo
.
taggerName
,
"test"
)
require
.
Equal
(
repo
.
taggerEmail
,
"test@test.com"
)
require
.
Equal
(
"development"
,
repo
.
defaultBranch
)
require
.
Equal
(
"test"
,
repo
.
taggerName
)
require
.
Equal
(
"test@test.com"
,
repo
.
taggerEmail
)
require
.
NotNil
(
repo
.
auth
)
}
func
setupRepo
()
(
string
,
error
)
{
...
...
@@ -45,6 +62,14 @@ func setupRepo() (string, error) {
if
err
!=
nil
{
return
""
,
err
}
_
,
err
=
repo
.
CreateRemote
(
&
config
.
RemoteConfig
{
Name
:
"origin"
,
URLs
:
[]
string
{
"http://localhost:3000/test/test.git"
},
})
if
err
!=
nil
{
return
""
,
err
}
w
,
err
:=
repo
.
Worktree
()
if
err
!=
nil
{
return
""
,
err
...
...
@@ -91,38 +116,51 @@ func setupRepo() (string, error) {
return
""
,
err
}
return
dir
,
nil
}
func
createRepo
()
(
*
Repository
,
string
,
error
)
{
gitPath
,
err
:=
setupRepo
()
err
=
repo
.
Push
(
&
git
.
PushOptions
{
RemoteName
:
"origin"
,
RefSpecs
:
[]
config
.
RefSpec
{
"refs/heads/*:refs/heads/*"
,
"refs/tags/*:refs/tags/*"
,
},
Auth
:
&
http
.
BasicAuth
{
Username
:
"test"
,
Password
:
"test"
,
},
Force
:
true
,
})
if
err
!=
nil
{
return
nil
,
""
,
err
return
""
,
err
}
return
dir
,
nil
}
func
createRepo
()
(
*
Repository
,
error
)
{
repo
:=
&
Repository
{}
err
=
repo
.
Init
(
map
[
string
]
string
{
"git_path"
:
gitPath
,
err
:=
repo
.
Init
(
map
[
string
]
string
{
"git_path"
:
testGitPath
,
"auth"
:
"basic"
,
"auth_username"
:
"test"
,
"auth_password"
:
"test"
,
})
if
err
!=
nil
{
return
nil
,
""
,
err
return
nil
,
err
}
return
repo
,
gitPath
,
nil
return
repo
,
nil
}
func
TestG
etInfo
(
t
*
testing
.
T
)
{
func
g
etInfo
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
repo
,
_
,
err
:=
createRepo
()
repo
,
err
:=
createRepo
()
require
.
NoError
(
err
)
repoInfo
,
err
:=
repo
.
GetInfo
()
require
.
NoError
(
err
)
require
.
Equal
(
"master"
,
repoInfo
.
DefaultBranch
)
}
func
TestG
etCommits
(
t
*
testing
.
T
)
{
func
g
etCommits
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
repo
,
_
,
err
:=
createRepo
()
repo
,
err
:=
createRepo
()
require
.
NoError
(
err
)
commits
,
err
:=
repo
.
GetCommits
(
""
,
"master"
)
require
.
NoError
(
err
)
...
...
@@ -133,12 +171,12 @@ func TestGetCommits(t *testing.T) {
}
}
func
TestGithubC
reateRelease
(
t
*
testing
.
T
)
{
func
c
reateRelease
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
repo
,
gitPath
,
err
:=
createRepo
()
repo
,
err
:=
createRepo
()
require
.
NoError
(
err
)
gRepo
,
err
:=
git
.
PlainOpen
(
g
itPath
)
gRepo
,
err
:=
git
.
PlainOpen
(
testG
itPath
)
require
.
NoError
(
err
)
head
,
err
:=
gRepo
.
Head
()
require
.
NoError
(
err
)
...
...
@@ -159,9 +197,9 @@ func TestGithubCreateRelease(t *testing.T) {
require
.
Equal
(
"new feature
\n
"
,
tagObj
.
Message
)
}
func
TestG
etReleases
(
t
*
testing
.
T
)
{
func
g
etReleases
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
repo
,
_
,
err
:=
createRepo
()
repo
,
err
:=
createRepo
()
require
.
NoError
(
err
)
releases
,
err
:=
repo
.
GetReleases
(
""
)
...
...
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