Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -39,23 +39,36 @@ final class BitbucketRepositoryProvider extends RepositoryProvider {
this.config = config ?: new ProviderConfig('bitbucket')
}

/** {@inheritDoc} */
@Override
protected String[] getAuth() {
if (config.user && config.password) {
return super.getAuth()
}

if (config.token) {
return new String[] { "Authorization", "Bearer ${config.token}" }
}

return null
}

/** {@inheritDoc} */
@Override
String getName() { "BitBucket" }

@Override
String getEndpointUrl() {
"${config.endpoint}/api/2.0/repositories/${project}"
"${config.endpoint}/2.0/repositories/${project}"
}

@Override
String getContentUrl( String path ) {
final ref = revision ? getRefForRevision(revision) : getMainBranch()
return "${config.endpoint}/api/2.0/repositories/$project/src/$ref/$path"
return "${config.endpoint}/2.0/repositories/$project/src/$ref/$path"
}

private String getMainBranchUrl() {
"${config.endpoint}/api/2.0/repositories/$project"
"${config.endpoint}/2.0/repositories/$project"
}

String getMainBranch() {
Expand Down Expand Up @@ -87,7 +100,7 @@ final class BitbucketRepositoryProvider extends RepositoryProvider {
}

private String getRefForRevision0(String revision, String type){
final resp = invokeAndParseResponse("${config.endpoint}/api/2.0/repositories/$project/refs/$type/$revision")
final resp = invokeAndParseResponse("${config.endpoint}/2.0/repositories/$project/refs/$type/$revision")
return resp?.target?.hash
}

Expand Down Expand Up @@ -117,7 +130,7 @@ final class BitbucketRepositoryProvider extends RepositoryProvider {
@Override
List<TagInfo> getTags() {
final result = new ArrayList<TagInfo>()
final url = "$config.endpoint/api/2.0/repositories/$project/refs/tags"
final url = "$config.endpoint/2.0/repositories/$project/refs/tags"
final mapper = { Map entry -> result.add( new TagInfo(entry.name, entry.target?.hash) ) }
invokeAndResponseWithPaging(url, mapper)
return result
Expand All @@ -131,7 +144,7 @@ final class BitbucketRepositoryProvider extends RepositoryProvider {
@Override
List<BranchInfo> getBranches() {
final result = new ArrayList<BranchInfo>()
final url = "$config.endpoint/api/2.0/repositories/$project/refs/branches"
final url = "$config.endpoint/2.0/repositories/$project/refs/branches"
final mapper = { Map entry -> result.add( new BranchInfo(entry.name, entry.target?.hash) ) }
invokeAndResponseWithPaging(url, mapper)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ProviderConfig {
case 'bitbucket':
attr.platform = name
if( !attr.server ) attr.server = 'https://bitbucket.org'
if( !attr.endpoint ) attr.endpoint = 'https://api.bitbucket.org'
break

case 'azurerepos':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BitbucketRepositoryProviderTest extends Specification {
when:
def url = new BitbucketRepositoryProvider('pditommaso/tutorial',config).getCloneUrl()
then:
url == "https://${config.user}@bitbucket.org/pditommaso/tutorial.git".toString()
url ==~ /https:\/\/\w+@bitbucket.org\/pditommaso\/tutorial.git/
}


Expand Down Expand Up @@ -100,17 +100,17 @@ class BitbucketRepositoryProviderTest extends Specification {
expect:
new BitbucketRepositoryProvider('pditommaso/tutorial', config)
.setRevision('test-branch')
.getContentUrl('main.nf') == 'https://bitbucket.org/api/2.0/repositories/pditommaso/tutorial/src/test-branch/main.nf'
.getContentUrl('main.nf') == 'https://api.bitbucket.org/2.0/repositories/pditommaso/tutorial/src/test-branch/main.nf'

and:
new BitbucketRepositoryProvider('pditommaso/tutorial', config)
.setRevision('feature/with-slash')
.getContentUrl('main.nf') == 'https://bitbucket.org/api/2.0/repositories/pditommaso/tutorial/src/a6b825b22d46758cdeb496ae6cf26aef839ace52/main.nf'
.getContentUrl('main.nf') == 'https://api.bitbucket.org/2.0/repositories/pditommaso/tutorial/src/a6b825b22d46758cdeb496ae6cf26aef839ace52/main.nf'

and:
new BitbucketRepositoryProvider('pditommaso/tutorial', config)
.setRevision('test/tag/v2')
.getContentUrl('main.nf') == 'https://bitbucket.org/api/2.0/repositories/pditommaso/tutorial/src/8f849beceb2ea479ef836809ca33d3daeeed25f9/main.nf'
.getContentUrl('main.nf') == 'https://api.bitbucket.org/2.0/repositories/pditommaso/tutorial/src/8f849beceb2ea479ef836809ca33d3daeeed25f9/main.nf'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ProviderConfigTest extends Specification {
then:
config.name == 'bitbucket'
config.server == 'https://bitbucket.org'
config.endpoint == 'https://bitbucket.org'
config.endpoint == 'https://api.bitbucket.org'
config.platform == 'bitbucket'
config.domain == 'bitbucket.org'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RepositoryProviderTest extends Specification {
provider = RepositoryFactory.newRepositoryProvider(new ProviderConfig('bitbucket'),'project/z')
then:
provider instanceof BitbucketRepositoryProvider
provider.endpointUrl == 'https://bitbucket.org/api/2.0/repositories/project/z'
provider.endpointUrl == 'https://api.bitbucket.org/2.0/repositories/project/z'

when:
provider = RepositoryFactory.newRepositoryProvider(new ProviderConfig('local', [path:'/user/data']),'local/w')
Expand Down