Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-28877] remove /scm before GitStatus.looselyMatches to match …
…ssh and https URI in Bitbucket Server
  • Loading branch information
Frieder Rick committed Dec 6, 2017
1 parent 1d65669 commit 362bf39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -88,6 +88,11 @@ private boolean match(SCM scm, URIish url) {
if (scm instanceof GitSCM) {
for (RemoteConfig remoteConfig : ((GitSCM) scm).getRepositories()) {
for (URIish urIish : remoteConfig.getURIs()) {
// needed cause the ssh and https URI differs in Bitbucket Server.

This comment has been minimized.

Copy link
@pghaemi

pghaemi Feb 16, 2018

This doesn't work when the bitbucket server base url is somethinglike https:/myserver.com/bitbucket.The plugin cannot find a match becuase of a missing /scm.

if(urIish.getPath().startsWith("/scm")){
urIish = urIish.setPath(urIish.getPath().substring(4));
}
LOGGER.log(Level.FINE, "Trying to match {0} ", urIish.toString() + "<-->" + url.toString());
if (GitStatus.looselyMatches(urIish, url)) {
return true;
}
Expand Down
Expand Up @@ -73,11 +73,7 @@ private void processWebhookPayloadBitBucketServer(JSONObject payload) {
if (repo.getJSONObject("links").getJSONArray("self").size() != 0) {
try {
URL pushHref = new URL(repo.getJSONObject("links").getJSONArray("self").getJSONObject(0).getString("href"));
if (pushHref.getProtocol().equals("https")) {
url = pushHref.toString().replaceFirst(new String("projects.*"), new String("scm/" + repo.getString("fullName").toLowerCase()));
} else {
url = pushHref.toString().replaceFirst(new String("projects.*"), new String(repo.getString("fullName").toLowerCase()));
}
url = pushHref.toString().replaceFirst(new String("projects.*"), new String(repo.getString("fullName").toLowerCase()));
String scm = repo.has("scmId") ? repo.getString("scmId") : "git";
probe.triggerMatchingJobs(user, url, scm, payload.toString());
} catch (MalformedURLException e) {
Expand Down
Expand Up @@ -63,16 +63,16 @@ public void testProcessWebhookPayload() {

@Test
public void processWebhookPayloadBitBucketServer() {
// Set headers so that payload processor will parse as new Webhook payload
when(request.getHeader("user-agent")).thenReturn("Apache-HttpClient/4.5.1 (Java/1.8.0_102)");
when(request.getHeader("x-event-key")).thenReturn("repo:push");

String user = "test_user";
String url = "https://bitbucket.org/scm/ce/test_repo";
String url = "https://bitbucket.org/ce/test_repo";

JSONObject href = new JSONObject();
href.element("href", "https://bitbucket.org/projects/CE/repos/test_repo/browse");

// Set actor and repository so that payload processor will parse as Bitbucket Server Post Webhook payload
JSONObject payload = new JSONObject()
.element("actor", new JSONObject()
.element("username", user))
Expand Down

0 comments on commit 362bf39

Please sign in to comment.