From 333feeb200ced5246182208bc72944cd4e11ce85 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 24 Oct 2017 11:26:59 +0200 Subject: [PATCH] SONAR-9869 Fix project urls in webhook payload --- .../server/webhook/WebhookPayloadFactoryImpl.java | 4 ++-- .../webhook/WebhookPayloadFactoryImplTest.java | 12 ++++++------ .../org/sonarqube/tests/webhook/WebhooksTest.java | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java index f70e4683a8e..9f4c0ca5015 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java @@ -110,7 +110,7 @@ public class WebhookPayloadFactoryImpl implements WebhookPayloadFactory { } private String projectUrlOf(Project project) { - return format("%s/project/dashboard?id=%s", server.getPublicRootUrl(), encode(project.getKey())); + return format("%s/dashboard?id=%s", server.getPublicRootUrl(), encode(project.getKey())); } private String branchUrlOf(Project project, Branch branch) { @@ -118,7 +118,7 @@ public class WebhookPayloadFactoryImpl implements WebhookPayloadFactory { if (branch.isMain()) { return projectUrlOf(project); } - return format("%s/project/dashboard?branch=%s&id=%s", + return format("%s/dashboard?branch=%s&id=%s", server.getPublicRootUrl(), encode(branch.getName().orElse("")), encode(project.getKey())); } else { return format("%s/project/issues?branch=%s&id=%s&resolved=false", diff --git a/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java index d9239b774b0..05501d9e366 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java @@ -69,7 +69,7 @@ public class WebhookPayloadFactoryImplTest { " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + - " \"url\": \"http://foo/project/dashboard?id=P1\"" + + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + @@ -110,7 +110,7 @@ public class WebhookPayloadFactoryImplTest { " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + - " \"url\": \"http://foo/project/dashboard?id=P1\"" + + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + @@ -151,7 +151,7 @@ public class WebhookPayloadFactoryImplTest { " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + - " \"url\": \"http://foo/project/dashboard?id=P1\"" + + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + @@ -186,7 +186,7 @@ public class WebhookPayloadFactoryImplTest { " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + - " \"url\": \"http://foo/project/dashboard?id=P1\"" + + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"properties\": {" + " }" + @@ -266,7 +266,7 @@ public class WebhookPayloadFactoryImplTest { " \"name\": \"feature/foo\"" + " \"type\": \"LONG\"" + " \"isMain\": false," + - " \"url\": \"http://foo/project/dashboard?branch=feature%2Ffoo&id=P1\"" + + " \"url\": \"http://foo/dashboard?branch=feature%2Ffoo&id=P1\"" + "}" + "}"); } @@ -282,7 +282,7 @@ public class WebhookPayloadFactoryImplTest { "\"branch\": {" + " \"type\": \"LONG\"" + " \"isMain\": true," + - " \"url\": \"http://foo/project/dashboard?id=P1\"" + + " \"url\": \"http://foo/dashboard?id=P1\"" + "}" + "}"); } diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java index 2539ab6bb6d..16d2ec83f88 100644 --- a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java +++ b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java @@ -20,7 +20,6 @@ package org.sonarqube.tests.webhook; import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.Category3Suite; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -31,6 +30,7 @@ import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.sonarqube.tests.Category3Suite; import org.sonarqube.ws.Webhooks; import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.WsClient; @@ -107,6 +107,7 @@ public class WebhooksTest { Map project = (Map) payload.get("project"); assertThat(project.get("key")).isEqualTo(PROJECT_KEY); assertThat(project.get("name")).isEqualTo(PROJECT_NAME); + assertThat(project.get("url")).isEqualTo(orchestrator.getServer().getUrl() + "/dashboard?id=" + PROJECT_KEY); Map gate = (Map) payload.get("qualityGate"); assertThat(gate.get("name")).isEqualTo("SonarQube way"); assertThat(gate.get("status")).isEqualTo("OK"); -- 2.39.5