Skip to content

Commit 9d8943e

Browse files
authored
Add token support for BitBucket, Gitea and Gitlab repository providers (#6212)
1 parent 1557a91 commit 9d8943e

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class BitbucketRepositoryProvider extends RepositoryProvider {
4848

4949
@Override
5050
boolean hasCredentials() {
51-
return config.token
51+
return getToken()
5252
? true
5353
: super.hasCredentials()
5454
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ final class GiteaRepositoryProvider extends RepositoryProvider {
5353
return null
5454
}
5555

56+
@Override
57+
boolean hasCredentials() {
58+
return getToken()
59+
? true
60+
: super.hasCredentials()
61+
}
62+
5663
@Override
5764
@CompileDynamic
5865
List<BranchInfo> getBranches() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class GitlabRepositoryProvider extends RepositoryProvider {
5050
return null
5151
}
5252

53+
@Override
54+
boolean hasCredentials() {
55+
return getToken()
56+
? true
57+
: super.hasCredentials()
58+
}
59+
5360
@Override
5461
String getName() { "GitLab" }
5562

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ abstract class RepositoryProvider {
133133

134134
String getPassword() { config?.password }
135135

136+
String getToken() { config?.token }
137+
136138
/**
137139
* @return The name of the source hub service e.g. github or bitbucket
138140
*/

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package nextflow.scm
1919
import spock.lang.IgnoreIf
2020
import spock.lang.Requires
2121
import spock.lang.Specification
22+
import spock.lang.Unroll
23+
2224
/**
2325
*
2426
* @author Akira Sekiguchi <[email protected]>
@@ -68,6 +70,22 @@ class GiteaRepositoryProviderTest extends Specification {
6870

6971
}
7072

73+
@Unroll
74+
def 'should validate hasCredentials' () {
75+
given:
76+
def provider = new GiteaRepositoryProvider('pditommaso/tutorial', PROVIDER_CONFIG)
77+
78+
expect:
79+
provider.hasCredentials() == EXPECTED
80+
81+
where:
82+
EXPECTED | PROVIDER_CONFIG
83+
false | new ProviderConfig('gitea')
84+
false | new ProviderConfig('gitea').setUser('foo')
85+
true | new ProviderConfig('gitea').setUser('foo').setPassword('bar')
86+
true | new ProviderConfig('gitea').setToken('xyz')
87+
}
88+
7189
@IgnoreIf({System.getenv('NXF_SMOKE')})
7290
@Requires({System.getenv('NXF_GITEA_ACCESS_TOKEN')})
7391
def 'should read file content'() {

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

Lines changed: 17 additions & 0 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
*
@@ -37,6 +38,22 @@ class GitlabRepositoryProviderTest extends Specification {
3738
new GitlabRepositoryProvider('pditommaso/hello').getRepositoryUrl() == 'https://gitlab.com/pditommaso/hello'
3839
}
3940

41+
@Unroll
42+
def 'should validate hasCredentials' () {
43+
given:
44+
def provider = new GitlabRepositoryProvider('pditommaso/tutorial', CONFIG)
45+
46+
expect:
47+
provider.hasCredentials() == EXPECTED
48+
49+
where:
50+
EXPECTED | CONFIG
51+
false | new ProviderConfig('gitlab')
52+
false | new ProviderConfig('gitlab').setUser('foo')
53+
true | new ProviderConfig('gitlab').setUser('foo').setPassword('bar')
54+
true | new ProviderConfig('gitlab').setToken('xyz')
55+
}
56+
4057
@Requires({System.getenv('NXF_GITLAB_ACCESS_TOKEN')})
4158
def 'should return clone url'() {
4259
given:

0 commit comments

Comments
 (0)