Skip to content

Commit

Permalink
Added branch name in md report
Browse files Browse the repository at this point in the history
  • Loading branch information
Topin2001 committed May 31, 2024
1 parent 7669974 commit 1106ed8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ private PlaceHolders() {
* Placeholder for project's name
*/
private static final String PROJECTNAME_PLACEHOLDER = "XX-PROJECTNAME-XX";
/**
* Placeholder for the project's branch
*/
private static final String PROJECTBRANCH_PLACEHOLDER = "XX-PROJECTBRANCH-XX";
/**
* Placeholder for the quality gate's anme
*/
Expand Down Expand Up @@ -352,6 +356,9 @@ public static Map<String, String> loadPlaceholdersMap(Report report) {
replacementValues.put(
PROJECTNAME_PLACEHOLDER,
report.getProjectName());
replacementValues.put(
PROJECTBRANCH_PLACEHOLDER,
report.getProjectBranch());
// configuration placeholders
replacementValues.put(
QUALITYGATENAME_PLACEHOLDER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public Report create() throws BadSonarQubeRequestException, UnknownQualityGateEx
report.setProject(projectProvider.getProject(this.project, this.branch));
// project's name's setting
report.setProjectName(report.getProject().getName());
// project's branch's setting
report.setProjectBranch(report.getProject().getBranch());
// formatted issues, unconfirmed issues and raw issues' setting
report.setIssues(issuesProvider.getIssues());
report.setUnconfirmed(issuesProvider.getUnconfirmedIssues());
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/fr/cnes/sonar/report/model/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class Report {
* Name of the project/report
*/
private String projectName;
/**
* Name of the branch
*/
private String branchName;
/**
* Name of the author
*/
Expand Down Expand Up @@ -107,6 +111,7 @@ public class Report {
*/
public Report() {
this.projectName = "";
this.branchName = "";
this.projectAuthor = "";
this.projectDate = "";
this.qualityProfiles = new ArrayList<>();
Expand Down Expand Up @@ -265,6 +270,24 @@ public void setProjectName(String pProjectName) {
this.projectName = pProjectName;
}

/**
* Getter for branchName
*
* @return branchName
*/
public String getProjectBranch() {
return branchName;
}

/**
* Setter for branchName
*
* @param pBranchName value
*/
public void setProjectBranch(String pBranchName) {
this.branchName = pBranchName;
}

/**
* Getter for projectAuthor
*
Expand Down Expand Up @@ -541,4 +564,5 @@ public Map<String, String> getQualityGateStatus() {
public void setQualityGateStatus(Map<String, String> pQualityGateStatus) {
this.qualityGateStatus = pQualityGateStatus;
}

}
3 changes: 2 additions & 1 deletion src/main/resources/template/code-analysis-template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Code analysis
## XX-PROJECTNAME-XX
#### Branch XX-PROJECTBRANCH-XX
#### Version XX-VERSION-XX

**By: XX-AUTHOR-XX**
Expand Down Expand Up @@ -82,4 +83,4 @@ $SECURITY_HOTSPOTS_COUNT

### Security hotspots

$SECURITY_HOTSPOTS_DETAILS
$SECURITY_HOTSPOTS_DETAILS
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 @@ -95,6 +95,7 @@ public void before() {
});

report.setProjectName("CNES Report");
report.setProjectBranch("main");
report.setProjectDate(new Date().toString().substring(0,16));
report.setProjectAuthor("Lequal");

Expand Down
1 change: 1 addition & 0 deletions src/test/ut/java/fr/cnes/sonar/report/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void defaultReportValuesTest() {
assertEquals("", report.getProjectAuthor());
assertEquals("", report.getProjectDate());
assertEquals("", report.getProjectName());
assertEquals("", report.getProjectBranch());
assertEquals("", report.getQualityProfilesFilename());
assert(report.getRawIssues().isEmpty());
assert(report.getQualityProfiles().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void loadPlaceholdersMapTest(){
Map<String,String> expected = new HashMap<>();
// Fill manually the placeHolders depending on what we initialized in "CommonTest"
expected.put("XX-PROJECTNAME-XX", "CNES Report");
expected.put("XX-PROJECTBRANCH-XX", "main");
expected.put("XX-DUPLICATION-XX", "1.0");
expected.put("XX-COMMENTDENSITY-XX", "1.0");
expected.put("XX-MAXNCLOC-XX", "unknown");
Expand Down

0 comments on commit 1106ed8

Please sign in to comment.