Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the comment density metric in synthesis report part #236

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public final class DataAdapter {
* Placeholder for duplication rate
*/
private static final String DUPLICATION_PLACEHOLDER = "XX-DUPLICATION-XX";
/**
* Placeholder for comment density
*/
private static final String COMMENTDENSITY_PLACEHOLDER = "XX-COMMENTDENSITY-XX";
/**
* Placeholder for maintainability mark
*/
Expand Down Expand Up @@ -224,6 +228,10 @@ public final class DataAdapter {
* Field in json response for duplications
*/
private static final String DUPLICATED_LINES_DENSITY = "duplicated_lines_density";
/**
* Field in json response for comment density
*/
private static final String COMMENT_LINES_DENSITY = "comment_lines_density";
/**
* Field in json response for maintainability mark
*/
Expand Down Expand Up @@ -689,6 +697,9 @@ private static String getPlaceHolderName(String metric) {
case DUPLICATED_LINES_DENSITY:
res = DUPLICATION_PLACEHOLDER;
break;
case COMMENT_LINES_DENSITY:
res = COMMENTDENSITY_PLACEHOLDER;
break;
case SQALE_RATING:
res = MAINTAINABILITY_PLACEHOLDER;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/requests.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MAX_PER_PAGE_SONARQUBE = 500
# Request to get the list of components and their metrics
GET_COMPONENTS_REQUEST = %s/api/measures/component_tree?component=%s&metricKeys=ncloc,comment_lines_density,coverage,complexity,cognitive_complexity,duplicated_lines_density&p=%s&ps=%s&branch=%s
# Request to get the list of metrics
GET_MEASURES_REQUEST = %s/api/measures/component?component=%s&metricKeys=ncloc,violations,ncloc_language_distribution,duplicated_lines_density,coverage,sqale_rating,reliability_rating,security_rating,alert_status,complexity,function_complexity,file_complexity,class_complexity,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,new_violations,bugs,vulnerabilities,code_smells&branch=%s
GET_MEASURES_REQUEST = %s/api/measures/component?component=%s&metricKeys=ncloc,violations,ncloc_language_distribution,duplicated_lines_density,comment_lines_density,coverage,sqale_rating,reliability_rating,security_rating,alert_status,complexity,function_complexity,file_complexity,class_complexity,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,new_violations,bugs,vulnerabilities,code_smells&branch=%s
# Request for getting a specific project
GET_PROJECT_REQUEST = %s/api/navigation/component?component=%s&branch=%s
# Request to get the list of quality gates
Expand Down
Binary file modified src/main/resources/template/code-analysis-template.docx
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/resources/template/code-analysis-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ XX-DESCRIPTION-XX
- File: XX-QUALITYGATEFILE-XX

## Synthesis
Quality Gate | Reliability | Security | Maintainability | Coverage | Duplications
Quality Gate | Reliability | Security | Maintainability | Coverage | Duplications | Comment density
:---:|:---:|:---:|:---:|:---:|:---:
XX-QUALITYGATE-XX | XX-RELIABILITY-XX | XX-SECURITY-XX | XX-MAINTAINABILITY-XX | XX-COVERAGE-XX % | XX-DUPLICATION-XX %
XX-QUALITYGATE-XX | XX-RELIABILITY-XX | XX-SECURITY-XX | XX-MAINTAINABILITY-XX | XX-COVERAGE-XX % | XX-DUPLICATION-XX % | XX-COMMENTDENSITY-XX %

## Metrics

Expand Down
1 change: 1 addition & 0 deletions src/test/ut/java/fr/cnes/sonar/report/CommonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public void before() {
final List<Measure> measures = new ArrayList<>();
measures.add(new Measure("reliability_rating", "1.0"));
measures.add(new Measure("duplicated_lines_density", "1.0"));
measures.add(new Measure("comment_lines_density", "1.0"));
measures.add(new Measure("sqale_rating", "2.0"));
measures.add(new Measure("coverage", "1.0"));
measures.add(new Measure("ncloc", "1.0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void loadPlaceholdersMapTest(){
// Fill manually the placeHolders depending on what we initialized in "CommonTest"
expected.put("XX-PROJECTNAME-XX", "CNES Report");
expected.put("XX-DUPLICATION-XX", "1.0");
expected.put("XX-COMMENTDENSITY-XX", "1.0");
expected.put("XX-MAXNCLOC-XX", "unknown");
expected.put("XX-QUALITYGATEFILE-XX", "CNES.xml");
expected.put("XX-MAXCOGNITIVECOMPLEXITY-XX", "unknown");
Expand Down