Skip to content

Commit 7b531f0

Browse files
committed
fixup! respect Bitbucket Server urls with branch in format /refs/heads/<branchname>
1 parent e4e21e5 commit 7b531f0

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ private BitbucketServerUrl parse(Matcher matcher, @Nullable String revision) {
228228
String branchFromUrl = null;
229229
try {
230230
String branch = matcher.group("branch");
231-
branchFromUrl = branch.startsWith("refs/heads/") ? branch.substring(11) : branch;
231+
branchFromUrl =
232+
branch.startsWith("refs/heads/")
233+
? branch.substring(11)
234+
: (branch.startsWith("refs%2Fheads%2F") ? branch.substring(15) : branch);
232235
} catch (IllegalArgumentException e) {
233236
// keep branch with null, as the pattern doesn't have the branch group
234237
}

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParserTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ public void shouldParseWithBranch() {
7878
assertEquals(bitbucketServerUrl.getBranch(), "branch");
7979
}
8080

81-
@Test
82-
public void shouldParseWithBranch1() {
83-
BitbucketServerUrl bitbucketServerUrl =
84-
bitbucketURLParser.parse(
85-
"https://bitbucket.2mcl.com/users/user/repos/repo/browse?at=refs/heads/branch", null);
86-
assertEquals(bitbucketServerUrl.getBranch(), "branch");
87-
}
88-
8981
@Test
9082
public void shouldParseWithUrlBranch() {
9183
BitbucketServerUrl bitbucketServerUrl =
@@ -256,14 +248,21 @@ public Object[][] expectedParsing() {
256248
null,
257249
"project",
258250
"test1",
259-
"refs%2Fheads%2Fbranch"
251+
"branch"
260252
},
261253
{
262254
"https://bbkt.com/projects/project/repos/test1/browse?at=refs%2Fheads%2Fbranch",
263255
null,
264256
"project",
265257
"test1",
266-
"refs%2Fheads%2Fbranch"
258+
"branch"
259+
},
260+
{
261+
"https://bitbucket.2mcl.com/users/user/repos/repo/browse?at=refs/heads/branch",
262+
"user",
263+
null,
264+
"repo",
265+
"branch"
267266
},
268267
{"https://bbkt.com/users/user/repos/repo/", "user", null, "repo", null}
269268
};

0 commit comments

Comments
 (0)