]> source.dussan.org Git - sonarqube.git/commitdiff
NO JIRA - Adding updatedAt field in WebAPI rules/search
authorzhengzexiang <zhengzexiang@meituan.com>
Thu, 15 Jun 2023 13:46:15 +0000 (21:46 +0800)
committersonartech <sonartech@sonarsource.com>
Tue, 27 Jun 2023 20:02:45 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
sonar-ws/src/main/protobuf/ws-rules.proto

index 01272609db2b1cb088c45f0a996237b498387f81..a455433994d82d7b39b9d378ec71c2cad1378d82 100644 (file)
@@ -312,6 +312,7 @@ public class SearchActionIT {
     Rules.SearchResponse response = ws.newRequest().executeProtobuf(Rules.SearchResponse.class);
     Rules.Rule result = response.getRules(0);
     assertThat(result.getCreatedAt()).isNotEmpty();
+    assertThat(result.getUpdatedAt()).isNotEmpty();
     assertThat(result.getGapDescription()).isNotEmpty();
     assertThat(result.getHtmlDesc()).isNotEmpty();
     assertThat(result.hasIsTemplate()).isTrue();
@@ -350,6 +351,7 @@ public class SearchActionIT {
     assertThat(result.hasName()).isFalse();
     assertThat(result.hasSeverity()).isFalse();
     assertThat(result.hasRepo()).isFalse();
+    assertThat(result.hasUpdatedAt()).isFalse();
   }
 
   @Test
index d468757279655be65c2bb4b06c16d05bc205b906..dddecdb2a5b048676ddf9be6b865412bbcb0c171 100644 (file)
@@ -79,6 +79,7 @@ import static org.sonar.server.rule.ws.RulesWsParameters.FIELD_STATUS;
 import static org.sonar.server.rule.ws.RulesWsParameters.FIELD_SYSTEM_TAGS;
 import static org.sonar.server.rule.ws.RulesWsParameters.FIELD_TAGS;
 import static org.sonar.server.rule.ws.RulesWsParameters.FIELD_TEMPLATE_KEY;
+import static org.sonar.server.rule.ws.RulesWsParameters.FIELD_UPDATED_AT;
 import static org.sonarqube.ws.Rules.Rule.DescriptionSection.Context.newBuilder;
 
 /**
@@ -125,6 +126,7 @@ public class RuleMapper {
     setSysTags(ruleResponse, ruleDto, fieldsToReturn);
     setParams(ruleResponse, ruleDto, result, fieldsToReturn);
     setCreatedAt(ruleResponse, ruleDto, fieldsToReturn);
+    setUpdatedAt(ruleResponse, ruleDto, fieldsToReturn);
     setDescriptionFields(ruleResponse, ruleDto, fieldsToReturn);
     setSeverity(ruleResponse, ruleDto, fieldsToReturn);
     setInternalKey(ruleResponse, ruleDto, fieldsToReturn);
@@ -327,6 +329,12 @@ public class RuleMapper {
     }
   }
 
+  private static void setUpdatedAt(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
+    if (shouldReturnField(fieldsToReturn, FIELD_UPDATED_AT)) {
+      ruleResponse.setUpdatedAt(formatDateTime(ruleDto.getUpdatedAt()));
+    }
+  }
+
   private void setDescriptionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
     if (shouldReturnField(fieldsToReturn, FIELD_HTML_DESCRIPTION)) {
       String htmlDescription = ruleDescriptionFormatter.getDescriptionAsHtml(ruleDto);
index 961cd3274286cd7f221787d0deada888ea9a496a..e1e242b8b81b818c1fa48d61c63447010486ba34 100644 (file)
@@ -120,6 +120,7 @@ message Rule {
   optional DeprecatedKeys deprecatedKeys = 48;
   optional DescriptionSections descriptionSections = 49;
   optional EducationPrinciples educationPrinciples = 50;
+  optional string updatedAt = 51;
 
   message DescriptionSections {
     repeated DescriptionSection descriptionSections = 1;