Skip to content

Commit 2b10b0c

Browse files
committed
feat: sw gitlab pagination to keyset mode; adding sort option queries
1 parent bcb6148 commit 2b10b0c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/sparrow/targets/remote/gitlab/gitlab.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ func (c *client) fetchFileList(ctx context.Context) ([]string, error) {
155155
log.ErrorContext(ctx, "Could not parse GitLab API repository URL", "url", rawUrl, "error", err)
156156
}
157157
query := reqUrl.Query()
158-
query.Set("ref", c.config.Branch)
158+
query.Set("pagination", "keyset")
159159
query.Set("per_page", strconv.Itoa(paginationPerPage))
160+
query.Set("order_by", "id")
161+
query.Set("sort", "asc")
162+
163+
query.Set("ref", c.config.Branch)
160164
reqUrl.RawQuery = query.Encode()
161165

162166
return c.fetchNextFileList(ctx, reqUrl.String())

pkg/sparrow/targets/remote/gitlab/gitlab_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func Test_gitlab_fetchFileList(t *testing.T) {
107107
if err != nil {
108108
t.Fatalf("error creating mock response: %v", err)
109109
}
110-
httpmock.RegisterResponder("GET", fmt.Sprintf("http://test/api/v4/projects/1/repository/tree?per_page=%d&ref=main", paginationPerPage), resp)
110+
httpmock.RegisterResponder("GET", fmt.Sprintf("http://test/api/v4/projects/1/repository/tree?order_by=id&pagination=keyset&per_page=%d&ref=main&sort=asc", paginationPerPage), resp)
111111

112112
g := &client{
113113
config: Config{
@@ -217,7 +217,7 @@ func Test_gitlab_FetchFiles(t *testing.T) {
217217
if err != nil {
218218
t.Fatalf("error creating mock response: %v", err)
219219
}
220-
httpmock.RegisterResponder("GET", fmt.Sprintf("http://test/api/v4/projects/1/repository/tree?per_page=%d&ref=main", paginationPerPage), resp)
220+
httpmock.RegisterResponder("GET", fmt.Sprintf("http://test/api/v4/projects/1/repository/tree?order_by=id&pagination=keyset&per_page=%d&ref=main&sort=asc", paginationPerPage), resp)
221221

222222
got, err := g.FetchFiles(context.Background())
223223
if (err != nil) != tt.wantErr {

0 commit comments

Comments
 (0)