Skip to content

Commit b8fa891

Browse files
authored
Properly handle value "https" in clone link name (#806)
In Bitbucket Server "http" is used as http link name, but in Bitbucket Cloud "https" is used. Bug was introduced in #796. Fixes #804.
1 parent 28d74e8 commit b8fa891

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private void withMirrorRemote() {
308308

309309
private String getCloneLink(List<BitbucketHref> cloneLinks) {
310310
return cloneLinks.stream()
311-
.filter(link -> protocol.getType().equals(link.getName()))
311+
.filter(link -> protocol.matches(link.getName()))
312312
.findAny()
313313
.orElseThrow(() -> new IllegalStateException("Can't find clone link for protocol " + protocol))
314314
.getHref();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/BitbucketRepositoryProtocol.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
package com.cloudbees.jenkins.plugins.bitbucket.api;
2525

26-
import edu.umd.cs.findbugs.annotations.CheckForNull;
2726
import edu.umd.cs.findbugs.annotations.NonNull;
2827

2928
public enum BitbucketRepositoryProtocol {
@@ -44,18 +43,16 @@ public enum BitbucketRepositoryProtocol {
4443
this.type = type;
4544
}
4645

47-
public String getType() {
48-
return type;
46+
/**
47+
* Check if link name matches protocol.
48+
* In Bitbucket Server "http" and "ssh" are used as link names.
49+
* In Bitbucket Cloud "https" and "ssh" are used.
50+
*
51+
* @param linkName link name to check
52+
* @return if link name matches
53+
*/
54+
public boolean matches(@NonNull String linkName) {
55+
return linkName.startsWith(type);
4956
}
5057

51-
@CheckForNull
52-
public static BitbucketRepositoryProtocol fromString(String type) {
53-
if (SSH.type.equals(type)) {
54-
return SSH;
55-
} else if (HTTP.type.equals(type)) {
56-
return HTTP;
57-
} else {
58-
return null;
59-
}
60-
}
6158
}

src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilderTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void given__cloud_branch_rev_anon__when__build__then__scmBuilt() throws E
9393

9494
instance.withCloneLinks(
9595
List.of(
96-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
96+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
9797
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
9898
),
9999
List.of()
@@ -153,7 +153,7 @@ public void given__cloud_branch_rev_userpass__when__build__then__scmBuilt() thro
153153

154154
instance.withCloneLinks(
155155
List.of(
156-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
156+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
157157
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
158158
),
159159
List.of()
@@ -213,7 +213,7 @@ public void given__cloud_branch_rev_userkey__when__build__then__scmBuilt() throw
213213

214214
instance.withCloneLinks(
215215
List.of(
216-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
216+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
217217
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
218218
),
219219
List.of()
@@ -271,7 +271,7 @@ public void given__cloud_branch_norev_anon__when__build__then__scmBuilt() throws
271271

272272
instance.withCloneLinks(
273273
List.of(
274-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
274+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
275275
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
276276
),
277277
List.of()
@@ -317,7 +317,7 @@ public void given__cloud_branch_norev_userpass__when__build__then__scmBuilt() th
317317

318318
instance.withCloneLinks(
319319
List.of(
320-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
320+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
321321
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
322322
),
323323
List.of()
@@ -363,7 +363,7 @@ public void given__cloud_branch_norev_userkey__when__build__then__scmBuilt() thr
363363

364364
instance.withCloneLinks(
365365
List.of(
366-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
366+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
367367
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
368368
),
369369
List.of()
@@ -915,7 +915,7 @@ public void given__cloud_pullHead_rev_anon__when__build__then__scmBuilt() throws
915915

916916
instance.withCloneLinks(
917917
List.of(
918-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
918+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
919919
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
920920
),
921921
List.of()
@@ -979,7 +979,7 @@ public void given__cloud_pullHead_rev_userpass__when__build__then__scmBuilt() th
979979

980980
instance.withCloneLinks(
981981
List.of(
982-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
982+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
983983
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
984984
),
985985
List.of()
@@ -1042,7 +1042,7 @@ public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() thr
10421042

10431043
instance.withCloneLinks(
10441044
List.of(
1045-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1045+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
10461046
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
10471047
),
10481048
List.of()
@@ -1106,7 +1106,7 @@ public void given__cloud_pullHead_rev_anon_sshtrait_anon__when__build__then__scm
11061106

11071107
instance.withCloneLinks(
11081108
List.of(
1109-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1109+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
11101110
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
11111111
),
11121112
List.of()
@@ -1176,7 +1176,7 @@ public void given__cloud_pullHead_rev_userpass_sshtrait_anon__when__build__then_
11761176

11771177
instance.withCloneLinks(
11781178
List.of(
1179-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1179+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
11801180
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
11811181
),
11821182
List.of()
@@ -1246,7 +1246,7 @@ public void given__cloud_pullHead_rev_userkey_sshtrait_anon__when__build__then__
12461246

12471247
instance.withCloneLinks(
12481248
List.of(
1249-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1249+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
12501250
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
12511251
),
12521252
List.of()
@@ -1316,7 +1316,7 @@ public void given__cloud_pullHead_rev_anon_sshtrait_userkey__when__build__then__
13161316

13171317
instance.withCloneLinks(
13181318
List.of(
1319-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1319+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
13201320
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
13211321
),
13221322
List.of()
@@ -1386,7 +1386,7 @@ public void given__cloud_pullHead_rev_userpass_sshtrait_userkey__when__build__th
13861386

13871387
instance.withCloneLinks(
13881388
List.of(
1389-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1389+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
13901390
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
13911391
),
13921392
List.of()
@@ -1456,7 +1456,7 @@ public void given__cloud_pullHead_rev_userkey_sshtrait_userkey__when__build__the
14561456

14571457
instance.withCloneLinks(
14581458
List.of(
1459-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1459+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
14601460
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
14611461
),
14621462
List.of()
@@ -1522,7 +1522,7 @@ public void given__cloud_pullHead_norev_anon__when__build__then__scmBuilt() thro
15221522

15231523
instance.withCloneLinks(
15241524
List.of(
1525-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1525+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
15261526
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
15271527
),
15281528
List.of()
@@ -1570,7 +1570,7 @@ public void given__cloud_pullHead_norev_userpass__when__build__then__scmBuilt()
15701570

15711571
instance.withCloneLinks(
15721572
List.of(
1573-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1573+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
15741574
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
15751575
),
15761576
List.of()
@@ -1618,7 +1618,7 @@ public void given__cloud_pullHead_norev_userkey__when__build__then__scmBuilt() t
16181618

16191619
instance.withCloneLinks(
16201620
List.of(
1621-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
1621+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
16221622
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
16231623
),
16241624
List.of()
@@ -2484,7 +2484,7 @@ public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throw
24842484

24852485
instance.withCloneLinks(
24862486
List.of(
2487-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
2487+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
24882488
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
24892489
),
24902490
List.of()
@@ -2568,7 +2568,7 @@ public void given__cloud_pullMerge_rev_userpass__when__build__then__scmBuilt() t
25682568

25692569
instance.withCloneLinks(
25702570
List.of(
2571-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
2571+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
25722572
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
25732573
),
25742574
List.of()
@@ -2652,7 +2652,7 @@ public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() th
26522652

26532653
instance.withCloneLinks(
26542654
List.of(
2655-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
2655+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
26562656
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
26572657
),
26582658
List.of()
@@ -2732,7 +2732,7 @@ public void given__cloud_pullMerge_norev_anon__when__build__then__scmBuilt() thr
27322732

27332733
instance.withCloneLinks(
27342734
List.of(
2735-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
2735+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
27362736
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
27372737
),
27382738
List.of()
@@ -2800,7 +2800,7 @@ public void given__cloud_pullMerge_norev_userpass__when__build__then__scmBuilt()
28002800

28012801
instance.withCloneLinks(
28022802
List.of(
2803-
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
2803+
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
28042804
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
28052805
),
28062806
List.of()

0 commit comments

Comments
 (0)