From 1106ed835895a46097d726d214c3e7ff4f78af96 Mon Sep 17 00:00:00 2001 From: Topin2001 Date: Tue, 28 May 2024 18:00:27 +0200 Subject: [PATCH] Added branch name in md report --- .../report/exporters/data/PlaceHolders.java | 7 ++++++ .../report/factory/ReportModelFactory.java | 2 ++ .../fr/cnes/sonar/report/model/Report.java | 24 +++++++++++++++++++ .../template/code-analysis-template.md | 3 ++- .../java/fr/cnes/sonar/report/CommonTest.java | 1 + .../java/fr/cnes/sonar/report/ReportTest.java | 1 + .../exporters/data/PlaceHoldersTest.java | 1 + 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/cnes/sonar/report/exporters/data/PlaceHolders.java b/src/main/java/fr/cnes/sonar/report/exporters/data/PlaceHolders.java index 703c6e98..9a96bb7f 100644 --- a/src/main/java/fr/cnes/sonar/report/exporters/data/PlaceHolders.java +++ b/src/main/java/fr/cnes/sonar/report/exporters/data/PlaceHolders.java @@ -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 */ @@ -352,6 +356,9 @@ public static Map loadPlaceholdersMap(Report report) { replacementValues.put( PROJECTNAME_PLACEHOLDER, report.getProjectName()); + replacementValues.put( + PROJECTBRANCH_PLACEHOLDER, + report.getProjectBranch()); // configuration placeholders replacementValues.put( QUALITYGATENAME_PLACEHOLDER, diff --git a/src/main/java/fr/cnes/sonar/report/factory/ReportModelFactory.java b/src/main/java/fr/cnes/sonar/report/factory/ReportModelFactory.java index cbb5fc1c..a1ef5e14 100644 --- a/src/main/java/fr/cnes/sonar/report/factory/ReportModelFactory.java +++ b/src/main/java/fr/cnes/sonar/report/factory/ReportModelFactory.java @@ -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()); diff --git a/src/main/java/fr/cnes/sonar/report/model/Report.java b/src/main/java/fr/cnes/sonar/report/model/Report.java index 1d839b41..6945af26 100644 --- a/src/main/java/fr/cnes/sonar/report/model/Report.java +++ b/src/main/java/fr/cnes/sonar/report/model/Report.java @@ -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 */ @@ -107,6 +111,7 @@ public class Report { */ public Report() { this.projectName = ""; + this.branchName = ""; this.projectAuthor = ""; this.projectDate = ""; this.qualityProfiles = new ArrayList<>(); @@ -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 * @@ -541,4 +564,5 @@ public Map getQualityGateStatus() { public void setQualityGateStatus(Map pQualityGateStatus) { this.qualityGateStatus = pQualityGateStatus; } + } diff --git a/src/main/resources/template/code-analysis-template.md b/src/main/resources/template/code-analysis-template.md index 7c0f6cbb..0c63db4d 100644 --- a/src/main/resources/template/code-analysis-template.md +++ b/src/main/resources/template/code-analysis-template.md @@ -1,5 +1,6 @@ # Code analysis ## XX-PROJECTNAME-XX +#### Branch XX-PROJECTBRANCH-XX #### Version XX-VERSION-XX **By: XX-AUTHOR-XX** @@ -82,4 +83,4 @@ $SECURITY_HOTSPOTS_COUNT ### Security hotspots -$SECURITY_HOTSPOTS_DETAILS \ No newline at end of file +$SECURITY_HOTSPOTS_DETAILS diff --git a/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java b/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java index 7631c69c..eef01d62 100644 --- a/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java +++ b/src/test/ut/java/fr/cnes/sonar/report/CommonTest.java @@ -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"); diff --git a/src/test/ut/java/fr/cnes/sonar/report/ReportTest.java b/src/test/ut/java/fr/cnes/sonar/report/ReportTest.java index 79227a3d..0f88a257 100644 --- a/src/test/ut/java/fr/cnes/sonar/report/ReportTest.java +++ b/src/test/ut/java/fr/cnes/sonar/report/ReportTest.java @@ -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()); diff --git a/src/test/ut/java/fr/cnes/sonar/report/exporters/data/PlaceHoldersTest.java b/src/test/ut/java/fr/cnes/sonar/report/exporters/data/PlaceHoldersTest.java index 74209021..acb024af 100644 --- a/src/test/ut/java/fr/cnes/sonar/report/exporters/data/PlaceHoldersTest.java +++ b/src/test/ut/java/fr/cnes/sonar/report/exporters/data/PlaceHoldersTest.java @@ -41,6 +41,7 @@ public void loadPlaceholdersMapTest(){ Map 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");