diff --git a/go.mod b/go.mod index 7ab5b9d..57434e0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( 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/xanzy/go-gitlab v0.34.2 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect diff --git a/go.sum b/go.sum index 63cc0d8..c0f5826 100644 --- a/go.sum +++ b/go.sum @@ -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-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.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/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= diff --git a/pkg/provider/gitlab.go b/pkg/provider/gitlab.go index 07221c2..c5c808f 100644 --- a/pkg/provider/gitlab.go +++ b/pkg/provider/gitlab.go @@ -83,14 +83,14 @@ func (repo *GitLabRepository) GetInfo() (*provider.RepositoryInfo, error) { }, nil } -func (repo *GitLabRepository) GetCommits(sha string) ([]*semrel.RawCommit, error) { +func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit, error) { opts := &gitlab.ListCommitsOptions{ ListOptions: gitlab.ListOptions{ Page: 1, PerPage: 100, }, - RefName: gitlab.String(fmt.Sprintf("%s...%s", repo.branch, sha)), - All: gitlab.Bool(true), + // No Matter the order ofr fromSha and toSha gitlab always returns commits in reverse chronological order + RefName: gitlab.String(fmt.Sprintf("%s...%s", fromSha, toSha)), } allCommits := make([]*semrel.RawCommit, 0) @@ -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 } diff --git a/pkg/provider/gitlab_test.go b/pkg/provider/gitlab_test.go index 49b5177..1381dd0 100644 --- a/pkg/provider/gitlab_test.go +++ b/pkg/provider/gitlab_test.go @@ -139,7 +139,7 @@ func TestGitlabGetInfo(t *testing.T) { func TestGitlabGetCommits(t *testing.T) { repo, ts := getNewGitlabTestRepo(t) defer ts.Close() - commits, err := repo.GetCommits("") + commits, err := repo.GetCommits("", "") require.NoError(t, err) require.Len(t, commits, 4)