Skip to content

Commit

Permalink
Fix azure repos when clone URL is used (#5667) [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: jorgee <[email protected]>
Signed-off-by: Jorge Ejarque <[email protected]>
Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
jorgee and pditommaso committed Jan 20, 2025
1 parent 6183fdf commit eb092c9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,38 @@ final class AzureRepositoryProvider extends RepositoryProvider {
private String continuationToken

AzureRepositoryProvider(String project, ProviderConfig config=null) {
/*
Azure repo format follows Organization/Project/Repository where Project can be optional
If Project is not present then Repository is used as Project (and also as Repository)
*/
this.urlPath = project
def tokens = project.tokenize('/')
def tokens = getUniformPath(project)
this.repo = tokens.removeLast()
if( tokens.size() == 1){
this.project = [tokens.first(), this.repo].join('/')
}else{
this.project = tokens.join('/')
}
this.project = tokens.join('/')
this.config = config ?: new ProviderConfig('azurerepos')
this.continuationToken = null
}

/**
* An Azure repo is identified with the Organization/Project/Repository parameters.
* This function gets these parameters for the different URL path formats supported in Nextflow for Azure repositories.
*
* @param urlPath Path of the Azure repo URL
* @return List with the azure repo parameters with the following order [ Organization, Project, Repository ]
*/
static List<String> getUniformPath(String urlPath){
def tokens = urlPath.tokenize('/')
if( tokens.size() == 2 ){
// URL is just organization/project. project and repo are the same.
return [tokens[0], tokens[1], tokens[1]]
}
if( tokens.size() == 3 ){
// URL is as expected organization/project/repository.
return tokens
}
if( tokens.size() == 4 && tokens[2] == '_git' ){
// Clone URL organization/project/_git/repository
return [tokens[0], tokens[1], tokens[3]]
}
throw new IllegalArgumentException("Unexpected Azure repository path format - offending value: '$urlPath'")
}

/** {@inheritDoc} */
@Override
String getName() { "Azure Repos" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ class ProviderConfig {
}

if( server == 'https://dev.azure.com' ) {
final parts = project.tokenize('/')
if( parts[2]=='_git' )
project = "${parts[0]}/${parts[1]}"
project = AzureRepositoryProvider.getUniformPath(project).join('/')
}

return project.stripStart('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,61 @@ class AzureRepositoryProviderTest extends Specification {
}
'''

def 'should return repo url' () {
def 'should parse repo fields from path' () {
expect:
AzureRepositoryProvider.getUniformPath(PATH) == EXPECTED

given:
def config = new ConfigSlurper().parse(CONFIG)
def obj = new ProviderConfig('azurerepos', config.providers.azurerepos as ConfigObject)
where:
PATH | EXPECTED
't-neumann/hello' | ['t-neumann', 'hello', 'hello']
'ORGANIZATION/PROJECT/hello' | ['ORGANIZATION','PROJECT','hello']
'ORGANIZATION/PROJECT/_git/hello' | ['ORGANIZATION','PROJECT','hello']

expect:
new AzureRepositoryProvider('t-neumann/hello', obj).getEndpointUrl() == 'https://dev.azure.com/t-neumann/hello/_apis/git/repositories/hello'
}

def 'should return repo with organization url' () {
def 'should throw exception if wrong path' () {
when:
def path = AzureRepositoryProvider.getUniformPath(PATH)

given:
def config = new ConfigSlurper().parse(CONFIG)
def obj = new ProviderConfig('azurerepos', config.providers.azurerepos as ConfigObject)
then :
def exception = thrown(IllegalArgumentException)
exception?.message == EXCEPTION

expect:
new AzureRepositoryProvider('ORGANIZATION/PROJECT/hello', obj).getEndpointUrl() == 'https://dev.azure.com/ORGANIZATION/PROJECT/_apis/git/repositories/hello'
where:
PATH | EXCEPTION
'incorrect_path_1' | "Unexpected Azure repository path format - offending value: 'incorrect_path_1'"
'ORG/PROJ/hello/incorrect' | "Unexpected Azure repository path format - offending value: 'ORG/PROJ/hello/incorrect'"
}

def 'should return project URL' () {
def 'should return repo url' () {

given:
def config = new ConfigSlurper().parse(CONFIG)
def obj = new ProviderConfig('azurerepos', config.providers.azurerepos as ConfigObject)

expect:
new AzureRepositoryProvider('t-neumann/hello', obj).getRepositoryUrl() == 'https://dev.azure.com/t-neumann/hello'
new AzureRepositoryProvider(PATH, obj).getEndpointUrl() == EXPECTED

where:
PATH | EXPECTED
't-neumann/hello' | 'https://dev.azure.com/t-neumann/hello/_apis/git/repositories/hello'
'ORGANIZATION/PROJECT/hello' | 'https://dev.azure.com/ORGANIZATION/PROJECT/_apis/git/repositories/hello'
'ORGANIZATION/PROJECT/_git/hello' | 'https://dev.azure.com/ORGANIZATION/PROJECT/_apis/git/repositories/hello'
}

def 'should return project with organization URL' () {
def 'should return project URL' () {

given:
def config = new ConfigSlurper().parse(CONFIG)
def obj = new ProviderConfig('azurerepos', config.providers.azurerepos as ConfigObject)

expect:
new AzureRepositoryProvider('ORGANIZATION/PROJECT/hello', obj).getRepositoryUrl() == 'https://dev.azure.com/ORGANIZATION/PROJECT/hello'
new AzureRepositoryProvider(PATH, obj).getRepositoryUrl() == EXPECTED
where:
PATH | EXPECTED
't-neumann/hello' | 'https://dev.azure.com/t-neumann/hello'
'ORGANIZATION/PROJECT/hello' | 'https://dev.azure.com/ORGANIZATION/PROJECT/hello'
'ORGANIZATION/PROJECT/_git/hello' | 'https://dev.azure.com/ORGANIZATION/PROJECT/_git/hello'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ class ProviderConfigTest extends Specification {
'a/b/c' | 'http://dot.com/a' | 'b/c'
'a/b/c' | 'http://dot.com/a/' | 'b/c'
and:
'paolo0758/nf-azure-repo' | 'https://dev.azure.com' | 'paolo0758/nf-azure-repo'
'paolo0758/nf-azure-repo/_git/nf-azure-repo' | 'https://dev.azure.com' | 'paolo0758/nf-azure-repo'
'paolo0758/nf-azure-repo' | 'https://dev.azure.com' | 'paolo0758/nf-azure-repo/nf-azure-repo'
'paolo0758/nf-azure-repo/_git/nf-azure-repo' | 'https://dev.azure.com' | 'paolo0758/nf-azure-repo/nf-azure-repo'
'paolo0758/nf-azure-repo/_git/another-azure-repo' | 'https://dev.azure.com' | 'paolo0758/nf-azure-repo/another-azure-repo'
}

}

0 comments on commit eb092c9

Please sign in to comment.