Skip to content

Commit 9dece2b

Browse files
Nathan JohnsonNathan Johnson
authored andcommitted
feat: GitlabRepositoryProvider now handles leading slashes for content URLs
1 parent cc5a9c9 commit 9dece2b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class GitlabRepositoryProvider extends RepositoryProvider {
8888
// https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
8989
//
9090
final ref = revision ?: getDefaultBranch()
91+
path = path.replaceAll("^/+", "") // leading slashes cause 400s with GitLab
9192
final encodedPath = URLEncoder.encode(path,'utf-8')
9293
return "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/files/${encodedPath}?ref=${ref}"
9394
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package nextflow.scm
1919
import spock.lang.IgnoreIf
2020
import spock.lang.Requires
2121
import spock.lang.Specification
22+
import spock.lang.Unroll
2223

2324
/**
2425
*
@@ -50,16 +51,20 @@ class GitlabRepositoryProviderTest extends Specification {
5051
}
5152

5253
@Requires({System.getenv('NXF_GITLAB_ACCESS_TOKEN')})
53-
def 'should read file content'() {
54+
@Unroll
55+
def 'should read file content: #contentURL'() {
5456
given:
5557
def token = System.getenv('NXF_GITLAB_ACCESS_TOKEN')
5658
def config = new ProviderConfig('gitlab').setAuth(token)
5759

5860
when:
5961
def repo = new GitlabRepositoryProvider('pditommaso/hello', config)
60-
def result = repo.readText('main.nf')
62+
def result = repo.readText(contentURL)
6163
then:
6264
result.trim().startsWith('#!/usr/bin/env nextflow')
65+
where:
66+
contentURL << ['main.nf', '/main.nf']
67+
6368
}
6469

6570
@Requires({System.getenv('NXF_GITLAB_ACCESS_TOKEN')})

0 commit comments

Comments
 (0)