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
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
......
......@@ -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
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment