Skip to content

Commit c26c7db

Browse files
committed
Fix GitLab repository tree pagination
Signed-off-by: Gavin Elder <gavin.elder@seqera.io>
1 parent 084fdc3 commit c26c7db

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

modules/nextflow/src/main/groovy/nextflow/scm/GitlabRepositoryProvider.groovy

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,12 @@ class GitlabRepositoryProvider extends RepositoryProvider {
223223
if (depth > 1) {
224224
params.add("recursive=true")
225225
}
226+
params.add("per_page=${MAX_PER_PAGE}")
226227

227-
if (params) {
228-
url += "?" + params.join("&")
229-
}
228+
url += "?" + params.join("&")
230229

231-
// Make the API call and parse response
232-
String response = invoke(url)
233-
List<Map> treeEntries = response ? new JsonSlurper().parseText(response) as List<Map> : []
230+
// Make the API call and parse response, fetching all pages
231+
List<Map> treeEntries = this.<Map>invokeAndResponseWithPaging(url, { Map entry -> entry })
234232

235233
if (!treeEntries) {
236234
return []

modules/nextflow/src/test/groovy/nextflow/scm/GitlabRepositoryProviderTest.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,34 @@ class GitlabRepositoryProviderTest extends Specification {
260260
entries.every { it.path && it.sha }
261261
}
262262

263+
def 'should follow all GitLab pagination links when listing a directory' () {
264+
given:
265+
def provider = Spy(GitlabRepositoryProvider, constructorArgs: ['pditommaso/hello', new ProviderConfig('gitlab')])
266+
provider.setRevision('main')
267+
and:
268+
def base = 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/tree?ref=main&per_page=100'
269+
int page = 0
270+
271+
when:
272+
def entries = provider.listDirectory('/', 1)
273+
274+
then:
275+
101 * provider.invokeResponse(_ as String) >> { String url ->
276+
page++
277+
assert url == (page == 1 ? base : "${base}&page=${page}")
278+
final next = page < 101 ? "${base}&page=${page + 1}" : null
279+
final link = next ? "<${next}>; rel=\"next\"" : null
280+
response(
281+
url,
282+
"""[{"id":"sha-${page}","name":"file-${page}.nf","type":"blob","path":"file-${page}.nf"}]""",
283+
link
284+
)
285+
}
286+
and:
287+
entries.size() == 101
288+
entries.every { it.type == RepositoryProvider.EntryType.FILE && it.path && it.sha }
289+
}
290+
263291
def 'should follow GitLab pagination links when listing branches' () {
264292
given:
265293
def provider = Spy(GitlabRepositoryProvider, constructorArgs: ['pditommaso/hello', new ProviderConfig('gitlab')])

0 commit comments

Comments
 (0)