Skip to content
Merged
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 @@ -17,6 +17,7 @@
package nextflow.scm

import java.net.http.HttpResponse
import java.nio.charset.StandardCharsets
import java.util.regex.Pattern

import groovy.transform.CompileDynamic
Expand Down Expand Up @@ -97,7 +98,7 @@ final class AzureRepositoryProvider extends RepositoryProvider {
'path':path
] as Map<String,Object>
if( revision ) {
queryParams['versionDescriptor.version']=revision
queryParams['versionDescriptor.version']=URLEncoder.encode(revision, StandardCharsets.UTF_8)

if( COMMIT_REGEX.matcher(revision).matches() )
queryParams['versionDescriptor.versionType'] = 'commit'
Expand Down Expand Up @@ -203,7 +204,7 @@ final class AzureRepositoryProvider extends RepositoryProvider {
] as Map<String,Object>

if( revision ) {
queryParams['versionDescriptor.version'] = revision
queryParams['versionDescriptor.version'] = URLEncoder.encode(revision, StandardCharsets.UTF_8)
if( COMMIT_REGEX.matcher(revision).matches() )
queryParams['versionDescriptor.versionType'] = 'commit'
}
Expand Down Expand Up @@ -236,7 +237,7 @@ final class AzureRepositoryProvider extends RepositoryProvider {
}

if (revision) {
queryParams['versionDescriptor.version'] = revision
queryParams['versionDescriptor.version'] = URLEncoder.encode(revision, StandardCharsets.UTF_8)
if (COMMIT_REGEX.matcher(revision).matches()) {
queryParams['versionDescriptor.versionType'] = 'commit'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import groovy.json.JsonSlurper
import groovy.transform.Memoized
import groovy.util.logging.Slf4j
import nextflow.exception.AbortOperationException

import java.nio.charset.StandardCharsets

/**
* Implements a repository provider for the private hosted BitBucket Server service
*
Expand Down Expand Up @@ -73,7 +76,7 @@ final class BitbucketServerRepositoryProvider extends RepositoryProvider {
//
def result = "${config.endpoint}/rest/api/1.0/projects/${project}/repos/${repository}/raw/${path}"
if( revision )
result += "?at=$revision"
result += "?at=${URLEncoder.encode(revision, StandardCharsets.UTF_8)}"
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package nextflow.scm
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

import java.nio.charset.StandardCharsets

/**
* Implements a repository provider for Gitea service
*
Expand Down Expand Up @@ -86,7 +89,7 @@ final class GiteaRepositoryProvider extends RepositoryProvider {
// note: `ref` is undocumented
def result = "${config.endpoint}/repos/$project/raw/$path"
if( revision )
result += "?ref=$revision"
result += "?ref=${URLEncoder.encode(revision, StandardCharsets.UTF_8)}"
return result
}

Expand Down Expand Up @@ -118,7 +121,7 @@ final class GiteaRepositoryProvider extends RepositoryProvider {
/** {@inheritDoc} */
@Override
List<RepositoryEntry> listDirectory(String path, int depth) {
final branch = revision ?: "master"
final branch = URLEncoder.encode(revision ?: "master", StandardCharsets.UTF_8)
// Normalize path using base class helper
final dirPath = normalizePath(path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import groovy.transform.Memoized
import groovy.util.logging.Slf4j
import nextflow.SysEnv

import java.nio.charset.StandardCharsets

/**
* Implements a repository provider for GitHub service
*
Expand Down Expand Up @@ -69,7 +71,7 @@ class GithubRepositoryProvider extends RepositoryProvider {
//
def result = "${config.endpoint}/repos/$project/contents/$path"
if( revision )
result += "?ref=$revision"
result += "?ref=${URLEncoder.encode(revision, StandardCharsets.UTF_8)}"
return result
}

Expand Down Expand Up @@ -205,7 +207,8 @@ class GithubRepositoryProvider extends RepositoryProvider {
if (revision) {
// Try to resolve the revision to a commit SHA
try {
Map ref = invokeAndParseResponse("${config.endpoint}/repos/$project/git/refs/heads/$revision")

Map ref = invokeAndParseResponse("${config.endpoint}/repos/$project/git/refs/heads/${URLEncoder.encode(revision, StandardCharsets.UTF_8)}")
Map object = ref.get('object') as Map
return object.get('sha') as String
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package nextflow.scm

import groovy.json.JsonSlurper
import groovy.util.logging.Slf4j

import java.nio.charset.StandardCharsets

/**
* Implements a repository provider for GitHub service
*
Expand Down Expand Up @@ -94,8 +97,8 @@ class GitlabRepositoryProvider extends RepositoryProvider {
// see
// https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
//
final ref = revision ?: getDefaultBranch()
final encodedPath = URLEncoder.encode(path.stripStart('/'),'utf-8')
final ref = URLEncoder.encode(revision ?: getDefaultBranch(), StandardCharsets.UTF_8)
final encodedPath = URLEncoder.encode(path.stripStart('/'), StandardCharsets.UTF_8)
return "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/files/${encodedPath}?ref=${ref}"
}

Expand Down Expand Up @@ -128,9 +131,9 @@ class GitlabRepositoryProvider extends RepositoryProvider {
/** {@inheritDoc} */
@Override
List<RepositoryEntry> listDirectory(String path, int depth) {
final ref = revision ?: getDefaultBranch()
final ref = URLEncoder.encode(revision ?: getDefaultBranch(),StandardCharsets.UTF_8)
final normalizedPath = normalizePath(path)
final encodedPath = normalizedPath ? URLEncoder.encode(normalizedPath, 'utf-8') : ""
final encodedPath = normalizedPath ? URLEncoder.encode(normalizedPath, StandardCharsets.UTF_8) : ""

// Build the Tree API URL
String url = "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/tree"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class AzureRepositoryProviderTest extends Specification {

expect:
new AzureRepositoryProvider('t-neumann/hello', obj).setRevision("a-branch").getContentUrl('main.nf') == 'https://dev.azure.com/t-neumann/hello/_apis/git/repositories/hello/items?download=false&includeContent=true&includeContentMetadata=false&api-version=6.0&\$format=json&path=main.nf&versionDescriptor.version=a-branch'
and:
new AzureRepositoryProvider('t-neumann/hello', obj).setRevision("test/branch+with&strangecharacters").getContentUrl('main.nf') == 'https://dev.azure.com/t-neumann/hello/_apis/git/repositories/hello/items?download=false&includeContent=true&includeContentMetadata=false&api-version=6.0&\$format=json&path=main.nf&versionDescriptor.version=test%2Fbranch%2Bwith%26strangecharacters'
}

/*
Expand All @@ -133,6 +135,8 @@ class AzureRepositoryProviderTest extends Specification {
def result = repo.readText('main.nf')
then:
result == 'println "Hello from Azure repos!"'


}

@IgnoreIf({System.getenv('NXF_SMOKE')})
Expand Down Expand Up @@ -226,6 +230,15 @@ class AzureRepositoryProviderTest extends Specification {
def result = repo.readText('file-on-dev.txt')
then:
result=='hello\n'

when:
// check revision with special branches
repo = new AzureRepositoryProvider('pditommaso/nf-azure-repo', config)
repo.revision = 'test/branch+with&special-chars'
result = repo.readText('main.nf')
then:
result == 'println "Hello from Azure repos!"'

}

@IgnoreIf({System.getenv('NXF_SMOKE')})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class BitbucketRepositoryProviderTest extends Specification {
.setRevision('test/tag/v2')
.getContentUrl('main.nf') == 'https://api.bitbucket.org/2.0/repositories/pditommaso/tutorial/src/8f849beceb2ea479ef836809ca33d3daeeed25f9/main.nf'

and:
new BitbucketRepositoryProvider('pditommaso/tutorial', config)
.setRevision('test/branch+with&special-chars')
.getContentUrl('main.nf') == 'https://api.bitbucket.org/2.0/repositories/pditommaso/tutorial/src/755ba829cbc4f28dcb3c16b9dcc1c49c7ee47ff5/main.nf'
}

@Requires( { System.getenv('NXF_BITBUCKET_ACCESS_TOKEN') } )
Expand Down Expand Up @@ -171,6 +175,14 @@ class BitbucketRepositoryProviderTest extends Specification {
then:
!data.contains('world')
data.contains('mundo')

when:
repo.setRevision('test/branch+with&special-chars')
and:
data = repo.readText('main.nf')
then:
data.contains('world')
!data.contains('WORLD')
}

@Unroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class BitbucketServerRepositoryProviderTest extends Specification {
new BitbucketServerRepositoryProvider('pditommaso/hello', obj)
.setRevision('foo')
.getContentUrl('main.nf') == 'https://bitbucket.server.com/rest/api/1.0/projects/pditommaso/repos/hello/raw/main.nf?at=foo'
and:
new BitbucketServerRepositoryProvider('pditommaso/hello', obj)
.setRevision('test/branch+with&strangecharacters')
.getContentUrl('main.nf') == 'https://bitbucket.server.com/rest/api/1.0/projects/pditommaso/repos/hello/raw/main.nf?at=test%2Fbranch%2Bwith%26strangecharacters'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class GiteaRepositoryProviderTest extends Specification {
new GiteaRepositoryProvider('pditommaso/hello', obj)
.setRevision('12345')
.getContentUrl('main.nf') == 'https://gitea.com/api/v1/repos/pditommaso/hello/raw/main.nf?ref=12345'

and:
new GiteaRepositoryProvider('pditommaso/hello', obj)
.setRevision('test/branch+with&strangecharacters')
.getContentUrl('main.nf') == 'https://gitea.com/api/v1/repos/pditommaso/hello/raw/main.nf?ref=test%2Fbranch%2Bwith%26strangecharacters'
}

@Unroll
Expand Down Expand Up @@ -92,6 +95,13 @@ class GiteaRepositoryProviderTest extends Specification {
// result = repo.readText('README.md')
// then:
// result.contains("foo branch")

when:
repo = new GiteaRepositoryProvider('pditommaso/test-hello', config)
repo.setRevision('test/branch+with&special-chars')
result = repo.readText('README.md')
then:
result.contains('Basic Nextflow script')
}

@IgnoreIf({System.getenv('NXF_SMOKE')})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class GithubRepositoryProviderTest extends Specification {
def result = repo.readText('main.nf')
then:
result.trim().startsWith('#!/usr/bin/env nextflow')

//Read from branch
when:
repo.setRevision('test/branch+with&strangecharacters')
result = repo.readText('/test/branch_name')
then:
result.trim().startsWith('test/branch+with&strangecharacters')

}

@Requires({System.getenv('NXF_GITHUB_ACCESS_TOKEN')})
Expand Down Expand Up @@ -95,6 +103,11 @@ class GithubRepositoryProviderTest extends Specification {
.setRevision('the-commit-id')
.getContentUrl('main.nf') == 'https://github.com/repos/pditommaso/hello/contents/main.nf?ref=the-commit-id'

and:
new GithubRepositoryProvider('pditommaso/hello', obj)
.setRevision('test/branch+with&strangecharacters')
.getContentUrl('main.nf') == 'https://github.com/repos/pditommaso/hello/contents/main.nf?ref=test%2Fbranch%2Bwith%26strangecharacters'

}

def 'should user github token as creds' () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class GitlabRepositoryProviderTest extends Specification {
def result = repo.readText('main.nf')
then:
result.trim().startsWith('#!/usr/bin/env nextflow')

when:
repo = new GitlabRepositoryProvider('pditommaso/hello', config)
repo.setRevision('test/branch+with&special-chars')
result = repo.readText('main.nf')
then:
result.trim().startsWith('#!/usr/bin/env nextflow')
}

@Requires({System.getenv('NXF_GITLAB_ACCESS_TOKEN')})
Expand Down Expand Up @@ -134,6 +141,11 @@ class GitlabRepositoryProviderTest extends Specification {
.setRevision('the-commit-id')
.getContentUrl('main.nf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/main.nf?ref=the-commit-id'

and:
new GitlabRepositoryProvider('pditommaso/hello', obj)
.setRevision('test/branch+with&strangecharacters')
.getContentUrl('main.nf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/main.nf?ref=test%2Fbranch%2Bwith%26strangecharacters'

and:
new GitlabRepositoryProvider('pditommaso/hello', obj)
.getContentUrl('conf/extra.conf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/conf%2Fextra.conf?ref=master'
Expand Down
Loading