]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9869 Fix changedAt value when a webhook is triggered from Web
authorEric Hartmann <hartmann.eric@gmail.com>
Wed, 18 Oct 2017 15:38:47 +0000 (17:38 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 19 Oct 2017 14:41:44 +0000 (16:41 +0200)
server/sonar-server/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java
server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java

index 432e23c55f43c9a7dd024362c93b4dce778c985f..6e94f505ce420797d66374d172db7c94262fb315 100644 (file)
@@ -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<String, String> 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<String, String> 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<Long> 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 +
       '}';
index 03a72052af7cc1844bb155be5160abf753e415c1..f70e4683a8ec518a7eabcb7c976220ff9d34a03f 100644 (file)
@@ -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) {
index aafce3fd808d1ae73d7a8d43e4d60db10ca81fe3..45187a36b5607087eb65ae6c7f3c1459fb470053 100644 (file)
@@ -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}}");
   }
 }