Skip to content

Commit

Permalink
Properly handle value "https" in clone link name (#806)
Browse files Browse the repository at this point in the history
In Bitbucket Server "http" is used as http link name,
but in Bitbucket Cloud "https" is used.

Bug was introduced in #796. Fixes #804.
  • Loading branch information
andrey-fomin committed Feb 12, 2024
1 parent 28d74e8 commit b8fa891
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void withMirrorRemote() {

private String getCloneLink(List<BitbucketHref> cloneLinks) {
return cloneLinks.stream()
.filter(link -> protocol.getType().equals(link.getName()))
.filter(link -> protocol.matches(link.getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("Can't find clone link for protocol " + protocol))
.getHref();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.api;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;

public enum BitbucketRepositoryProtocol {
Expand All @@ -44,18 +43,16 @@ public enum BitbucketRepositoryProtocol {
this.type = type;
}

public String getType() {
return type;
/**
* Check if link name matches protocol.
* In Bitbucket Server "http" and "ssh" are used as link names.
* In Bitbucket Cloud "https" and "ssh" are used.
*
* @param linkName link name to check
* @return if link name matches
*/
public boolean matches(@NonNull String linkName) {
return linkName.startsWith(type);
}

@CheckForNull
public static BitbucketRepositoryProtocol fromString(String type) {
if (SSH.type.equals(type)) {
return SSH;
} else if (HTTP.type.equals(type)) {
return HTTP;
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void given__cloud_branch_rev_anon__when__build__then__scmBuilt() throws E

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -153,7 +153,7 @@ public void given__cloud_branch_rev_userpass__when__build__then__scmBuilt() thro

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -213,7 +213,7 @@ public void given__cloud_branch_rev_userkey__when__build__then__scmBuilt() throw

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -271,7 +271,7 @@ public void given__cloud_branch_norev_anon__when__build__then__scmBuilt() throws

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -317,7 +317,7 @@ public void given__cloud_branch_norev_userpass__when__build__then__scmBuilt() th

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -363,7 +363,7 @@ public void given__cloud_branch_norev_userkey__when__build__then__scmBuilt() thr

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -915,7 +915,7 @@ public void given__cloud_pullHead_rev_anon__when__build__then__scmBuilt() throws

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -979,7 +979,7 @@ public void given__cloud_pullHead_rev_userpass__when__build__then__scmBuilt() th

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1042,7 +1042,7 @@ public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() thr

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public void given__cloud_pullHead_rev_anon_sshtrait_anon__when__build__then__scm

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1176,7 +1176,7 @@ public void given__cloud_pullHead_rev_userpass_sshtrait_anon__when__build__then_

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1246,7 +1246,7 @@ public void given__cloud_pullHead_rev_userkey_sshtrait_anon__when__build__then__

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1316,7 +1316,7 @@ public void given__cloud_pullHead_rev_anon_sshtrait_userkey__when__build__then__

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1386,7 +1386,7 @@ public void given__cloud_pullHead_rev_userpass_sshtrait_userkey__when__build__th

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1456,7 +1456,7 @@ public void given__cloud_pullHead_rev_userkey_sshtrait_userkey__when__build__the

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1522,7 +1522,7 @@ public void given__cloud_pullHead_norev_anon__when__build__then__scmBuilt() thro

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1570,7 +1570,7 @@ public void given__cloud_pullHead_norev_userpass__when__build__then__scmBuilt()

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -1618,7 +1618,7 @@ public void given__cloud_pullHead_norev_userkey__when__build__then__scmBuilt() t

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -2484,7 +2484,7 @@ public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throw

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -2568,7 +2568,7 @@ public void given__cloud_pullMerge_rev_userpass__when__build__then__scmBuilt() t

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -2652,7 +2652,7 @@ public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() th

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -2732,7 +2732,7 @@ public void given__cloud_pullMerge_norev_anon__when__build__then__scmBuilt() thr

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down Expand Up @@ -2800,7 +2800,7 @@ public void given__cloud_pullMerge_norev_userpass__when__build__then__scmBuilt()

instance.withCloneLinks(
List.of(
new BitbucketHref("http", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
),
List.of()
Expand Down

0 comments on commit b8fa891

Please sign in to comment.