Skip to content

Commit

Permalink
Merge pull request #55 from entfrickler/sshgit
Browse files Browse the repository at this point in the history
[FIXED JENKINS-28877] remove /scm before GitStatus.looselyMatches to match …
  • Loading branch information
fbelzunc committed Dec 6, 2017
2 parents 1d65669 + 362bf39 commit 0316730
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.
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

1 comment on commit 0316730

@airadier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fbelzunc,

this fix works as long as bitbucket is on the root of the webserver. In our setup, we have bitbucket at /bitbucket, so the URL for the repository is like /bitbucket/**scm/project/repo.git

Is it possible to remove /scm part in the path? I guess if the componentes are always like:

/path/to/bitbucket/root/scm/project/repo.git

It could be checked if the component at [len - 2] == scm, then remove that component.

Regards.

Please sign in to comment.