Skip to content
Snippets Groups Projects
Commit cd36f67a authored by Ciaran Liedeman's avatar Ciaran Liedeman Committed by Christoph Witzko
Browse files

feat: Implemented to sha method

parent 4bd8009e
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ go 1.15 ...@@ -4,7 +4,7 @@ go 1.15
require ( require (
github.com/Masterminds/semver/v3 v3.1.0 github.com/Masterminds/semver/v3 v3.1.0
github.com/go-semantic-release/semantic-release/v2 v2.5.0 github.com/go-semantic-release/semantic-release/v2 v2.7.0
github.com/stretchr/testify v1.6.1 github.com/stretchr/testify v1.6.1
github.com/xanzy/go-gitlab v0.34.2 github.com/xanzy/go-gitlab v0.34.2
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
......
...@@ -60,6 +60,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 ...@@ -60,6 +60,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-semantic-release/semantic-release/v2 v2.5.0 h1:QDE5x/D/Rt7c1fcgZ3EGAgKOaBuK30R+SX4oPL8b6QI= github.com/go-semantic-release/semantic-release/v2 v2.5.0 h1:QDE5x/D/Rt7c1fcgZ3EGAgKOaBuK30R+SX4oPL8b6QI=
github.com/go-semantic-release/semantic-release/v2 v2.5.0/go.mod h1:2YcQ8CPUnSXnw5Krcakz8gDMrkd+eF69DySp8jAIbQI= github.com/go-semantic-release/semantic-release/v2 v2.5.0/go.mod h1:2YcQ8CPUnSXnw5Krcakz8gDMrkd+eF69DySp8jAIbQI=
github.com/go-semantic-release/semantic-release/v2 v2.7.0 h1:oJSHMjiCPXH9J+bHhtK+eM0R8k/VZvD9JwvzwYkDLZo=
github.com/go-semantic-release/semantic-release/v2 v2.7.0/go.mod h1:2YcQ8CPUnSXnw5Krcakz8gDMrkd+eF69DySp8jAIbQI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
......
...@@ -83,14 +83,14 @@ func (repo *GitLabRepository) GetInfo() (*provider.RepositoryInfo, error) { ...@@ -83,14 +83,14 @@ func (repo *GitLabRepository) GetInfo() (*provider.RepositoryInfo, error) {
}, nil }, nil
} }
func (repo *GitLabRepository) GetCommits(sha string) ([]*semrel.RawCommit, error) { func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit, error) {
opts := &gitlab.ListCommitsOptions{ opts := &gitlab.ListCommitsOptions{
ListOptions: gitlab.ListOptions{ ListOptions: gitlab.ListOptions{
Page: 1, Page: 1,
PerPage: 100, PerPage: 100,
}, },
RefName: gitlab.String(fmt.Sprintf("%s...%s", repo.branch, sha)), // No Matter the order ofr fromSha and toSha gitlab always returns commits in reverse chronological order
All: gitlab.Bool(true), RefName: gitlab.String(fmt.Sprintf("%s...%s", fromSha, toSha)),
} }
allCommits := make([]*semrel.RawCommit, 0) allCommits := make([]*semrel.RawCommit, 0)
...@@ -109,7 +109,10 @@ func (repo *GitLabRepository) GetCommits(sha string) ([]*semrel.RawCommit, error ...@@ -109,7 +109,10 @@ func (repo *GitLabRepository) GetCommits(sha string) ([]*semrel.RawCommit, error
}) })
} }
if resp.CurrentPage >= resp.TotalPages { // We cannot always rely on the total pages header
// https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23931
// if resp.CurrentPage >= resp.TotalPages {
if resp.NextPage == 0 {
break break
} }
......
...@@ -139,7 +139,7 @@ func TestGitlabGetInfo(t *testing.T) { ...@@ -139,7 +139,7 @@ func TestGitlabGetInfo(t *testing.T) {
func TestGitlabGetCommits(t *testing.T) { func TestGitlabGetCommits(t *testing.T) {
repo, ts := getNewGitlabTestRepo(t) repo, ts := getNewGitlabTestRepo(t)
defer ts.Close() defer ts.Close()
commits, err := repo.GetCommits("") commits, err := repo.GetCommits("", "")
require.NoError(t, err) require.NoError(t, err)
require.Len(t, commits, 4) require.Len(t, commits, 4)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment