Skip to content

Commit b7fa6f4

Browse files
swingingsimianNathan Johnsonpditommaso
authored
GitlabRepositoryProvider now handles leading slashes for content URLs (#6284)
Signed-off-by: Author Name <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Nathan Johnson <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
1 parent cc5a9c9 commit b7fa6f4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +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-
final encodedPath = URLEncoder.encode(path,'utf-8')
91+
final encodedPath = URLEncoder.encode(path.stripStart('/'),'utf-8')
9292
return "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/files/${encodedPath}?ref=${ref}"
9393
}
9494

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,15 @@ class GitlabRepositoryProviderTest extends Specification {
121121
new GitlabRepositoryProvider('pditommaso/hello', obj)
122122
.getContentUrl('conf/extra.conf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/conf%2Fextra.conf?ref=master'
123123

124+
125+
and: // should strip leading slashes
126+
new GitlabRepositoryProvider('pditommaso/hello', obj)
127+
.getContentUrl('/main.nf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/main.nf?ref=master'
128+
129+
and:
130+
new GitlabRepositoryProvider('pditommaso/hello', obj)
131+
.getContentUrl('//conf/extra.conf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/conf%2Fextra.conf?ref=master'
132+
133+
124134
}
125135
}

0 commit comments

Comments
 (0)