From: Eric Hartmann Date: Wed, 18 Oct 2017 15:38:47 +0000 (+0200) Subject: SONAR-9869 Fix changedAt value when a webhook is triggered from Web X-Git-Tag: 6.7-RC1~161 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f0f885748a2c1442690970de335c64fdd30791b4;p=sonarqube.git SONAR-9869 Fix changedAt value when a webhook is triggered from Web --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java b/server/sonar-server/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java index 432e23c55f4..6e94f505ce4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java +++ b/server/sonar-server/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java @@ -32,18 +32,18 @@ public class ProjectAnalysis { private final CeTask ceTask; private final Branch branch; private final QualityGate qualityGate; - private final Long date; + private final Long updatedAt; private final Map properties; private final Analysis analysis; public ProjectAnalysis(Project project, @Nullable CeTask ceTask, @Nullable Analysis analysis, - @Nullable Branch branch, @Nullable QualityGate qualityGate, @Nullable Long date, + @Nullable Branch branch, @Nullable QualityGate qualityGate, @Nullable Long updatedAt, Map properties) { this.project = requireNonNull(project, "project can't be null"); this.ceTask = ceTask; this.branch = branch; this.qualityGate = qualityGate; - this.date = date; + this.updatedAt = updatedAt; this.properties = copyOf(requireNonNull(properties, "properties can't be null")); this.analysis = analysis; } @@ -72,6 +72,10 @@ public class ProjectAnalysis { return Optional.ofNullable(analysis); } + public Optional getUpdatedAt() { + return Optional.ofNullable(updatedAt); + } + @Override public boolean equals(Object o) { if (this == o) { @@ -85,14 +89,14 @@ public class ProjectAnalysis { Objects.equals(ceTask, that.ceTask) && Objects.equals(branch, that.branch) && Objects.equals(qualityGate, that.qualityGate) && - Objects.equals(date, that.date) && + Objects.equals(updatedAt, that.updatedAt) && Objects.equals(properties, that.properties) && Objects.equals(analysis, that.analysis); } @Override public int hashCode() { - return Objects.hash(project, ceTask, branch, qualityGate, date, properties, analysis); + return Objects.hash(project, ceTask, branch, qualityGate, updatedAt, properties, analysis); } @Override @@ -102,7 +106,7 @@ public class ProjectAnalysis { ", ceTask=" + ceTask + ", branch=" + branch + ", qualityGate=" + qualityGate + - ", date=" + date + + ", updatedAt=" + updatedAt + ", properties=" + properties + ", analysis=" + analysis + '}'; 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 03a72052af7..f70e4683a8e 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 @@ -69,7 +69,7 @@ public class WebhookPayloadFactoryImpl implements WebhookPayloadFactory { private static void writeDates(JsonWriter writer, ProjectAnalysis analysis, System2 system2) { analysis.getAnalysis().ifPresent(a -> writer.propDateTime("analysedAt", a.getDate())); - writer.propDateTime("changedAt", analysis.getAnalysis().map(Analysis::getDate).orElseGet(() -> new Date(system2.now()))); + writer.propDateTime("changedAt", new Date(analysis.getUpdatedAt().orElse(system2.now()))); } private void writeProject(ProjectAnalysis analysis, JsonWriter writer, Project project) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java b/server/sonar-server/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java index aafce3fd808..45187a36b56 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java @@ -134,6 +134,6 @@ public class ProjectAnalysisTest { @Test public void verify_toString() { assertThat(underTest.toString()).isEqualTo( - "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=QualityGate{id='id', name='name', status=WARN, conditions=[]}, date=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}"); + "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=QualityGate{id='id', name='name', status=WARN, conditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}"); } }