Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ class GitlabRepositoryProvider extends RepositoryProvider {
if (depth > 1) {
params.add("recursive=true")
}
params.add("per_page=${MAX_PER_PAGE}")

if (params) {
url += "?" + params.join("&")
}
url += "?" + params.join("&")

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

if (!treeEntries) {
return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,34 @@ class GitlabRepositoryProviderTest extends Specification {
entries.every { it.path && it.sha }
}

def 'should follow all GitLab pagination links when listing a directory' () {
given:
def provider = Spy(GitlabRepositoryProvider, constructorArgs: ['pditommaso/hello', new ProviderConfig('gitlab')])
provider.setRevision('main')
and:
def base = 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/tree?ref=main&per_page=100'
int page = 0

when:
def entries = provider.listDirectory('/', 1)

then:
101 * provider.invokeResponse(_ as String) >> { String url ->
page++
assert url == (page == 1 ? base : "${base}&page=${page}")
final next = page < 101 ? "${base}&page=${page + 1}" : null
final link = next ? "<${next}>; rel=\"next\"" : null
response(
url,
"""[{"id":"sha-${page}","name":"file-${page}.nf","type":"blob","path":"file-${page}.nf"}]""",
link
)
}
and:
entries.size() == 101
entries.every { it.type == RepositoryProvider.EntryType.FILE && it.path && it.sha }
}

def 'should follow GitLab pagination links when listing branches' () {
given:
def provider = Spy(GitlabRepositoryProvider, constructorArgs: ['pditommaso/hello', new ProviderConfig('gitlab')])
Expand Down
Loading