From 1b6e79b64075519838d8df47ac21d36f06f33f19 Mon Sep 17 00:00:00 2001 From: George Tay Date: Mon, 15 Apr 2024 14:32:10 +0800 Subject: [PATCH 01/12] Implement one-stop config file --- build.gradle | 6 +- config/report-config.yaml | 43 +++++++ docs/ug/configFiles.md | 16 ++- docs/ug/report-config.json | 3 - docs/ug/report-config.yaml | 11 ++ src/main/java/reposense/RepoSense.java | 2 +- .../java/reposense/model/CliArguments.java | 5 +- .../reposense/model/ReportConfiguration.java | 13 -- .../model/reportconfig/ReportBranchData.java | 121 ++++++++++++++++++ .../reportconfig/ReportConfiguration.java | 57 +++++++++ .../reportconfig/ReportGroupDetails.java | 49 +++++++ .../reportconfig/ReportGroupNameAndGlobs.java | 69 ++++++++++ .../reportconfig/ReportRepoConfiguration.java | 93 ++++++++++++++ .../java/reposense/parser/ArgsParser.java | 7 +- .../parser/ReportConfigJsonParser.java | 34 ----- .../parser/ReportConfigYamlParser.java | 59 +++++++++ .../reposense/report/ReportGenerator.java | 10 +- .../java/reposense/report/SummaryJson.java | 7 +- .../ConfigSystemTest/report-config.json | 1 - .../ConfigSystemTest/report-config.yaml | 43 +++++++ .../reportconfig/ReportBranchDataTest.java | 56 ++++++++ .../reportconfig/ReportConfigurationTest.java | 28 ++++ .../reportconfig/ReportGroupDetailsTest.java | 23 ++++ .../ReportGroupNameAndGlobsTest.java | 22 ++++ .../ReportRepoConfigurationTest.java | 46 +++++++ .../parser/ReportConfigJsonParserTest.java | 38 ------ .../parser/ReportConfigYamlParserTest.java | 44 +++++++ .../report-config-empty.json | 3 - .../report-config-invalid.json | 3 - .../report-config-valid.json | 3 - .../report-config-empty.yaml | 0 .../report-config-invalid.yaml | 36 ++++++ .../report-config-valid.yaml | 44 +++++++ 33 files changed, 878 insertions(+), 117 deletions(-) create mode 100644 config/report-config.yaml delete mode 100644 docs/ug/report-config.json create mode 100644 docs/ug/report-config.yaml delete mode 100644 src/main/java/reposense/model/ReportConfiguration.java create mode 100644 src/main/java/reposense/model/reportconfig/ReportBranchData.java create mode 100644 src/main/java/reposense/model/reportconfig/ReportConfiguration.java create mode 100644 src/main/java/reposense/model/reportconfig/ReportGroupDetails.java create mode 100644 src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java create mode 100644 src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java delete mode 100644 src/main/java/reposense/parser/ReportConfigJsonParser.java create mode 100644 src/main/java/reposense/parser/ReportConfigYamlParser.java delete mode 100644 src/systemtest/resources/ConfigSystemTest/report-config.json create mode 100644 src/systemtest/resources/ConfigSystemTest/report-config.yaml create mode 100644 src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportGroupNameAndGlobsTest.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java delete mode 100644 src/test/java/reposense/parser/ReportConfigJsonParserTest.java create mode 100644 src/test/java/reposense/parser/ReportConfigYamlParserTest.java delete mode 100644 src/test/resources/ReportConfigJsonParserTest/report-config-empty.json delete mode 100644 src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json delete mode 100644 src/test/resources/ReportConfigJsonParserTest/report-config-valid.json create mode 100644 src/test/resources/ReportConfigYamlParserTest/report-config-empty.yaml create mode 100644 src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml create mode 100644 src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml diff --git a/build.gradle b/build.gradle index 95e377018b..2cda2181b8 100644 --- a/build.gradle +++ b/build.gradle @@ -18,8 +18,8 @@ mainClassName = 'reposense.RepoSense' node.download = false // The Liferay Node Gradle Plugin will use the system PATH to find the Node/npm executable. -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_11 repositories { mavenCentral() @@ -38,6 +38,8 @@ dependencies { implementation group: 'org.apache.ant', name: 'ant', version: '1.10.12' implementation group: 'org.apache.commons', name: 'commons-csv', version: '1.9.0' implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0' + implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.17.0' + implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.17.0' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion diff --git a/config/report-config.yaml b/config/report-config.yaml new file mode 100644 index 0000000000..4e430c7404 --- /dev/null +++ b/config/report-config.yaml @@ -0,0 +1,43 @@ +title: RepoSense Report +group-details: + - repo: https://github.com/user/repo/tree/fake-branch + groups: + - group-name: code + globs: + - "**.java" + - group-name: tests + globs: + - "src/test**" + - group-name: docs + globs: + - "docs**" + - "**.adoc" + - "**.md" +repos: + - repo: https://github.com/user/repo/tree/fake-branch + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + branches: + - branch: main + file-formats: + - override:java + - md + - fxml + ignore-glob-list: + - "docs**" + ignore-standalone-config: true + ignore-commits-list: + - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 + - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 + - cd7f610e0becbdf331d5231887d8010a689f87c7 + - 768015345e70f06add2a8b7d1f901dc07bf70582 + ignore-authors-list: + - author1 + - author2 + is-shallow-cloning: true + is-find-previous-authors: false diff --git a/docs/ug/configFiles.md b/docs/ug/configFiles.md index 1797f8e4ea..2b942673c1 100644 --- a/docs/ug/configFiles.md +++ b/docs/ug/configFiles.md @@ -107,12 +107,22 @@ e.g.: `example.java` in `example-repo` can either be in the `test` group or the -## `report-config.json` +## `report-config.yaml` -You can optionally use `report-config.json` to customize report generation by providing the following information. ([example](report-config.json)) +You can also optionally use a `report-config.json` file to quickly define the repository information for the repositories you are interested in tracking and generate your very own code portfolio. + +View this [example](report-config.yaml) for a better understanding of what repository information is required. **Fields to provide**: -* `title`: Title of the generated report, which is also the title of the deployed dashboard. Default: "RepoSense Report" +* `repoUrl`: The URL to your repository of interest +* `reportTitle`: Title of the generated report, which is also the title of the deployed dashboard. Default: "RepoSense Report" +* `authorDisplayName`: Name of the author to track in the repository. +* `authorGithubId`: The GitHub username of the author to track in the repository. +* `branches`: A list of branches with their associated blurbs. + * `name`: Name of the branch to track + * `blurb`: Blurb to include with the branch +* `startDate`: The start date of analysis for RepoSense. Default: "2020-01-01" +* `endDate`: The end date of analysis for RepoSense. Default: "9999-12-32" diff --git a/docs/ug/report-config.json b/docs/ug/report-config.json deleted file mode 100644 index 8165c98ac4..0000000000 --- a/docs/ug/report-config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "title": "CS2103 RepoSense Report" -} diff --git a/docs/ug/report-config.yaml b/docs/ug/report-config.yaml new file mode 100644 index 0000000000..d7fed5f8fe --- /dev/null +++ b/docs/ug/report-config.yaml @@ -0,0 +1,11 @@ +repoUrl: github.com/user/repo +reportTitle: RepoSense Report +authorDisplayName: Sample Author +authorGithubId: Sample Author Github ID +branches: + - name: Branch 1 + blurb: Blurb 1 + - name: Branch 2 + blurb: Blurb 2 +startDate: 2020-01-01 +endDate: 9999-12-31 diff --git a/src/main/java/reposense/RepoSense.java b/src/main/java/reposense/RepoSense.java index 20a8c9188d..4132a90969 100644 --- a/src/main/java/reposense/RepoSense.java +++ b/src/main/java/reposense/RepoSense.java @@ -12,8 +12,8 @@ import reposense.git.GitConfig; import reposense.model.CliArguments; import reposense.model.RepoConfiguration; -import reposense.model.ReportConfiguration; import reposense.model.RunConfigurationDecider; +import reposense.model.reportconfig.ReportConfiguration; import reposense.parser.ArgsParser; import reposense.parser.exceptions.InvalidCsvException; import reposense.parser.exceptions.InvalidHeaderException; diff --git a/src/main/java/reposense/model/CliArguments.java b/src/main/java/reposense/model/CliArguments.java index 0b70dd2b0e..f78e9cd24b 100644 --- a/src/main/java/reposense/model/CliArguments.java +++ b/src/main/java/reposense/model/CliArguments.java @@ -7,11 +7,12 @@ import java.util.List; import java.util.Objects; +import reposense.model.reportconfig.ReportConfiguration; import reposense.parser.ArgsParser; import reposense.parser.AuthorConfigCsvParser; import reposense.parser.GroupConfigCsvParser; import reposense.parser.RepoConfigCsvParser; -import reposense.parser.ReportConfigJsonParser; +import reposense.parser.ReportConfigYamlParser; /** * Represents command line arguments user supplied when running the program. @@ -441,7 +442,7 @@ public Builder configFolderPath(Path configFolderPath) { this.cliArguments.groupConfigFilePath = configFolderPath.resolve( GroupConfigCsvParser.GROUP_CONFIG_FILENAME); this.cliArguments.reportConfigFilePath = configFolderPath.resolve( - ReportConfigJsonParser.REPORT_CONFIG_FILENAME); + ReportConfigYamlParser.REPORT_CONFIG_FILENAME); return this; } diff --git a/src/main/java/reposense/model/ReportConfiguration.java b/src/main/java/reposense/model/ReportConfiguration.java deleted file mode 100644 index 4f6e166c34..0000000000 --- a/src/main/java/reposense/model/ReportConfiguration.java +++ /dev/null @@ -1,13 +0,0 @@ -package reposense.model; - -/** - * Represents configuration information from JSON config file for generated report. - */ -public class ReportConfiguration { - private static final String DEFAULT_TITLE = "RepoSense Report"; - private String title; - - public String getTitle() { - return (title == null) ? DEFAULT_TITLE : title; - } -} diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java new file mode 100644 index 0000000000..687577b863 --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -0,0 +1,121 @@ +package reposense.model.reportconfig; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a single entry of a branch in the YAML config file. + */ +public class ReportBranchData { + public static final String DEFAULT_BRANCH = "main"; + public static final List DEFAULT_FILE_FORMATS = List.of( + "override:java", "md", "fxml" + ); + public static final List DEFAULT_IGNORE_GLOB_LIST = List.of( + "docs**" + ); + public static final List DEFAULT_IGNORE_COMMITS_LIST = List.of( + "2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7", + "c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151", + "cd7f610e0becbdf331d5231887d8010a689f87c7", + "768015345e70f06add2a8b7d1f901dc07bf70582" + ); + public static final List DEFAULT_IGNORE_AUTHORS_LIST = List.of( + "author1", + "author2" + ); + public static final boolean DEFAULT_IS_FIND_PREVIOUS_AUTHOR = false; + public static final boolean DEFAULT_IS_SHALLOW_CLONING = true; + public static final boolean DEFAULT_IS_IGNORE_STANDALONE_CONFIG = true; + + public static final ReportBranchData DEFAULT_INSTANCE = new ReportBranchData(); + + static { + DEFAULT_INSTANCE.branch = ReportBranchData.DEFAULT_BRANCH; + DEFAULT_INSTANCE.fileFormats = ReportBranchData.DEFAULT_FILE_FORMATS; + DEFAULT_INSTANCE.ignoreGlobList = ReportBranchData.DEFAULT_IGNORE_GLOB_LIST; + DEFAULT_INSTANCE.ignoreCommitList = ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST; + DEFAULT_INSTANCE.ignoreAuthorList = ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST; + DEFAULT_INSTANCE.isFindPreviousAuthor = ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR; + DEFAULT_INSTANCE.isShallowCloning = ReportBranchData.DEFAULT_IS_SHALLOW_CLONING; + DEFAULT_INSTANCE.isIgnoreStandaloneConfig = ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG; + } + + @JsonProperty("branch") + private String branch; + + @JsonProperty("file-formats") + private List fileFormats; + + @JsonProperty("ignore-glob-list") + private List ignoreGlobList; + + @JsonProperty("ignore-standalone-config") + private Boolean isIgnoreStandaloneConfig; + + @JsonProperty("ignore-commits-list") + private List ignoreCommitList; + + @JsonProperty("ignore-authors-list") + private List ignoreAuthorList; + + @JsonProperty("is-shallow-cloning") + private Boolean isShallowCloning; + + @JsonProperty("is-find-previous-authors") + private Boolean isFindPreviousAuthor; + + public String getBranch() { + return branch == null ? DEFAULT_BRANCH : branch; + } + + public List getFileFormats() { + return fileFormats == null ? DEFAULT_FILE_FORMATS : fileFormats; + } + + public List getIgnoreGlobList() { + return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : fileFormats; + } + + public boolean getIsIgnoreStandaloneConfig() { + return isIgnoreStandaloneConfig == null ? DEFAULT_IS_IGNORE_STANDALONE_CONFIG : isIgnoreStandaloneConfig; + } + + public List getIgnoreCommitList() { + return ignoreCommitList == null ? DEFAULT_IGNORE_COMMITS_LIST : ignoreCommitList; + } + + public List getIgnoreAuthorList() { + return ignoreAuthorList == null ? DEFAULT_IGNORE_AUTHORS_LIST : ignoreAuthorList; + } + + public boolean getIsShallowCloning() { + return isShallowCloning == null ? DEFAULT_IS_SHALLOW_CLONING : isShallowCloning; + } + + public boolean getIsFindPreviousAuthor() { + return isFindPreviousAuthor == null ? DEFAULT_IS_FIND_PREVIOUS_AUTHOR : isFindPreviousAuthor; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportBranchData) { + ReportBranchData rbd = (ReportBranchData) obj; + return this.getBranch().equals(rbd.getBranch()) + && this.getFileFormats().equals(rbd.getFileFormats()) + && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) + && this.getIsIgnoreStandaloneConfig() == rbd.getIsIgnoreStandaloneConfig() + && this.getIgnoreCommitList().equals(rbd.getIgnoreCommitList()) + && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()) + && this.getIsShallowCloning() == rbd.getIsShallowCloning() + && this.getIsFindPreviousAuthor() == rbd.getIsFindPreviousAuthor(); + } + + return false; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java new file mode 100644 index 0000000000..fcaf682598 --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java @@ -0,0 +1,57 @@ +package reposense.model.reportconfig; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Class that contains information on a report's configurations. + * This class is used mainly for quickly setting up one's personal code portfolio. + */ +public class ReportConfiguration { + public static final String DEFAULT_TITLE = "RepoSense Report"; + public static final List DEFAULT_REPORT_GROUP_DETAILS = new ArrayList<>(); + public static final List DEFAULT_REPORT_REPO_CONFIGS = new ArrayList<>(); + + static { + DEFAULT_REPORT_REPO_CONFIGS.add(ReportRepoConfiguration.DEFAULT_INSTANCE); + DEFAULT_REPORT_GROUP_DETAILS.add(ReportGroupDetails.DEFAULT_INSTANCE); + } + + @JsonProperty("title") + private String title; + + @JsonProperty("group-details") + private List groupDetails; + + @JsonProperty("repos") + private List reportRepoConfigurations; + + public String getTitle() { + return title == null ? DEFAULT_TITLE : title; + } + + public List getGroupDetails() { + return groupDetails == null ? DEFAULT_REPORT_GROUP_DETAILS : groupDetails; + } + + public List getReportRepoConfigurations() { + return reportRepoConfigurations == null ? DEFAULT_REPORT_REPO_CONFIGS : reportRepoConfigurations; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportConfiguration) { + ReportConfiguration rc = (ReportConfiguration) obj; + return rc.getTitle().equals(this.getTitle()) + && rc.getReportRepoConfigurations().equals(this.getReportRepoConfigurations()); + } + + return false; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java b/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java new file mode 100644 index 0000000000..8310e86f49 --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java @@ -0,0 +1,49 @@ +package reposense.model.reportconfig; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Contains information about the group contained in a particular repo. + */ +public class ReportGroupDetails { + public static final String DEFAULT_REPO = "https://github.com/user/repo/tree/fake-branch"; + public static final List DEFAULT_NAMES_AND_GLOBS = + ReportGroupNameAndGlobs.DEFAULT_INSTANCES; + public static final ReportGroupDetails DEFAULT_INSTANCE = new ReportGroupDetails(); + + static { + DEFAULT_INSTANCE.repo = DEFAULT_REPO; + DEFAULT_INSTANCE.reportGroupNameAndGlobsList = ReportGroupNameAndGlobs.DEFAULT_INSTANCES; + } + + @JsonProperty("repo") + private String repo; + + @JsonProperty("groups") + private List reportGroupNameAndGlobsList; + + public String getRepo() { + return repo == null ? DEFAULT_REPO : repo; + } + + public List getReportGroupNameAndGlobsList() { + return reportGroupNameAndGlobsList == null ? DEFAULT_NAMES_AND_GLOBS : reportGroupNameAndGlobsList; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportGroupDetails) { + ReportGroupDetails rgd = (ReportGroupDetails) obj; + return this.getRepo().equals(rgd.getRepo()) + && this.getReportGroupNameAndGlobsList().equals(rgd.getReportGroupNameAndGlobsList()); + } + + return false; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java b/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java new file mode 100644 index 0000000000..f3403d31ab --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java @@ -0,0 +1,69 @@ +package reposense.model.reportconfig; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Contains details about each report group and the corresponding globs. + */ +public class ReportGroupNameAndGlobs { + public static final String DEFAULT_GROUP_NAME = "code"; + public static final List DEFAULT_GLOBS = List.of( + "**.java" + ); + public static final List DEFAULT_INSTANCES = new ArrayList<>(); + + static { + ReportGroupNameAndGlobs rg1 = new ReportGroupNameAndGlobs(); + rg1.groupName = "code"; + rg1.globs = List.of("**.java"); + + ReportGroupNameAndGlobs rg2 = new ReportGroupNameAndGlobs(); + rg2.groupName = "tests"; + rg2.globs = List.of("src/test**"); + + ReportGroupNameAndGlobs rg3 = new ReportGroupNameAndGlobs(); + rg3.groupName = "docs"; + rg3.globs = List.of("docs**", "**.adoc", "**.md"); + + DEFAULT_INSTANCES.add(rg1); + DEFAULT_INSTANCES.add(rg2); + DEFAULT_INSTANCES.add(rg3); + } + + @JsonProperty("group-name") + private String groupName; + + @JsonProperty("globs") + private List globs; + + public String getGroupName() { + return groupName == null ? DEFAULT_GROUP_NAME : groupName; + } + + public List getGlobs() { + return globs == null ? DEFAULT_GLOBS : globs; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportGroupNameAndGlobs) { + ReportGroupNameAndGlobs rgnag = (ReportGroupNameAndGlobs) obj; + return rgnag.getGroupName().equals(this.getGroupName()) + && rgnag.getGlobs().equals(this.getGlobs()); + } + + return false; + } + + @Override + public String toString() { + return "RGNAG { group-name: " + this.groupName + ", globs: " + this.globs + "}"; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java new file mode 100644 index 0000000000..3a90009cad --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java @@ -0,0 +1,93 @@ +package reposense.model.reportconfig; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a single repository configuration in the overall report + * configuration. + */ +public class ReportRepoConfiguration { + public static final String DEFAULT_REPO = "https://github.com/user/repo"; + public static final List DEFAULT_AUTHOR_EMAIL = List.of( + "john@john.com", "johny@mail.com", "j@domain.com" + ); + public static final String DEFAULT_GIT_HOST_ID = "johnDoe"; + public static final String DEFAULT_DISPLAY_NAME = "John Doe"; + public static final String DEFAULT_GIT_AUTHOR_NAME = "my home PC"; + public static final List DEFAULT_BRANCHES = List.of( + ReportBranchData.DEFAULT_INSTANCE + ); + public static final ReportRepoConfiguration DEFAULT_INSTANCE = new ReportRepoConfiguration(); + + static { + DEFAULT_INSTANCE.repo = DEFAULT_REPO; + DEFAULT_INSTANCE.authorEmails = DEFAULT_AUTHOR_EMAIL; + DEFAULT_INSTANCE.authorGitHostId = DEFAULT_GIT_HOST_ID; + DEFAULT_INSTANCE.authorDisplayName = DEFAULT_DISPLAY_NAME; + DEFAULT_INSTANCE.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME; + DEFAULT_INSTANCE.branches = DEFAULT_BRANCHES; + } + + @JsonProperty("repo") + private String repo; + + @JsonProperty("author-emails") + private List authorEmails; + + @JsonProperty("author-git-host-id") + private String authorGitHostId; + + @JsonProperty("author-display-name") + private String authorDisplayName; + + @JsonProperty("author-git-author-name") + private String authorGitAuthorName; + + @JsonProperty("branches") + private List branches; + + public String getRepo() { + return repo == null ? DEFAULT_REPO : repo; + } + + public List getAuthorEmails() { + return authorEmails == null ? DEFAULT_AUTHOR_EMAIL : authorEmails; + } + + public String getAuthorGitHostId() { + return authorGitHostId == null ? DEFAULT_GIT_HOST_ID : authorGitHostId; + } + + public String getAuthorDisplayName() { + return authorDisplayName == null ? DEFAULT_DISPLAY_NAME : authorDisplayName; + } + + public String getAuthorGitAuthorName() { + return authorGitAuthorName == null ? DEFAULT_GIT_AUTHOR_NAME : authorGitAuthorName; + } + + public List getBranches() { + return branches == null ? DEFAULT_BRANCHES : branches; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportRepoConfiguration) { + ReportRepoConfiguration rrc = (ReportRepoConfiguration) obj; + return rrc.getRepo().equals(this.getRepo()) + && rrc.getAuthorEmails().equals(this.getAuthorEmails()) + && rrc.getAuthorGitHostId().equals(this.getAuthorGitHostId()) + && rrc.getAuthorDisplayName().equals(this.getAuthorDisplayName()) + && rrc.getAuthorGitAuthorName().equals(this.getAuthorGitAuthorName()) + && rrc.getBranches().equals(this.getBranches()); + } + + return false; + } +} diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 245be1a6a3..7c8e493d92 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -27,7 +27,7 @@ import reposense.RepoSense; import reposense.model.CliArguments; import reposense.model.FileType; -import reposense.model.ReportConfiguration; +import reposense.model.reportconfig.ReportConfiguration; import reposense.parser.exceptions.ParseException; import reposense.parser.types.AlphanumericArgumentType; import reposense.parser.types.AnalysisThreadsArgumentType; @@ -361,10 +361,10 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names // Report config is ignored if --repos is provided if (locations == null) { - Path reportConfigFilePath = configFolderPath.resolve(ReportConfigJsonParser.REPORT_CONFIG_FILENAME); + Path reportConfigFilePath = configFolderPath.resolve(ReportConfigYamlParser.REPORT_CONFIG_FILENAME); try { - reportConfig = new ReportConfigJsonParser().parse(reportConfigFilePath); + reportConfig = new ReportConfigYamlParser().parse(reportConfigFilePath); } catch (JsonSyntaxException jse) { logger.warning(String.format(MESSAGE_INVALID_CONFIG_PATH, reportConfigFilePath)); } catch (IllegalArgumentException iae) { @@ -374,6 +374,7 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names // Ignore exception as the file is optional. } } + builder.reportConfiguration(reportConfig); } diff --git a/src/main/java/reposense/parser/ReportConfigJsonParser.java b/src/main/java/reposense/parser/ReportConfigJsonParser.java deleted file mode 100644 index f200fc712a..0000000000 --- a/src/main/java/reposense/parser/ReportConfigJsonParser.java +++ /dev/null @@ -1,34 +0,0 @@ -package reposense.parser; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.nio.file.Path; - -import com.google.gson.reflect.TypeToken; - -import reposense.model.ReportConfiguration; - -/** - * Parses json file from {@link Path} and creates a new {@link ReportConfiguration} object. - */ -public class ReportConfigJsonParser extends JsonParser { - public static final String REPORT_CONFIG_FILENAME = "report-config.json"; - - /** - * Gets the type of {@link ReportConfiguration} for json conversion. - */ - @Override - public Type getType() { - return new TypeToken(){}.getType(); - } - - /** - * Converts json file from the given {@code path} and returns a {@link ReportConfiguration} object. - * - * @throws IOException if {@code path} is invalid. - */ - @Override - public ReportConfiguration parse(Path path) throws IOException { - return fromJson(path); - } -} diff --git a/src/main/java/reposense/parser/ReportConfigYamlParser.java b/src/main/java/reposense/parser/ReportConfigYamlParser.java new file mode 100644 index 0000000000..d584d8d40b --- /dev/null +++ b/src/main/java/reposense/parser/ReportConfigYamlParser.java @@ -0,0 +1,59 @@ +package reposense.parser; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Path; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.google.gson.Gson; + +import reposense.model.reportconfig.ReportConfiguration; +import reposense.system.LogsManager; + +/** + * YAML Parser for report-config.yaml files. + */ +public class ReportConfigYamlParser extends JsonParser { + public static final String REPORT_CONFIG_FILENAME = "report-config.yaml"; + private static final Logger logger = LogsManager.getLogger(ReportConfigYamlParser.class); + + @Override + public Type getType() { + return ReportConfiguration.class; + } + + @Override + public ReportConfiguration parse(Path path) throws IOException { + return this.fromJson(null, path, null); + } + + @Override + protected ReportConfiguration fromJson(Path path) throws IOException { + return this.fromJson(null, path, null); + } + + @Override + protected ReportConfiguration fromJson(Gson gson, Path path, Type type) throws IOException , JsonMappingException { + // adapted from https://www.baeldung.com/jackson-yaml + ReportConfiguration reportConfigation; + + try { + logger.log(Level.INFO, "Parsing report-config.yaml file..."); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + mapper.findAndRegisterModules(); + reportConfigation = mapper.readValue(new File(path.toString()), ReportConfiguration.class); + logger.log(Level.INFO, "report-config.yaml file parsed successfully!"); + } catch (IOException ioe) { + // if the parse fails for any reason, the default config file is used instead + logger.log(Level.WARNING, "Error parsing report-config.yaml: " + ioe.getMessage(), ioe); + reportConfigation = new ReportConfiguration(); + } + + return reportConfigation; + } +} diff --git a/src/main/java/reposense/report/ReportGenerator.java b/src/main/java/reposense/report/ReportGenerator.java index 39d87a343e..913b427765 100644 --- a/src/main/java/reposense/report/ReportGenerator.java +++ b/src/main/java/reposense/report/ReportGenerator.java @@ -44,8 +44,8 @@ import reposense.model.CommitHash; import reposense.model.RepoConfiguration; import reposense.model.RepoLocation; -import reposense.model.ReportConfiguration; import reposense.model.StandaloneConfig; +import reposense.model.reportconfig.ReportConfiguration; import reposense.parser.StandaloneConfigJsonParser; import reposense.report.exception.NoAuthorsWithCommitsFoundException; import reposense.system.LogsManager; @@ -114,10 +114,10 @@ public class ReportGenerator { * @throws IOException if templateZip.zip does not exists in jar file. */ public List generateReposReport(List configs, String outputPath, String assetsPath, - ReportConfiguration reportConfig, String generationDate, LocalDateTime cliSinceDate, - LocalDateTime untilDate, boolean isSinceDateProvided, boolean isUntilDateProvided, int numCloningThreads, - int numAnalysisThreads, Supplier reportGenerationTimeProvider, ZoneId zoneId, - boolean shouldFreshClone) throws IOException { + ReportConfiguration reportConfig, String generationDate, LocalDateTime cliSinceDate, + LocalDateTime untilDate, boolean isSinceDateProvided, boolean isUntilDateProvided, int numCloningThreads, + int numAnalysisThreads, Supplier reportGenerationTimeProvider, ZoneId zoneId, + boolean shouldFreshClone) throws IOException { prepareTemplateFile(outputPath); if (Files.exists(Paths.get(assetsPath))) { FileUtil.copyDirectoryContents(assetsPath, outputPath, assetsFilesWhiteList); diff --git a/src/main/java/reposense/report/SummaryJson.java b/src/main/java/reposense/report/SummaryJson.java index 4d264f938f..80961aff9c 100644 --- a/src/main/java/reposense/report/SummaryJson.java +++ b/src/main/java/reposense/report/SummaryJson.java @@ -7,8 +7,8 @@ import java.util.Set; import reposense.model.RepoConfiguration; -import reposense.model.ReportConfiguration; import reposense.model.SupportedDomainUrlMap; +import reposense.model.reportconfig.ReportConfiguration; /** * Represents the structure of summary.json file in reposense-report folder. @@ -30,8 +30,9 @@ public class SummaryJson { private final Map> supportedDomainUrlMap; public SummaryJson(List repos, ReportConfiguration reportConfig, String reportGeneratedTime, - LocalDateTime sinceDate, LocalDateTime untilDate, boolean isSinceDateProvided, boolean isUntilDateProvided, - String repoSenseVersion, Set> errorSet, String reportGenerationTime, ZoneId zoneId) { + LocalDateTime sinceDate, LocalDateTime untilDate, boolean isSinceDateProvided, + boolean isUntilDateProvided, String repoSenseVersion, Set> errorSet, + String reportGenerationTime, ZoneId zoneId) { this.repos = repos; this.reportGeneratedTime = reportGeneratedTime; this.reportGenerationTime = reportGenerationTime; diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.json b/src/systemtest/resources/ConfigSystemTest/report-config.json deleted file mode 100644 index c2aa7ed0bd..0000000000 --- a/src/systemtest/resources/ConfigSystemTest/report-config.json +++ /dev/null @@ -1 +0,0 @@ -{"title": "RepoSense Report Test Title"} diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml new file mode 100644 index 0000000000..1708f569bd --- /dev/null +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -0,0 +1,43 @@ +title: RepoSense Report Test Title +group-details: + - repo: https://github.com/user/repo/tree/fake-branch + groups: + - group-name: code + globs: + - "**.java" + - group-name: tests + globs: + - "src/test**" + - group-name: docs + globs: + - "docs**" + - "**.adoc" + - "**.md" +repos: + - repo: https://github.com/user/repo/tree/fake-branch + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + branches: + - branch: main + file-formats: + - override:java + - md + - fxml + ignore-glob-list: + - "docs**" + ignore-standalone-config: true + ignore-commits-list: + - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 + - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 + - cd7f610e0becbdf331d5231887d8010a689f87c7 + - 768015345e70f06add2a8b7d1f901dc07bf70582 + ignore-authors-list: + - author1 + - author2 + is-shallow-cloning: true + is-find-previous-authors: false diff --git a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java new file mode 100644 index 0000000000..70302084c2 --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java @@ -0,0 +1,56 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportBranchDataTest { + @Test + public void getBranch_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getBranch(), ReportBranchData.DEFAULT_BRANCH); + } + + @Test + public void getFileFormats_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getFileFormats(), ReportBranchData.DEFAULT_FILE_FORMATS); + } + + @Test + public void getIgnoreGlobList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIgnoreGlobList(), ReportBranchData.DEFAULT_IGNORE_GLOB_LIST); + } + + @Test + public void getIsIgnoreStandaloneConfig_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsIgnoreStandaloneConfig(), + ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG); + } + + @Test + public void getIgnoreCommitList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIgnoreCommitList(), + ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST); + } + + @Test + public void getIgnoreAuthorList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIgnoreAuthorList(), + ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST); + } + + @Test + public void getIsShallowCloning_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsShallowCloning(), + ReportBranchData.DEFAULT_IS_SHALLOW_CLONING); + } + + @Test + public void getIsFindPreviousAuthor_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsFindPreviousAuthor(), + ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR); + } + + @Test + public void equals_defaultInstancesAreEqual_success() { + Assertions.assertEquals(new ReportBranchData(), new ReportBranchData()); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java new file mode 100644 index 0000000000..19a5fad8b3 --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java @@ -0,0 +1,28 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportConfigurationTest { + @Test + public void getTitle_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportConfiguration().getTitle(), ReportConfiguration.DEFAULT_TITLE); + } + + @Test + public void getReportRepoConfigurations_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportConfiguration().getReportRepoConfigurations(), + ReportConfiguration.DEFAULT_REPORT_REPO_CONFIGS); + } + + @Test + public void getGroupDetails_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportConfiguration().getGroupDetails(), + ReportConfiguration.DEFAULT_REPORT_GROUP_DETAILS); + } + + @Test + public void equals_defaultInstancesAreEqual_success() { + Assertions.assertEquals(new ReportConfiguration(), new ReportConfiguration()); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java b/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java new file mode 100644 index 0000000000..d3df44380f --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java @@ -0,0 +1,23 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportGroupDetailsTest { + @Test + public void getRepo_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportGroupDetails().getRepo(), ReportGroupDetails.DEFAULT_REPO); + } + + @Test + public void getReportGroupNameAndGlobsList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportGroupDetails().getReportGroupNameAndGlobsList(), + ReportGroupDetails.DEFAULT_NAMES_AND_GLOBS); + } + + @Test + public void equals_defaultInstancesAreEqual_success() { + Assertions.assertEquals(new ReportGroupDetails(), new ReportGroupDetails()); + Assertions.assertEquals(new ReportGroupDetails(), ReportGroupDetails.DEFAULT_INSTANCE); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportGroupNameAndGlobsTest.java b/src/test/java/reposense/model/reportconfig/ReportGroupNameAndGlobsTest.java new file mode 100644 index 0000000000..e44028c85e --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportGroupNameAndGlobsTest.java @@ -0,0 +1,22 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportGroupNameAndGlobsTest { + @Test + public void getRepo_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportGroupNameAndGlobs().getGroupName(), ReportGroupNameAndGlobs.DEFAULT_GROUP_NAME); + } + + @Test + public void getReportGroupNameAndGlobsList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportGroupNameAndGlobs().getGlobs(), + ReportGroupNameAndGlobs.DEFAULT_GLOBS); + } + + @Test + public void equals_defaultInstancesAreEqual_success() { + Assertions.assertEquals(new ReportGroupNameAndGlobs(), new ReportGroupNameAndGlobs()); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java new file mode 100644 index 0000000000..679e9ea88f --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java @@ -0,0 +1,46 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportRepoConfigurationTest { + @Test + public void getRepo_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getRepo(), ReportRepoConfiguration.DEFAULT_REPO); + } + + @Test + public void getAuthorEmails_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getAuthorEmails(), + ReportRepoConfiguration.DEFAULT_AUTHOR_EMAIL); + } + + @Test + public void getAuthorGitHostId_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getAuthorGitHostId(), + ReportRepoConfiguration.DEFAULT_GIT_HOST_ID); + } + + @Test + public void getAuthorDisplayName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getAuthorDisplayName(), + ReportRepoConfiguration.DEFAULT_DISPLAY_NAME); + } + + @Test + public void getAuthorGitAuthorName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getAuthorGitAuthorName(), + ReportRepoConfiguration.DEFAULT_GIT_AUTHOR_NAME); + } + + @Test + public void getBranches_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getBranches(), ReportRepoConfiguration.DEFAULT_BRANCHES); + } + + @Test + public void equals_defaultInstancesAreEqual_success() { + Assertions.assertEquals(new ReportRepoConfiguration(), new ReportRepoConfiguration()); + Assertions.assertEquals(new ReportRepoConfiguration(), ReportRepoConfiguration.DEFAULT_INSTANCE); + } +} diff --git a/src/test/java/reposense/parser/ReportConfigJsonParserTest.java b/src/test/java/reposense/parser/ReportConfigJsonParserTest.java deleted file mode 100644 index 44005ad8d2..0000000000 --- a/src/test/java/reposense/parser/ReportConfigJsonParserTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package reposense.parser; - -import static reposense.util.TestUtil.loadResource; - -import java.nio.file.Path; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import reposense.model.ReportConfiguration; - -public class ReportConfigJsonParserTest { - - private static final Path VALID_REPORT_CONFIG = loadResource( - ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-valid.json"); - private static final Path INVALID_REPORT_CONFIG = loadResource( - ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-invalid.json"); - private static final Path EMPTY_REPORT_CONFIG = loadResource( - ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-empty.json"); - private static final String DEFAULT_TITLE = "RepoSense Report"; - - @Test - public void reportConfig_parseEmptyJsonFile_getDefaultTitle() throws Exception { - ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(EMPTY_REPORT_CONFIG); - Assertions.assertEquals(reportConfig.getTitle(), DEFAULT_TITLE); - } - @Test - public void reportConfig_parseInvalidJsonFile_getDefaultTitle() throws Exception { - ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(INVALID_REPORT_CONFIG); - Assertions.assertEquals(reportConfig.getTitle(), DEFAULT_TITLE); - } - - @Test - public void reportConfig_parseValidJsonFile_getCustomTitle() throws Exception { - ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_REPORT_CONFIG); - Assertions.assertNotEquals(reportConfig.getTitle(), DEFAULT_TITLE); - } -} diff --git a/src/test/java/reposense/parser/ReportConfigYamlParserTest.java b/src/test/java/reposense/parser/ReportConfigYamlParserTest.java new file mode 100644 index 0000000000..79e440b09e --- /dev/null +++ b/src/test/java/reposense/parser/ReportConfigYamlParserTest.java @@ -0,0 +1,44 @@ +package reposense.parser; + +import static reposense.util.TestUtil.loadResource; + +import java.nio.file.Path; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import reposense.model.reportconfig.ReportConfiguration; + +public class ReportConfigYamlParserTest { + + private static final Path VALID_REPORT_CONFIG = loadResource( + ReportConfigYamlParserTest.class, "ReportConfigYamlParserTest/report-config-valid.yaml"); + private static final Path INVALID_REPORT_CONFIG = loadResource( + ReportConfigYamlParserTest.class, "ReportConfigYamlParserTest/report-config-invalid.yaml"); + private static final Path EMPTY_REPORT_CONFIG = loadResource( + ReportConfigYamlParserTest.class, "ReportConfigYamlParserTest/report-config-empty.yaml"); + + @Test + public void reportConfig_parseEmptyYamlFile_getDefaultTitle() throws Exception { + ReportConfiguration reportConfig = new ReportConfigYamlParser().parse(EMPTY_REPORT_CONFIG); + Assertions.assertEquals(reportConfig.getTitle(), ReportConfiguration.DEFAULT_TITLE); + Assertions.assertEquals(reportConfig.getReportRepoConfigurations(), + ReportConfiguration.DEFAULT_REPORT_REPO_CONFIGS); + } + + @Test + public void reportConfig_parseInvalidYamlFile_getDefaultTitle() throws Exception { + ReportConfiguration reportConfig = new ReportConfigYamlParser().parse(INVALID_REPORT_CONFIG); + Assertions.assertEquals(reportConfig.getTitle(), ReportConfiguration.DEFAULT_TITLE); + Assertions.assertEquals(reportConfig.getReportRepoConfigurations(), + ReportConfiguration.DEFAULT_REPORT_REPO_CONFIGS); + } + + @Test + public void reportConfig_parseValidYamlFile_getCustomTitle() throws Exception { + ReportConfiguration reportConfig = new ReportConfigYamlParser().parse(VALID_REPORT_CONFIG); + Assertions.assertNotEquals(reportConfig.getTitle(), ReportConfiguration.DEFAULT_TITLE); + Assertions.assertNotEquals(reportConfig.getReportRepoConfigurations(), + ReportConfiguration.DEFAULT_REPORT_REPO_CONFIGS); + } +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-empty.json b/src/test/resources/ReportConfigJsonParserTest/report-config-empty.json deleted file mode 100644 index 0db3279e44..0000000000 --- a/src/test/resources/ReportConfigJsonParserTest/report-config-empty.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json b/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json deleted file mode 100644 index fd26202fa2..0000000000 --- a/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "ti": "!@#$%^&*()<>:" -} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-valid.json b/src/test/resources/ReportConfigJsonParserTest/report-config-valid.json deleted file mode 100644 index ba731c2add..0000000000 --- a/src/test/resources/ReportConfigJsonParserTest/report-config-valid.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "title": "!@#$%^&*()<>:" -} diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-empty.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-empty.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml new file mode 100644 index 0000000000..fda2a639be --- /dev/null +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml @@ -0,0 +1,36 @@ +title: RepoSense Report +group-details: + - repo: https://github.com/user/repo/tree/fake-branch + grou + - group-name: code + globs: + - "**.java" + - group-name: tests + globs: + - "src/test**" + - group-name: docs + globs: + - "docs**" + - "**.adoc" + - "**.md" +os: + - repo: https://github.com/user/repo/tree/fake-branch + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + author-git-author-name: my home PC + branches: + - branch: main + file-formats: + - override:java + - md + - fxml + ignore-glob-list: + - "docs**" + ignore-standalone-config: true + ignore-author-list: + - author1 + - author2 + is-shallow-cloning: true + is-find-previous-authors: false diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml new file mode 100644 index 0000000000..746b0493f6 --- /dev/null +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -0,0 +1,44 @@ +title: RepoSense Report Repo Test +group-details: + - repo: https://github.com/user/repo/tree/fake-branch + groups: + - group-name: code + globs: + - "**.java" + - group-name: tests + globs: + - "src/test**" + - group-name: docs + globs: + - "docs**" + - "**.adoc" + - "**.md" +repos: + - repo: https://github.com/user/repo/tree/fake-branch + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + branches: + - branch: main + file-formats: + - override:java + - md + - fxml + ignore-glob-list: + - "docs**" + ignore-standalone-config: true + ignore-commits-list: + - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 + - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 + - cd7f610e0becbdf331d5231887d8010a689f87c7 + - 768015345e70f06add2a8b7d1f901dc07bf70582 + ignore-authors-list: + - author1 + - author2 + is-shallow-cloning: true + is-find-previous-authors: false + From b76b29e90e160e4c5a2fd72ba1b366f721f7a21f Mon Sep 17 00:00:00 2001 From: George Tay Date: Sat, 27 Apr 2024 16:22:25 +0800 Subject: [PATCH 02/12] Update report-config.yaml file --- docs/ug/configFiles.md | 2 +- docs/ug/report-config.yaml | 54 +++++++++++++++---- .../java/reposense/parser/ArgsParser.java | 6 +-- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/docs/ug/configFiles.md b/docs/ug/configFiles.md index 2b942673c1..46f95d4851 100644 --- a/docs/ug/configFiles.md +++ b/docs/ug/configFiles.md @@ -109,7 +109,7 @@ e.g.: `example.java` in `example-repo` can either be in the `test` group or the ## `report-config.yaml` -You can also optionally use a `report-config.json` file to quickly define the repository information for the repositories you are interested in tracking and generate your very own code portfolio. +You can also optionally use a `report-config.yaml` file to quickly define the repository information for the repositories you are interested in tracking and generate your very own code portfolio. View this [example](report-config.yaml) for a better understanding of what repository information is required. diff --git a/docs/ug/report-config.yaml b/docs/ug/report-config.yaml index d7fed5f8fe..4e430c7404 100644 --- a/docs/ug/report-config.yaml +++ b/docs/ug/report-config.yaml @@ -1,11 +1,43 @@ -repoUrl: github.com/user/repo -reportTitle: RepoSense Report -authorDisplayName: Sample Author -authorGithubId: Sample Author Github ID -branches: - - name: Branch 1 - blurb: Blurb 1 - - name: Branch 2 - blurb: Blurb 2 -startDate: 2020-01-01 -endDate: 9999-12-31 +title: RepoSense Report +group-details: + - repo: https://github.com/user/repo/tree/fake-branch + groups: + - group-name: code + globs: + - "**.java" + - group-name: tests + globs: + - "src/test**" + - group-name: docs + globs: + - "docs**" + - "**.adoc" + - "**.md" +repos: + - repo: https://github.com/user/repo/tree/fake-branch + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + branches: + - branch: main + file-formats: + - override:java + - md + - fxml + ignore-glob-list: + - "docs**" + ignore-standalone-config: true + ignore-commits-list: + - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 + - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 + - cd7f610e0becbdf331d5231887d8010a689f87c7 + - 768015345e70f06add2a8b7d1f901dc07bf70582 + ignore-authors-list: + - author1 + - author2 + is-shallow-cloning: true + is-find-previous-authors: false diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 7c8e493d92..efe37cee65 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -89,7 +89,7 @@ public class ArgsParser { private static final String MESSAGE_USING_DEFAULT_CONFIG_PATH = "Config path not provided, using the config folder as default."; private static final String MESSAGE_INVALID_CONFIG_PATH = "%s is malformed."; - private static final String MESSAGE_INVALID_CONFIG_JSON = "%s Ignoring the report config provided."; + private static final String MESSAGE_INVALID_CONFIG_YAML = "%s Ignoring the report config provided."; private static final String MESSAGE_SINCE_D1_WITH_PERIOD = "You may be using --since d1 with the --period flag. " + "This may result in an incorrect date range being analysed."; private static final String MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE = @@ -368,9 +368,9 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names } catch (JsonSyntaxException jse) { logger.warning(String.format(MESSAGE_INVALID_CONFIG_PATH, reportConfigFilePath)); } catch (IllegalArgumentException iae) { - logger.warning(String.format(MESSAGE_INVALID_CONFIG_JSON, iae.getMessage())); + logger.warning(String.format(MESSAGE_INVALID_CONFIG_YAML, iae.getMessage())); } catch (IOException ioe) { - // IOException thrown as report-config.json is not found. + // IOException thrown as report-config.yaml is not found. // Ignore exception as the file is optional. } } From 65cf7ddeab9565b3e485f91d03bb1d4507f8ddef Mon Sep 17 00:00:00 2001 From: sopa301 <96387349+sopa301@users.noreply.github.com> Date: Tue, 7 May 2024 12:48:08 +0800 Subject: [PATCH 03/12] Update config file in cypress --- frontend/cypress/config/report-config.json | 3 --- frontend/cypress/config/report-config.yaml | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 frontend/cypress/config/report-config.json create mode 100644 frontend/cypress/config/report-config.yaml diff --git a/frontend/cypress/config/report-config.json b/frontend/cypress/config/report-config.json deleted file mode 100644 index ea98e619e3..0000000000 --- a/frontend/cypress/config/report-config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "title": "RepoSense Test Report" -} diff --git a/frontend/cypress/config/report-config.yaml b/frontend/cypress/config/report-config.yaml new file mode 100644 index 0000000000..a530aa7a91 --- /dev/null +++ b/frontend/cypress/config/report-config.yaml @@ -0,0 +1 @@ +title: RepoSense Report From 0a4b72d173f1de5c8f05f373cb87a6b82a1fc991 Mon Sep 17 00:00:00 2001 From: sopa301 <96387349+sopa301@users.noreply.github.com> Date: Tue, 7 May 2024 12:49:03 +0800 Subject: [PATCH 04/12] Fix title name --- frontend/cypress/config/report-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/cypress/config/report-config.yaml b/frontend/cypress/config/report-config.yaml index a530aa7a91..a5d9bb7897 100644 --- a/frontend/cypress/config/report-config.yaml +++ b/frontend/cypress/config/report-config.yaml @@ -1 +1 @@ -title: RepoSense Report +title: RepoSense Test Report From ab3aff4d8d69395ca1dd7155e8b6ac93bd238e90 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 12 May 2024 19:41:52 +0800 Subject: [PATCH 05/12] Update report-config.yaml format --- config/report-config.yaml | 38 ++++---- docs/ug/cli.md | 2 +- docs/ug/configFiles.md | 38 ++++---- .../reportconfig/ReportAuthorDetails.java | 94 +++++++++++++++++++ .../model/reportconfig/ReportBranchData.java | 13 +++ .../reportconfig/ReportRepoConfiguration.java | 42 --------- .../ConfigSystemTest/report-config.yaml | 15 +-- .../reportconfig/ReportAuthorDetailsTest.java | 30 ++++++ .../ReportRepoConfigurationTest.java | 24 ----- .../report-config-valid.yaml | 15 +-- 10 files changed, 192 insertions(+), 119 deletions(-) create mode 100644 src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java diff --git a/config/report-config.yaml b/config/report-config.yaml index 4e430c7404..b5914b25ce 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -1,6 +1,6 @@ title: RepoSense Report group-details: - - repo: https://github.com/user/repo/tree/fake-branch + - repo: https://github.com/reposense/testrepo-Delta.git groups: - group-name: code globs: @@ -14,30 +14,30 @@ group-details: - "**.adoc" - "**.md" repos: - - repo: https://github.com/user/repo/tree/fake-branch - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC + - repo: https://github.com/reposense/testrepo-Delta.git branches: - - branch: main + - branch: master + authors: + - author-git-host-id: fzdy1914 + author-display-name: WANG CHAO + author-git-author-name: WANG CHAO + author-emails: + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - file-formats: - override:java - md - fxml ignore-glob-list: - - "docs**" - ignore-standalone-config: true + - + ignore-standalone-config: false ignore-commits-list: - - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 - - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 - - cd7f610e0becbdf331d5231887d8010a689f87c7 - - 768015345e70f06add2a8b7d1f901dc07bf70582 + - ignore-authors-list: - - author1 - - author2 - is-shallow-cloning: true + - + is-shallow-cloning: false is-find-previous-authors: false diff --git a/docs/ug/cli.md b/docs/ug/cli.md index 550713969c..d596af8594 100644 --- a/docs/ug/cli.md +++ b/docs/ug/cli.md @@ -68,7 +68,7 @@ partial credit.
**`--config CONFIG_DIRECTORY`**: Specifies that config files located in `CONFIG_DIRECTORY` should be used to customize the report. -* Parameter: `CONFIG_DIRECTORY` The directory containing the config files. Should contain a `repo-config.csv` file. Optionally, can contain an `author-config.csv` file or/and a `group-config.csv` file or/and a `report-config.json` file. +* Parameter: `CONFIG_DIRECTORY` The directory containing the config files. Should contain a `repo-config.csv` file. Optionally, can contain an `author-config.csv` file or/and a `group-config.csv` file or/and a `report-config.yaml` file. * Alias: `-c` * Example: `java -jar RepoSense.jar --config ./config` diff --git a/docs/ug/configFiles.md b/docs/ug/configFiles.md index 46f95d4851..3c9585fb54 100644 --- a/docs/ug/configFiles.md +++ b/docs/ug/configFiles.md @@ -31,20 +31,20 @@ Given below are the details of the various config files used by RepoSense. **`repo-config.csv` file contains repo-level config data.** Each row represents a repository's configuration ([example](repo-config.csv)). -| Column Name | Explanation | -|-------------|-------------| -| Repository's Location {{ mandatory }} | The `Remote Repo URL` or `Disk Path` to the git repository e.g., `https://github.com/foo/bar.git` or `C:\Users\user\Desktop\GitHub\foo\bar` | -| Branch | The branch to analyze in the target repository e.g., `master`. Default: the default branch of the repo | -| File formats*+ | The file extensions to analyze. Binary file formats, such as `png` and `jpg`, will be automatically labelled as the file type `binary` in the generated report. Default: all file formats | -| Find Previous Authors | Enter **`yes`** to utilize Git blame's ignore revisions functionality, RepoSense will attempt to blame the line changes caused by commits in the ignore commit list to the previous authors who altered those lines (if available). | -| Ignore Glob List*+ | The list of file path globs to ignore during analysis for each author e.g., `test/**;temp/**`. Refer to the [_glob format_](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob) for the path glob syntax. | -| Ignore standalone config | To ignore the standalone config file (if any) in target repository, enter **`yes`**. If the cell is empty, the standalone config file in the repo (if any) will take precedence over configurations provided in the csv files. | -| Ignore Commits List*+ | The list of commits to ignore during analysis. For accurate results, the commits should be provided with their full hash. Additionally, a range of commits can be specified using the `..` notation e.g. `abc123..def456` (both inclusive). | -| Ignore Authors List*+ | The list of authors to ignore during analysis. Authors should be specified by their [Git Author Name](#a-note-about-git-author-name). | -| Shallow Cloning | Enter **`yes`** to clone the repository using Git's shallow cloning functionality. This option can significantly reduce the time taken to clone large repositories. However, the option should ideally be disabled for smaller repositories where the `.git` file is smaller than 500 MB, as it would create overhead. | -| File Size Limit+ | Enter a file size limit for the repository in bytes as a single number without units (for a size limit of 1MB for example, enter 1000000). This file size limit will override the default file size limit (500KB). Files exceeding the file size limit will be marked as ignored and only the file name and line count will be reflected in the report. | -| Ignore File Size Limit | Enter **`yes`** to ignore both the default file size limit and the file size limit possibly set by the user in `repo-config.csv`. | -| Skip Ignored File Analysis | Enter **`yes`** to ignore analysis of files exceeding the file size limit entirely. If file analysis is skipped, all information about the file will be omitted from the generated report. This option can significantly improve report generation time. | +| Column Name | Explanation | +|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Repository's Location {{ mandatory }} | The `Remote Repo URL` or `Disk Path` to the git repository e.g., `https://github.com/foo/bar.git` or `C:\Users\user\Desktop\GitHub\foo\bar` | +| Branch | The branch to analyze in the target repository e.g., `master`. Default: the default branch of the repo | +| File formats*+ | The file extensions to analyze. Binary file formats, such as `png` and `jpg`, will be automatically labelled as the file type `binary` in the generated report. Default: all file formats | +| Find Previous Authors | Enter **`yes`** to utilize Git blame's ignore revisions functionality, RepoSense will attempt to blame the line changes caused by commits in the ignore commit list to the previous authors who altered those lines (if available). | +| Ignore Glob List*+ | The list of file path globs to ignore during analysis for each author e.g., `test/**;temp/**`. Refer to the [_glob format_](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob) for the path glob syntax. | +| Ignore standalone config | To ignore the standalone config file (if any) in target repository, enter **`yes`**. If the cell is empty, the standalone config file in the repo (if any) will take precedence over configurations provided in the csv files. | +| Ignore Commits List*+ | The list of commits to ignore during analysis. For accurate results, the commits should be provided with their full hash. Additionally, a range of commits can be specified using the `..` notation e.g. `abc123..def456` (both inclusive). | +| Ignore Authors List*+ | The list of authors to ignore during analysis. Authors should be specified by their [Git Author Name](#a-note-about-git-author-name). | +| Shallow Cloning | Enter **`yes`** to clone the repository using Git's shallow cloning functionality. This option can significantly reduce the time taken to clone large repositories. However, the option should ideally be disabled for smaller repositories where the `.git` file is smaller than 500 MB, as it would create overhead. | +| File Size Limit+ | Enter a file size limit for the repository in bytes as a single number without units (for a size limit of 1MB for example, enter 1000000). This file size limit will override the default file size limit (500KB). Files exceeding the file size limit will be marked as ignored and only the file name and line count will be reflected in the report. | +| Ignore File Size Limit | Enter **`yes`** to ignore both the default file size limit and the file size limit possibly set by the user in `repo-config.csv`. | +| Skip Ignored File Analysis | Enter **`yes`** to ignore analysis of files exceeding the file size limit entirely. If file analysis is skipped, all information about the file will be omitted from the generated report. This option can significantly improve report generation time. | The Shallow Cloning option is incompatible with the "--last-modified-date" CLI flag. @@ -94,11 +94,11 @@ If `author-config.csv` is not given and the repo has not provided author details Optionally, you can provide a `group-config.csv`(which should be in the same directory as `repo-config.csv` file) to provide details on any custom groupings for files in specified repositories ([example](group-config.csv)). It should contain the following columns: -| Column Name | Explanation | -|-------------|-------------| -| Repository's Location | Same as `repo-config.csv`. Default: all the repos in `repo-config.csv` | -| Group Name {{ mandatory }} | Name of the group, e.g.,`test`. | -| Globs * {{ mandatory }} | The list of file path globs to include for specified group, e.g.,`**/test/*;**.java`. | +| Column Name | Explanation | +|----------------------------|---------------------------------------------------------------------------------------| +| Repository's Location | Same as `repo-config.csv`. Default: all the repos in `repo-config.csv` | +| Group Name {{ mandatory }} | Name of the group, e.g.,`test`. | +| Globs * {{ mandatory }} | The list of file path globs to include for specified group, e.g.,`**/test/*;**.java`. | * **Multi-value column**: multiple values can be entered in this column using a semicolon `;` as the separator. diff --git a/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java b/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java new file mode 100644 index 0000000000..af5d41662f --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java @@ -0,0 +1,94 @@ +package reposense.model.reportconfig; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents an author's details in the report-config.yaml file. + */ +public class ReportAuthorDetails { + public static final List DEFAULT_INSTANCES = new ArrayList<>(); + + public static final List DEFAULT_AUTHOR_EMAIL = List.of("john@john.com", "johny@mail.com", "j@domain.com"); + public static final String DEFAULT_GIT_HOST_ID = "johnDoe"; + public static final String DEFAULT_DISPLAY_NAME = "John Doe"; + public static final String DEFAULT_GIT_AUTHOR_NAME = "my home PC"; + + private static final List DEFAULT_AUTHOR_EMAIL_1 = List.of("1229983126@qq.com"); + private static final String DEFAULT_GIT_HOST_ID_1 = "fzdy1914"; + private static final String DEFAULT_DISPLAY_NAME_1 = "WANG CHAO"; + private static final String DEFAULT_GIT_AUTHOR_NAME_1 = "WANG CHAO"; + private static final List DEFAULT_AUTHOR_EMAIL_2 = List.of(""); + private static final String DEFAULT_GIT_HOST_ID_2 = "FH-30"; + private static final String DEFAULT_DISPLAY_NAME_2 = "Francis Hodianto"; + private static final String DEFAULT_GIT_AUTHOR_NAME_2 = "Francis Hodianto"; + + static { + ReportAuthorDetails rad1 = new ReportAuthorDetails(); + ReportAuthorDetails rad2 = new ReportAuthorDetails(); + + rad1.authorEmails = DEFAULT_AUTHOR_EMAIL_1; + rad1.authorGitHostId = DEFAULT_GIT_HOST_ID_1; + rad1.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_1; + rad1.authorDisplayName = DEFAULT_DISPLAY_NAME_1; + + rad2.authorEmails = DEFAULT_AUTHOR_EMAIL_2; + rad2.authorGitHostId = DEFAULT_GIT_HOST_ID_2; + rad2.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_2; + rad2.authorDisplayName = DEFAULT_DISPLAY_NAME_2; + + DEFAULT_INSTANCES.add(rad1); + DEFAULT_INSTANCES.add(rad2); + } + + @JsonProperty("author-emails") + private List authorEmails; + + @JsonProperty("author-git-host-id") + private String authorGitHostId; + + @JsonProperty("author-display-name") + private String authorDisplayName; + + @JsonProperty("author-git-author-name") + private String authorGitAuthorName; + + public ReportAuthorDetails() { + + } + + public List getAuthorEmails() { + return authorEmails == null ? DEFAULT_AUTHOR_EMAIL : authorEmails; + } + + public String getAuthorGitHostId() { + return authorGitHostId == null ? DEFAULT_GIT_HOST_ID : authorGitHostId; + } + + public String getAuthorDisplayName() { + return authorDisplayName == null ? DEFAULT_DISPLAY_NAME : authorDisplayName; + } + + public String getAuthorGitAuthorName() { + return authorGitAuthorName == null ? DEFAULT_GIT_AUTHOR_NAME : authorGitAuthorName; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportAuthorDetails) { + ReportAuthorDetails rad = (ReportAuthorDetails) obj; + return rad.getAuthorEmails().equals(this.getAuthorEmails()) + && rad.getAuthorGitHostId().equals(this.getAuthorGitHostId()) + && rad.getAuthorDisplayName().equals(this.getAuthorDisplayName()) + && rad.getAuthorGitAuthorName().equals(this.getAuthorGitAuthorName()); + } + + return false; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java index 687577b863..88cf71ef62 100644 --- a/src/main/java/reposense/model/reportconfig/ReportBranchData.java +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -1,5 +1,6 @@ package reposense.model.reportconfig; +import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,6 +10,9 @@ */ public class ReportBranchData { public static final String DEFAULT_BRANCH = "main"; + public static final List DEFAULT_REPORT_AUTHOR_DETAILS = new ArrayList<>( + ReportAuthorDetails.DEFAULT_INSTANCES + ); public static final List DEFAULT_FILE_FORMATS = List.of( "override:java", "md", "fxml" ); @@ -40,11 +44,15 @@ public class ReportBranchData { DEFAULT_INSTANCE.isFindPreviousAuthor = ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR; DEFAULT_INSTANCE.isShallowCloning = ReportBranchData.DEFAULT_IS_SHALLOW_CLONING; DEFAULT_INSTANCE.isIgnoreStandaloneConfig = ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG; + DEFAULT_INSTANCE.reportAuthorDetails = ReportAuthorDetails.DEFAULT_INSTANCES; } @JsonProperty("branch") private String branch; + @JsonProperty("authors") + private List reportAuthorDetails; + @JsonProperty("file-formats") private List fileFormats; @@ -70,6 +78,10 @@ public String getBranch() { return branch == null ? DEFAULT_BRANCH : branch; } + public List getReportAuthorDetails() { + return reportAuthorDetails == null ? DEFAULT_REPORT_AUTHOR_DETAILS : reportAuthorDetails; + } + public List getFileFormats() { return fileFormats == null ? DEFAULT_FILE_FORMATS : fileFormats; } @@ -107,6 +119,7 @@ public boolean equals(Object obj) { if (obj instanceof ReportBranchData) { ReportBranchData rbd = (ReportBranchData) obj; return this.getBranch().equals(rbd.getBranch()) + && this.getReportAuthorDetails().equals(rbd.getReportAuthorDetails()) && this.getFileFormats().equals(rbd.getFileFormats()) && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) && this.getIsIgnoreStandaloneConfig() == rbd.getIsIgnoreStandaloneConfig() diff --git a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java index 3a90009cad..375ce95653 100644 --- a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java @@ -10,12 +10,6 @@ */ public class ReportRepoConfiguration { public static final String DEFAULT_REPO = "https://github.com/user/repo"; - public static final List DEFAULT_AUTHOR_EMAIL = List.of( - "john@john.com", "johny@mail.com", "j@domain.com" - ); - public static final String DEFAULT_GIT_HOST_ID = "johnDoe"; - public static final String DEFAULT_DISPLAY_NAME = "John Doe"; - public static final String DEFAULT_GIT_AUTHOR_NAME = "my home PC"; public static final List DEFAULT_BRANCHES = List.of( ReportBranchData.DEFAULT_INSTANCE ); @@ -23,28 +17,12 @@ public class ReportRepoConfiguration { static { DEFAULT_INSTANCE.repo = DEFAULT_REPO; - DEFAULT_INSTANCE.authorEmails = DEFAULT_AUTHOR_EMAIL; - DEFAULT_INSTANCE.authorGitHostId = DEFAULT_GIT_HOST_ID; - DEFAULT_INSTANCE.authorDisplayName = DEFAULT_DISPLAY_NAME; - DEFAULT_INSTANCE.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME; DEFAULT_INSTANCE.branches = DEFAULT_BRANCHES; } @JsonProperty("repo") private String repo; - @JsonProperty("author-emails") - private List authorEmails; - - @JsonProperty("author-git-host-id") - private String authorGitHostId; - - @JsonProperty("author-display-name") - private String authorDisplayName; - - @JsonProperty("author-git-author-name") - private String authorGitAuthorName; - @JsonProperty("branches") private List branches; @@ -52,22 +30,6 @@ public String getRepo() { return repo == null ? DEFAULT_REPO : repo; } - public List getAuthorEmails() { - return authorEmails == null ? DEFAULT_AUTHOR_EMAIL : authorEmails; - } - - public String getAuthorGitHostId() { - return authorGitHostId == null ? DEFAULT_GIT_HOST_ID : authorGitHostId; - } - - public String getAuthorDisplayName() { - return authorDisplayName == null ? DEFAULT_DISPLAY_NAME : authorDisplayName; - } - - public String getAuthorGitAuthorName() { - return authorGitAuthorName == null ? DEFAULT_GIT_AUTHOR_NAME : authorGitAuthorName; - } - public List getBranches() { return branches == null ? DEFAULT_BRANCHES : branches; } @@ -81,10 +43,6 @@ public boolean equals(Object obj) { if (obj instanceof ReportRepoConfiguration) { ReportRepoConfiguration rrc = (ReportRepoConfiguration) obj; return rrc.getRepo().equals(this.getRepo()) - && rrc.getAuthorEmails().equals(this.getAuthorEmails()) - && rrc.getAuthorGitHostId().equals(this.getAuthorGitHostId()) - && rrc.getAuthorDisplayName().equals(this.getAuthorDisplayName()) - && rrc.getAuthorGitAuthorName().equals(this.getAuthorGitAuthorName()) && rrc.getBranches().equals(this.getBranches()); } diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index 1708f569bd..95399c0930 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -15,15 +15,16 @@ group-details: - "**.md" repos: - repo: https://github.com/user/repo/tree/fake-branch - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC branches: - branch: main + authors: + - author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com file-formats: - override:java - md diff --git a/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java b/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java new file mode 100644 index 0000000000..1e066fbde1 --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java @@ -0,0 +1,30 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportAuthorDetailsTest { + @Test + public void getAuthorEmails_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorEmails(), + ReportAuthorDetails.DEFAULT_AUTHOR_EMAIL); + } + + @Test + public void getAuthorGitHostId_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorGitHostId(), + ReportAuthorDetails.DEFAULT_GIT_HOST_ID); + } + + @Test + public void getAuthorDisplayName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorDisplayName(), + ReportAuthorDetails.DEFAULT_DISPLAY_NAME); + } + + @Test + public void getAuthorGitAuthorName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorGitAuthorName(), + ReportAuthorDetails.DEFAULT_GIT_AUTHOR_NAME); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java index 679e9ea88f..0c5b589e3c 100644 --- a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java @@ -9,30 +9,6 @@ public void getRepo_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getRepo(), ReportRepoConfiguration.DEFAULT_REPO); } - @Test - public void getAuthorEmails_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportRepoConfiguration().getAuthorEmails(), - ReportRepoConfiguration.DEFAULT_AUTHOR_EMAIL); - } - - @Test - public void getAuthorGitHostId_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportRepoConfiguration().getAuthorGitHostId(), - ReportRepoConfiguration.DEFAULT_GIT_HOST_ID); - } - - @Test - public void getAuthorDisplayName_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportRepoConfiguration().getAuthorDisplayName(), - ReportRepoConfiguration.DEFAULT_DISPLAY_NAME); - } - - @Test - public void getAuthorGitAuthorName_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportRepoConfiguration().getAuthorGitAuthorName(), - ReportRepoConfiguration.DEFAULT_GIT_AUTHOR_NAME); - } - @Test public void getBranches_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getBranches(), ReportRepoConfiguration.DEFAULT_BRANCHES); diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index 746b0493f6..5ff5b91dc0 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -15,15 +15,16 @@ group-details: - "**.md" repos: - repo: https://github.com/user/repo/tree/fake-branch - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC branches: - branch: main + authors: + - author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com file-formats: - override:java - md From c20e450c6169ff93ba744615948c6c9d920b2fb6 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 12 May 2024 20:18:25 +0800 Subject: [PATCH 06/12] Update docs for report-config.yaml --- docs/ug/configFiles.md | 33 ++++++++++++++++++++++++--------- docs/ug/report-config.yaml | 38 +++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/docs/ug/configFiles.md b/docs/ug/configFiles.md index 3c9585fb54..2b12def07d 100644 --- a/docs/ug/configFiles.md +++ b/docs/ug/configFiles.md @@ -113,16 +113,31 @@ You can also optionally use a `report-config.yaml` file to quickly define the re View this [example](report-config.yaml) for a better understanding of what repository information is required. +Note: All fields should be defined, and left blank if not used. + **Fields to provide**: -* `repoUrl`: The URL to your repository of interest -* `reportTitle`: Title of the generated report, which is also the title of the deployed dashboard. Default: "RepoSense Report" -* `authorDisplayName`: Name of the author to track in the repository. -* `authorGithubId`: The GitHub username of the author to track in the repository. -* `branches`: A list of branches with their associated blurbs. - * `name`: Name of the branch to track - * `blurb`: Blurb to include with the branch -* `startDate`: The start date of analysis for RepoSense. Default: "2020-01-01" -* `endDate`: The end date of analysis for RepoSense. Default: "9999-12-32" +* `title`: Title of the generated report, which is also the title of the deployed dashboard. Default: "RepoSense Report". +* `group-details`: Details regarding the different custom groupings of files in your repository (refer to the section on `group-config.csv` for more information). + * `repo`: The `Remote Repo URL` or `Disk Path` to the git repository. + * `groups`: A list of the different custom groupings. + * `group-name`: Name of the group. + * `globs`: The list of file path globs to include for specified group. +* `repos`: A list of repositories to include for analysis. + * `repo`: The URL to your repository of interest. + * `branches`: A list of branches to analyse for each repository. + * `branch`: The name of the branch. + * `authors`: A list of authors to analyse on the branch. + * `author-git-host-id`: Git host username of the author. + * `author-display-name`: Display name of the author. + * `author-git-author-name`: Author's Git host name. + * `author-emails`: A list of emails associated with an author. + * `file-formats`: File formats to analyze. + * `ignore-glob-list`: Folders/files to ignore, specified using the [_glob format_](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob). + * `ignore-standalone-config`: Ignores the different standalone configuration files when analysing this branch + * `ignore-commits-list`: The list of commits to ignore during analysis. For accurate results, the commits should be provided with their full hash. Additionally, a range of commits can be specified using the `..` notation e.g. `abc123..def456` (both inclusive). + * `ignore-authors-list`: The list of authors to ignore during analysis. Authors specified in `authors` field or `author-config.csv` will be also be omitted if they are in this list. Authors should be specified by their [Git Author Name](#a-note-about-git-author-name). + * `is-shallow-cloning`: Indicates whether to clone the repository using Git's shallow cloning functionality. + * `is-find-previous-authors`: Indicates whether to find previous authors of the repository/branch. diff --git a/docs/ug/report-config.yaml b/docs/ug/report-config.yaml index 4e430c7404..b5914b25ce 100644 --- a/docs/ug/report-config.yaml +++ b/docs/ug/report-config.yaml @@ -1,6 +1,6 @@ title: RepoSense Report group-details: - - repo: https://github.com/user/repo/tree/fake-branch + - repo: https://github.com/reposense/testrepo-Delta.git groups: - group-name: code globs: @@ -14,30 +14,30 @@ group-details: - "**.adoc" - "**.md" repos: - - repo: https://github.com/user/repo/tree/fake-branch - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC + - repo: https://github.com/reposense/testrepo-Delta.git branches: - - branch: main + - branch: master + authors: + - author-git-host-id: fzdy1914 + author-display-name: WANG CHAO + author-git-author-name: WANG CHAO + author-emails: + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - file-formats: - override:java - md - fxml ignore-glob-list: - - "docs**" - ignore-standalone-config: true + - + ignore-standalone-config: false ignore-commits-list: - - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 - - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 - - cd7f610e0becbdf331d5231887d8010a689f87c7 - - 768015345e70f06add2a8b7d1f901dc07bf70582 + - ignore-authors-list: - - author1 - - author2 - is-shallow-cloning: true + - + is-shallow-cloning: false is-find-previous-authors: false From 66cd7190e3169ecab759b0309313b77eccd6263b Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 12 May 2024 20:21:25 +0800 Subject: [PATCH 07/12] Update URLs --- src/systemtest/resources/ConfigSystemTest/report-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index 95399c0930..5d7a6d7079 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -1,6 +1,6 @@ title: RepoSense Report Test Title group-details: - - repo: https://github.com/user/repo/tree/fake-branch + - repo: https://github.com/user/repo.git groups: - group-name: code globs: @@ -14,7 +14,7 @@ group-details: - "**.adoc" - "**.md" repos: - - repo: https://github.com/user/repo/tree/fake-branch + - repo: https://github.com/user/repo.git branches: - branch: main authors: From 18772f07d32cce2e2748b5c094ea2e8f120fa848 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 9 Jun 2024 14:12:42 +0800 Subject: [PATCH 08/12] Update YAML Format --- config/report-config.yaml | 4 +- .../reportconfig/ReportConfiguration.java | 14 ++-- .../reportconfig/ReportGroupDetails.java | 49 ----------- .../reportconfig/ReportRepoConfiguration.java | 15 ++++ .../parser/ReportConfigYamlParser.java | 24 ++---- .../java/reposense/parser/YamlParser.java | 32 +++++++ .../30daysFromUntilDate/expected/summary.json | 83 ++++++++++++++++++- .../expected/summary.json | 83 ++++++++++++++++++- .../expected/summary.json | 83 ++++++++++++++++++- .../ConfigSystemTest/report-config.yaml | 6 +- .../expected/summary.json | 83 ++++++++++++++++++- .../expected/summary.json | 83 ++++++++++++++++++- .../expected/summary.json | 83 ++++++++++++++++++- .../reportconfig/ReportConfigurationTest.java | 6 -- .../reportconfig/ReportGroupDetailsTest.java | 23 ----- .../report-config-invalid.yaml | 40 ++++----- .../report-config-valid.yaml | 40 ++++----- 17 files changed, 590 insertions(+), 161 deletions(-) delete mode 100644 src/main/java/reposense/model/reportconfig/ReportGroupDetails.java create mode 100644 src/main/java/reposense/parser/YamlParser.java delete mode 100644 src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java diff --git a/config/report-config.yaml b/config/report-config.yaml index b5914b25ce..71b1bc3e00 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -1,5 +1,5 @@ title: RepoSense Report -group-details: +repos: - repo: https://github.com/reposense/testrepo-Delta.git groups: - group-name: code @@ -13,8 +13,6 @@ group-details: - "docs**" - "**.adoc" - "**.md" -repos: - - repo: https://github.com/reposense/testrepo-Delta.git branches: - branch: master authors: diff --git a/src/main/java/reposense/model/reportconfig/ReportConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java index fcaf682598..b91f4d4a08 100644 --- a/src/main/java/reposense/model/reportconfig/ReportConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java @@ -11,20 +11,15 @@ */ public class ReportConfiguration { public static final String DEFAULT_TITLE = "RepoSense Report"; - public static final List DEFAULT_REPORT_GROUP_DETAILS = new ArrayList<>(); public static final List DEFAULT_REPORT_REPO_CONFIGS = new ArrayList<>(); static { DEFAULT_REPORT_REPO_CONFIGS.add(ReportRepoConfiguration.DEFAULT_INSTANCE); - DEFAULT_REPORT_GROUP_DETAILS.add(ReportGroupDetails.DEFAULT_INSTANCE); } @JsonProperty("title") private String title; - @JsonProperty("group-details") - private List groupDetails; - @JsonProperty("repos") private List reportRepoConfigurations; @@ -32,10 +27,6 @@ public String getTitle() { return title == null ? DEFAULT_TITLE : title; } - public List getGroupDetails() { - return groupDetails == null ? DEFAULT_REPORT_GROUP_DETAILS : groupDetails; - } - public List getReportRepoConfigurations() { return reportRepoConfigurations == null ? DEFAULT_REPORT_REPO_CONFIGS : reportRepoConfigurations; } @@ -54,4 +45,9 @@ public boolean equals(Object obj) { return false; } + + @Override + public String toString() { + return title + "\n" + reportRepoConfigurations; + } } diff --git a/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java b/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java deleted file mode 100644 index 8310e86f49..0000000000 --- a/src/main/java/reposense/model/reportconfig/ReportGroupDetails.java +++ /dev/null @@ -1,49 +0,0 @@ -package reposense.model.reportconfig; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Contains information about the group contained in a particular repo. - */ -public class ReportGroupDetails { - public static final String DEFAULT_REPO = "https://github.com/user/repo/tree/fake-branch"; - public static final List DEFAULT_NAMES_AND_GLOBS = - ReportGroupNameAndGlobs.DEFAULT_INSTANCES; - public static final ReportGroupDetails DEFAULT_INSTANCE = new ReportGroupDetails(); - - static { - DEFAULT_INSTANCE.repo = DEFAULT_REPO; - DEFAULT_INSTANCE.reportGroupNameAndGlobsList = ReportGroupNameAndGlobs.DEFAULT_INSTANCES; - } - - @JsonProperty("repo") - private String repo; - - @JsonProperty("groups") - private List reportGroupNameAndGlobsList; - - public String getRepo() { - return repo == null ? DEFAULT_REPO : repo; - } - - public List getReportGroupNameAndGlobsList() { - return reportGroupNameAndGlobsList == null ? DEFAULT_NAMES_AND_GLOBS : reportGroupNameAndGlobsList; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (obj instanceof ReportGroupDetails) { - ReportGroupDetails rgd = (ReportGroupDetails) obj; - return this.getRepo().equals(rgd.getRepo()) - && this.getReportGroupNameAndGlobsList().equals(rgd.getReportGroupNameAndGlobsList()); - } - - return false; - } -} diff --git a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java index 375ce95653..9d14d2a5df 100644 --- a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java @@ -10,6 +10,7 @@ */ public class ReportRepoConfiguration { public static final String DEFAULT_REPO = "https://github.com/user/repo"; + public static final List DEFAULT_GROUP_DETAILS = ReportGroupNameAndGlobs.DEFAULT_INSTANCES; public static final List DEFAULT_BRANCHES = List.of( ReportBranchData.DEFAULT_INSTANCE ); @@ -17,12 +18,16 @@ public class ReportRepoConfiguration { static { DEFAULT_INSTANCE.repo = DEFAULT_REPO; + DEFAULT_INSTANCE.groups = DEFAULT_GROUP_DETAILS; DEFAULT_INSTANCE.branches = DEFAULT_BRANCHES; } @JsonProperty("repo") private String repo; + @JsonProperty("groups") + private List groups; + @JsonProperty("branches") private List branches; @@ -30,6 +35,10 @@ public String getRepo() { return repo == null ? DEFAULT_REPO : repo; } + public List getGroupDetails() { + return groups == null ? DEFAULT_GROUP_DETAILS : groups; + } + public List getBranches() { return branches == null ? DEFAULT_BRANCHES : branches; } @@ -43,9 +52,15 @@ public boolean equals(Object obj) { if (obj instanceof ReportRepoConfiguration) { ReportRepoConfiguration rrc = (ReportRepoConfiguration) obj; return rrc.getRepo().equals(this.getRepo()) + && rrc.getGroupDetails().equals(this.getGroupDetails()) && rrc.getBranches().equals(this.getBranches()); } return false; } + + @Override + public String toString() { + return repo + "\n" + groups + "\n" + branches; + } } diff --git a/src/main/java/reposense/parser/ReportConfigYamlParser.java b/src/main/java/reposense/parser/ReportConfigYamlParser.java index d584d8d40b..1cdceaa13a 100644 --- a/src/main/java/reposense/parser/ReportConfigYamlParser.java +++ b/src/main/java/reposense/parser/ReportConfigYamlParser.java @@ -5,40 +5,32 @@ import java.lang.reflect.Type; import java.nio.file.Path; import java.util.logging.Level; -import java.util.logging.Logger; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.google.gson.Gson; import reposense.model.reportconfig.ReportConfiguration; -import reposense.system.LogsManager; /** * YAML Parser for report-config.yaml files. */ -public class ReportConfigYamlParser extends JsonParser { +public class ReportConfigYamlParser extends YamlParser { public static final String REPORT_CONFIG_FILENAME = "report-config.yaml"; - private static final Logger logger = LogsManager.getLogger(ReportConfigYamlParser.class); @Override public Type getType() { return ReportConfiguration.class; } + /** + * Parses the YAML file at {@code path}. + * + * @param path Path to the YAML file + * @return Parsed {@code ReportConfiguration} object + * @throws IOException if the provided path is invalid + */ @Override public ReportConfiguration parse(Path path) throws IOException { - return this.fromJson(null, path, null); - } - - @Override - protected ReportConfiguration fromJson(Path path) throws IOException { - return this.fromJson(null, path, null); - } - - @Override - protected ReportConfiguration fromJson(Gson gson, Path path, Type type) throws IOException , JsonMappingException { // adapted from https://www.baeldung.com/jackson-yaml ReportConfiguration reportConfigation; diff --git a/src/main/java/reposense/parser/YamlParser.java b/src/main/java/reposense/parser/YamlParser.java new file mode 100644 index 0000000000..5c47407e18 --- /dev/null +++ b/src/main/java/reposense/parser/YamlParser.java @@ -0,0 +1,32 @@ +package reposense.parser; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Path; +import java.util.logging.Logger; + +import reposense.system.LogsManager; + +/** + * Represents a YAML parser that is able to parse a YAML file from a {@link Path} into an object of + * type {@code T}. + * + * @param Type {@code T} that this parser can parse and return as an object + */ +public abstract class YamlParser { + protected static final Logger logger = LogsManager.getLogger(YamlParser.class); + + /** + * Returns the type of {@code T} for YAML file conversion. + */ + public abstract Type getType(); + + /** + * Converts the YAML file from the given {@code path} into object of type {@code T} and return it. + * + * @param path Path to the YAML file + * @return Parsed object of type {@code T} + * @throws IOException if the {@code path} is invalid + */ + public abstract T parse(Path path) throws IOException; +} diff --git a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDate/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDate/expected/summary.json index c809a19ae0..b4a4475f8f 100644 --- a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDate/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDate/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-10-01","untilDate":"2017-11-01","isSinceDateProvided":false,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-10-01", + "untilDate": "2017-11-01", + "isSinceDateProvided": false, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateFindPreviousAuthors/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateFindPreviousAuthors/expected/summary.json index c809a19ae0..b4a4475f8f 100644 --- a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateFindPreviousAuthors/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateFindPreviousAuthors/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-10-01","untilDate":"2017-11-01","isSinceDateProvided":false,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-10-01", + "untilDate": "2017-11-01", + "isSinceDateProvided": false, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateWithShallowCloning/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateWithShallowCloning/expected/summary.json index c809a19ae0..b4a4475f8f 100644 --- a/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateWithShallowCloning/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/30daysFromUntilDateWithShallowCloning/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-10-01","untilDate":"2017-11-01","isSinceDateProvided":false,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-10-01", + "untilDate": "2017-11-01", + "isSinceDateProvided": false, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index 5d7a6d7079..1c6fed2d3c 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -1,5 +1,5 @@ -title: RepoSense Report Test Title -group-details: +title: RepoSense Report +repos: - repo: https://github.com/user/repo.git groups: - group-name: code @@ -13,8 +13,6 @@ group-details: - "docs**" - "**.adoc" - "**.md" -repos: - - repo: https://github.com/user/repo.git branches: - branch: main authors: diff --git a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRange/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRange/expected/summary.json index f0d69e7d5b..629c28d968 100644 --- a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRange/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRange/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-09-30","untilDate":"2019-03-02","isSinceDateProvided":true,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-09-30", + "untilDate": "2019-03-02", + "isSinceDateProvided": true, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeFindPreviousAuthors/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeFindPreviousAuthors/expected/summary.json index f0d69e7d5b..629c28d968 100644 --- a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeFindPreviousAuthors/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeFindPreviousAuthors/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-09-30","untilDate":"2019-03-02","isSinceDateProvided":true,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-09-30", + "untilDate": "2019-03-02", + "isSinceDateProvided": true, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeWithShallowCloning/expected/summary.json b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeWithShallowCloning/expected/summary.json index f0d69e7d5b..629c28d968 100644 --- a/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeWithShallowCloning/expected/summary.json +++ b/src/systemtest/resources/ConfigSystemTest/sinceBeginningDateRangeWithShallowCloning/expected/summary.json @@ -1 +1,82 @@ -{"reportGeneratedTime":"Tue Jul 24 17:45:15 SGT 2018","reportGenerationTime":"15 second(s)","zoneId":"Asia/Singapore","reportTitle":"RepoSense Report Test Title","repos":[{"location":{"location":"https://github.com/reposense/testrepo-Alpha.git","repoName":"testrepo-Alpha","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Alpha[master]","outputFolderName":"reposense_testrepo-Alpha_master"},{"location":{"location":"https://github.com/reposense/testrepo-Beta.git","repoName":"testrepo-Beta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Beta[master]","outputFolderName":"reposense_testrepo-Beta_master"},{"location":{"location":"https://github.com/reposense/testrepo-Charlie.git","repoName":"testrepo-Charlie","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Charlie[master]","outputFolderName":"reposense_testrepo-Charlie_master"},{"location":{"location":"https://github.com/reposense/testrepo-Delta.git","repoName":"testrepo-Delta","organization":"reposense","domainName":"github"},"branch":"master","displayName":"reposense/testrepo-Delta[master]","outputFolderName":"reposense_testrepo-Delta_master"}],"errorSet":[{"repoName":"ttps://github.com/reposense/testrepo-Beta.git","errorMessage":"ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL."},{"repoName":"reposense/testrepo-Delta[nonExistentBranch]","errorMessage":"Branch \"nonExistentBranch\" does not exist."}],"sinceDate":"2017-09-30","untilDate":"2019-03-02","isSinceDateProvided":true,"isUntilDateProvided":true,"supportedDomainUrlMap":{"NOT_RECOGNIZED":{"BRANCH":"","REPO_URL":"UNSUPPORTED","BASE_URL":"UNSUPPORTED","HISTORY_PATH":"","COMMIT_PATH":"","BLAME_PATH":""},"github":{"BRANCH":"tree/$BRANCH","REPO_URL":"https://github.com/$ORGANIZATION/$REPO_NAME/","BASE_URL":"https://github.com/","HISTORY_PATH":"commits/$BRANCH/$FILE_PATH","COMMIT_PATH":"commit/$COMMIT_HASH","BLAME_PATH":"blame/$BRANCH/$FILE_PATH"}}} +{ + "zoneId": "Asia/Singapore", + "reportTitle": "RepoSense Report", + "repos": [ + { + "location": { + "location": "https://github.com/reposense/testrepo-Alpha.git", + "repoName": "testrepo-Alpha", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Alpha[master]", + "outputFolderName": "reposense_testrepo-Alpha_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Beta.git", + "repoName": "testrepo-Beta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Beta[master]", + "outputFolderName": "reposense_testrepo-Beta_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Charlie.git", + "repoName": "testrepo-Charlie", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Charlie[master]", + "outputFolderName": "reposense_testrepo-Charlie_master" + }, + { + "location": { + "location": "https://github.com/reposense/testrepo-Delta.git", + "repoName": "testrepo-Delta", + "organization": "reposense", + "domainName": "github" + }, + "branch": "master", + "displayName": "reposense/testrepo-Delta[master]", + "outputFolderName": "reposense_testrepo-Delta_master" + } + ], + "errorSet": [ + { + "repoName": "ttps://github.com/reposense/testrepo-Beta.git", + "errorMessage": "ttps://github.com/reposense/testrepo-Beta.git is an invalid remote URL." + }, + { + "repoName": "reposense/testrepo-Delta[nonExistentBranch]", + "errorMessage": "Branch \"nonExistentBranch\" does not exist." + } + ], + "sinceDate": "2017-09-30", + "untilDate": "2019-03-02", + "isSinceDateProvided": true, + "isUntilDateProvided": true, + "supportedDomainUrlMap": { + "NOT_RECOGNIZED": { + "BRANCH": "", + "REPO_URL": "UNSUPPORTED", + "BASE_URL": "UNSUPPORTED", + "HISTORY_PATH": "", + "COMMIT_PATH": "", + "BLAME_PATH": "" + }, + "github": { + "BRANCH": "tree/$BRANCH", + "REPO_URL": "https://github.com/$ORGANIZATION/$REPO_NAME/", + "BASE_URL": "https://github.com/", + "HISTORY_PATH": "commits/$BRANCH/$FILE_PATH", + "COMMIT_PATH": "commit/$COMMIT_HASH", + "BLAME_PATH": "blame/$BRANCH/$FILE_PATH" + } + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java index 19a5fad8b3..935b0872ff 100644 --- a/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportConfigurationTest.java @@ -15,12 +15,6 @@ public void getReportRepoConfigurations_equalsDefaultReturnValue_success() { ReportConfiguration.DEFAULT_REPORT_REPO_CONFIGS); } - @Test - public void getGroupDetails_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportConfiguration().getGroupDetails(), - ReportConfiguration.DEFAULT_REPORT_GROUP_DETAILS); - } - @Test public void equals_defaultInstancesAreEqual_success() { Assertions.assertEquals(new ReportConfiguration(), new ReportConfiguration()); diff --git a/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java b/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java deleted file mode 100644 index d3df44380f..0000000000 --- a/src/test/java/reposense/model/reportconfig/ReportGroupDetailsTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package reposense.model.reportconfig; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class ReportGroupDetailsTest { - @Test - public void getRepo_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportGroupDetails().getRepo(), ReportGroupDetails.DEFAULT_REPO); - } - - @Test - public void getReportGroupNameAndGlobsList_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportGroupDetails().getReportGroupNameAndGlobsList(), - ReportGroupDetails.DEFAULT_NAMES_AND_GLOBS); - } - - @Test - public void equals_defaultInstancesAreEqual_success() { - Assertions.assertEquals(new ReportGroupDetails(), new ReportGroupDetails()); - Assertions.assertEquals(new ReportGroupDetails(), ReportGroupDetails.DEFAULT_INSTANCE); - } -} diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml index fda2a639be..bd6058f6c4 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml @@ -1,36 +1,30 @@ -title: RepoSense Report -group-details: - - repo: https://github.com/user/repo/tree/fake-branch - grou - - group-name: code +titles: RepoSense Report +repo: + - repos: https://github.com/reposense/testrepo-Delta.git + group: + - grame: code globs: - "**.java" - group-name: tests globs: - "src/test**" - group-name: docs - globs: + gl: - "docs**" - "**.adoc" - "**.md" -os: - - repo: https://github.com/user/repo/tree/fake-branch - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - author-git-author-name: my home PC - branches: - - branch: main + bhes: + - branch: master + autho:thor-name: WANG CHAO + author-emails: + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - file-formats: - override:java - md - - fxml - ignore-glob-list: - - "docs**" - ignore-standalone-config: true - ignore-author-list: - - author1 - - author2 - is-shallow-cloning: true + is-shallow-cloning: false is-find-previous-authors: false diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index 5ff5b91dc0..dea7a91415 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -1,6 +1,6 @@ -title: RepoSense Report Repo Test -group-details: - - repo: https://github.com/user/repo/tree/fake-branch +title: RepoSense Report Test Repo +repos: + - repo: https://github.com/reposense/testrepo-Delta.git groups: - group-name: code globs: @@ -13,33 +13,29 @@ group-details: - "docs**" - "**.adoc" - "**.md" -repos: - - repo: https://github.com/user/repo/tree/fake-branch branches: - - branch: main + - branch: master authors: - - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC + - author-git-host-id: fzdy1914 + author-display-name: WANG CHAO + author-git-author-name: WANG CHAO author-emails: - - john@john.com - - johny@mail.com - - j@domain.com + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - file-formats: - override:java - md - fxml ignore-glob-list: - - "docs**" - ignore-standalone-config: true + - + ignore-standalone-config: false ignore-commits-list: - - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 - - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 - - cd7f610e0becbdf331d5231887d8010a689f87c7 - - 768015345e70f06add2a8b7d1f901dc07bf70582 + - ignore-authors-list: - - author1 - - author2 - is-shallow-cloning: true + - + is-shallow-cloning: false is-find-previous-authors: false - From 587f1528f1d3400683e6c589be85d77f8cb0619f Mon Sep 17 00:00:00 2001 From: George Tay Date: Sat, 29 Jun 2024 22:02:26 +0800 Subject: [PATCH 09/12] Update YAML config file format --- config/report-config.yaml | 21 +---- .../reportconfig/ReportAuthorDetails.java | 94 ------------------- .../model/reportconfig/ReportBranchData.java | 79 ++-------------- .../ConfigSystemTest/report-config.yaml | 21 +---- .../reportconfig/ReportAuthorDetailsTest.java | 30 ------ .../reportconfig/ReportBranchDataTest.java | 29 ------ .../report-config-valid.yaml | 21 +---- 7 files changed, 12 insertions(+), 283 deletions(-) delete mode 100644 src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java delete mode 100644 src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java diff --git a/config/report-config.yaml b/config/report-config.yaml index 71b1bc3e00..d7bda4334c 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -15,27 +15,8 @@ repos: - "**.md" branches: - branch: master - authors: - - author-git-host-id: fzdy1914 - author-display-name: WANG CHAO - author-git-author-name: WANG CHAO - author-emails: - - 1229983126@qq.com - - author-git-host-id: FH-30 - author-display-name: Francis Hodianto - author-git-author-name: Francis Hodianto - author-emails: - - - file-formats: - - override:java - - md - - fxml + blurb: ignore-glob-list: - - ignore-standalone-config: false - ignore-commits-list: - - ignore-authors-list: - - is-shallow-cloning: false - is-find-previous-authors: false diff --git a/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java b/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java deleted file mode 100644 index af5d41662f..0000000000 --- a/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java +++ /dev/null @@ -1,94 +0,0 @@ -package reposense.model.reportconfig; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Represents an author's details in the report-config.yaml file. - */ -public class ReportAuthorDetails { - public static final List DEFAULT_INSTANCES = new ArrayList<>(); - - public static final List DEFAULT_AUTHOR_EMAIL = List.of("john@john.com", "johny@mail.com", "j@domain.com"); - public static final String DEFAULT_GIT_HOST_ID = "johnDoe"; - public static final String DEFAULT_DISPLAY_NAME = "John Doe"; - public static final String DEFAULT_GIT_AUTHOR_NAME = "my home PC"; - - private static final List DEFAULT_AUTHOR_EMAIL_1 = List.of("1229983126@qq.com"); - private static final String DEFAULT_GIT_HOST_ID_1 = "fzdy1914"; - private static final String DEFAULT_DISPLAY_NAME_1 = "WANG CHAO"; - private static final String DEFAULT_GIT_AUTHOR_NAME_1 = "WANG CHAO"; - private static final List DEFAULT_AUTHOR_EMAIL_2 = List.of(""); - private static final String DEFAULT_GIT_HOST_ID_2 = "FH-30"; - private static final String DEFAULT_DISPLAY_NAME_2 = "Francis Hodianto"; - private static final String DEFAULT_GIT_AUTHOR_NAME_2 = "Francis Hodianto"; - - static { - ReportAuthorDetails rad1 = new ReportAuthorDetails(); - ReportAuthorDetails rad2 = new ReportAuthorDetails(); - - rad1.authorEmails = DEFAULT_AUTHOR_EMAIL_1; - rad1.authorGitHostId = DEFAULT_GIT_HOST_ID_1; - rad1.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_1; - rad1.authorDisplayName = DEFAULT_DISPLAY_NAME_1; - - rad2.authorEmails = DEFAULT_AUTHOR_EMAIL_2; - rad2.authorGitHostId = DEFAULT_GIT_HOST_ID_2; - rad2.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_2; - rad2.authorDisplayName = DEFAULT_DISPLAY_NAME_2; - - DEFAULT_INSTANCES.add(rad1); - DEFAULT_INSTANCES.add(rad2); - } - - @JsonProperty("author-emails") - private List authorEmails; - - @JsonProperty("author-git-host-id") - private String authorGitHostId; - - @JsonProperty("author-display-name") - private String authorDisplayName; - - @JsonProperty("author-git-author-name") - private String authorGitAuthorName; - - public ReportAuthorDetails() { - - } - - public List getAuthorEmails() { - return authorEmails == null ? DEFAULT_AUTHOR_EMAIL : authorEmails; - } - - public String getAuthorGitHostId() { - return authorGitHostId == null ? DEFAULT_GIT_HOST_ID : authorGitHostId; - } - - public String getAuthorDisplayName() { - return authorDisplayName == null ? DEFAULT_DISPLAY_NAME : authorDisplayName; - } - - public String getAuthorGitAuthorName() { - return authorGitAuthorName == null ? DEFAULT_GIT_AUTHOR_NAME : authorGitAuthorName; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (obj instanceof ReportAuthorDetails) { - ReportAuthorDetails rad = (ReportAuthorDetails) obj; - return rad.getAuthorEmails().equals(this.getAuthorEmails()) - && rad.getAuthorGitHostId().equals(this.getAuthorGitHostId()) - && rad.getAuthorDisplayName().equals(this.getAuthorDisplayName()) - && rad.getAuthorGitAuthorName().equals(this.getAuthorGitAuthorName()); - } - - return false; - } -} diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java index 88cf71ef62..27d7e07377 100644 --- a/src/main/java/reposense/model/reportconfig/ReportBranchData.java +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -1,6 +1,5 @@ package reposense.model.reportconfig; -import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; @@ -10,106 +9,51 @@ */ public class ReportBranchData { public static final String DEFAULT_BRANCH = "main"; - public static final List DEFAULT_REPORT_AUTHOR_DETAILS = new ArrayList<>( - ReportAuthorDetails.DEFAULT_INSTANCES - ); - public static final List DEFAULT_FILE_FORMATS = List.of( - "override:java", "md", "fxml" - ); + public static final String DEFAULT_BLURB = ""; public static final List DEFAULT_IGNORE_GLOB_LIST = List.of( "docs**" ); - public static final List DEFAULT_IGNORE_COMMITS_LIST = List.of( - "2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7", - "c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151", - "cd7f610e0becbdf331d5231887d8010a689f87c7", - "768015345e70f06add2a8b7d1f901dc07bf70582" - ); public static final List DEFAULT_IGNORE_AUTHORS_LIST = List.of( "author1", "author2" ); - public static final boolean DEFAULT_IS_FIND_PREVIOUS_AUTHOR = false; - public static final boolean DEFAULT_IS_SHALLOW_CLONING = true; - public static final boolean DEFAULT_IS_IGNORE_STANDALONE_CONFIG = true; - public static final ReportBranchData DEFAULT_INSTANCE = new ReportBranchData(); static { DEFAULT_INSTANCE.branch = ReportBranchData.DEFAULT_BRANCH; - DEFAULT_INSTANCE.fileFormats = ReportBranchData.DEFAULT_FILE_FORMATS; + DEFAULT_INSTANCE.blurb = ReportBranchData.DEFAULT_BLURB; DEFAULT_INSTANCE.ignoreGlobList = ReportBranchData.DEFAULT_IGNORE_GLOB_LIST; - DEFAULT_INSTANCE.ignoreCommitList = ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST; DEFAULT_INSTANCE.ignoreAuthorList = ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST; - DEFAULT_INSTANCE.isFindPreviousAuthor = ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR; - DEFAULT_INSTANCE.isShallowCloning = ReportBranchData.DEFAULT_IS_SHALLOW_CLONING; - DEFAULT_INSTANCE.isIgnoreStandaloneConfig = ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG; - DEFAULT_INSTANCE.reportAuthorDetails = ReportAuthorDetails.DEFAULT_INSTANCES; } @JsonProperty("branch") private String branch; - @JsonProperty("authors") - private List reportAuthorDetails; - - @JsonProperty("file-formats") - private List fileFormats; + @JsonProperty("blurb") + private String blurb; @JsonProperty("ignore-glob-list") private List ignoreGlobList; - @JsonProperty("ignore-standalone-config") - private Boolean isIgnoreStandaloneConfig; - - @JsonProperty("ignore-commits-list") - private List ignoreCommitList; - @JsonProperty("ignore-authors-list") private List ignoreAuthorList; - @JsonProperty("is-shallow-cloning") - private Boolean isShallowCloning; - - @JsonProperty("is-find-previous-authors") - private Boolean isFindPreviousAuthor; - public String getBranch() { return branch == null ? DEFAULT_BRANCH : branch; } - public List getReportAuthorDetails() { - return reportAuthorDetails == null ? DEFAULT_REPORT_AUTHOR_DETAILS : reportAuthorDetails; - } - - public List getFileFormats() { - return fileFormats == null ? DEFAULT_FILE_FORMATS : fileFormats; + public String getBlurb() { + return blurb == null ? DEFAULT_BLURB : blurb; } public List getIgnoreGlobList() { - return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : fileFormats; - } - - public boolean getIsIgnoreStandaloneConfig() { - return isIgnoreStandaloneConfig == null ? DEFAULT_IS_IGNORE_STANDALONE_CONFIG : isIgnoreStandaloneConfig; - } - - public List getIgnoreCommitList() { - return ignoreCommitList == null ? DEFAULT_IGNORE_COMMITS_LIST : ignoreCommitList; + return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : ignoreGlobList; } public List getIgnoreAuthorList() { return ignoreAuthorList == null ? DEFAULT_IGNORE_AUTHORS_LIST : ignoreAuthorList; } - public boolean getIsShallowCloning() { - return isShallowCloning == null ? DEFAULT_IS_SHALLOW_CLONING : isShallowCloning; - } - - public boolean getIsFindPreviousAuthor() { - return isFindPreviousAuthor == null ? DEFAULT_IS_FIND_PREVIOUS_AUTHOR : isFindPreviousAuthor; - } - @Override public boolean equals(Object obj) { if (obj == this) { @@ -119,14 +63,9 @@ public boolean equals(Object obj) { if (obj instanceof ReportBranchData) { ReportBranchData rbd = (ReportBranchData) obj; return this.getBranch().equals(rbd.getBranch()) - && this.getReportAuthorDetails().equals(rbd.getReportAuthorDetails()) - && this.getFileFormats().equals(rbd.getFileFormats()) + && this.getBlurb().equals(rbd.getBlurb()) && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) - && this.getIsIgnoreStandaloneConfig() == rbd.getIsIgnoreStandaloneConfig() - && this.getIgnoreCommitList().equals(rbd.getIgnoreCommitList()) - && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()) - && this.getIsShallowCloning() == rbd.getIsShallowCloning() - && this.getIsFindPreviousAuthor() == rbd.getIsFindPreviousAuthor(); + && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()); } return false; diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index f0eb63aafc..fdcdf7cb9f 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -15,28 +15,9 @@ repos: - "**.md" branches: - branch: main - authors: - - author-git-host-id: johnDoe - author-display-name: John Doe - author-git-author-name: my home PC - author-emails: - - john@john.com - - johny@mail.com - - j@domain.com - file-formats: - - override:java - - md - - fxml + blurb: ignore-glob-list: - "docs**" - ignore-standalone-config: true - ignore-commits-list: - - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 - - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 - - cd7f610e0becbdf331d5231887d8010a689f87c7 - - 768015345e70f06add2a8b7d1f901dc07bf70582 ignore-authors-list: - author1 - author2 - is-shallow-cloning: true - is-find-previous-authors: false diff --git a/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java b/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java deleted file mode 100644 index 1e066fbde1..0000000000 --- a/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package reposense.model.reportconfig; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class ReportAuthorDetailsTest { - @Test - public void getAuthorEmails_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportAuthorDetails().getAuthorEmails(), - ReportAuthorDetails.DEFAULT_AUTHOR_EMAIL); - } - - @Test - public void getAuthorGitHostId_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportAuthorDetails().getAuthorGitHostId(), - ReportAuthorDetails.DEFAULT_GIT_HOST_ID); - } - - @Test - public void getAuthorDisplayName_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportAuthorDetails().getAuthorDisplayName(), - ReportAuthorDetails.DEFAULT_DISPLAY_NAME); - } - - @Test - public void getAuthorGitAuthorName_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportAuthorDetails().getAuthorGitAuthorName(), - ReportAuthorDetails.DEFAULT_GIT_AUTHOR_NAME); - } -} diff --git a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java index 70302084c2..79b9a49ef6 100644 --- a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java @@ -9,46 +9,17 @@ public void getBranch_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getBranch(), ReportBranchData.DEFAULT_BRANCH); } - @Test - public void getFileFormats_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getFileFormats(), ReportBranchData.DEFAULT_FILE_FORMATS); - } - @Test public void getIgnoreGlobList_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getIgnoreGlobList(), ReportBranchData.DEFAULT_IGNORE_GLOB_LIST); } - @Test - public void getIsIgnoreStandaloneConfig_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsIgnoreStandaloneConfig(), - ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG); - } - - @Test - public void getIgnoreCommitList_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIgnoreCommitList(), - ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST); - } - @Test public void getIgnoreAuthorList_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getIgnoreAuthorList(), ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST); } - @Test - public void getIsShallowCloning_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsShallowCloning(), - ReportBranchData.DEFAULT_IS_SHALLOW_CLONING); - } - - @Test - public void getIsFindPreviousAuthor_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsFindPreviousAuthor(), - ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR); - } - @Test public void equals_defaultInstancesAreEqual_success() { Assertions.assertEquals(new ReportBranchData(), new ReportBranchData()); diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index dea7a91415..3957c75ec8 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -15,27 +15,8 @@ repos: - "**.md" branches: - branch: master - authors: - - author-git-host-id: fzdy1914 - author-display-name: WANG CHAO - author-git-author-name: WANG CHAO - author-emails: - - 1229983126@qq.com - - author-git-host-id: FH-30 - author-display-name: Francis Hodianto - author-git-author-name: Francis Hodianto - author-emails: - - - file-formats: - - override:java - - md - - fxml + blurb: ignore-glob-list: - - ignore-standalone-config: false - ignore-commits-list: - - ignore-authors-list: - - is-shallow-cloning: false - is-find-previous-authors: false From cc151f489c0ca295ee0c16b97596ca3359f23a54 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 14 Jul 2024 17:41:33 +0800 Subject: [PATCH 10/12] Revert "Update YAML config file format" This reverts commit 587f1528f1d3400683e6c589be85d77f8cb0619f. --- config/report-config.yaml | 21 ++++- .../reportconfig/ReportAuthorDetails.java | 94 +++++++++++++++++++ .../model/reportconfig/ReportBranchData.java | 79 ++++++++++++++-- .../ConfigSystemTest/report-config.yaml | 21 ++++- .../reportconfig/ReportAuthorDetailsTest.java | 30 ++++++ .../reportconfig/ReportBranchDataTest.java | 29 ++++++ .../report-config-valid.yaml | 21 ++++- 7 files changed, 283 insertions(+), 12 deletions(-) create mode 100644 src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java create mode 100644 src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java diff --git a/config/report-config.yaml b/config/report-config.yaml index d7bda4334c..71b1bc3e00 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -15,8 +15,27 @@ repos: - "**.md" branches: - branch: master - blurb: + authors: + - author-git-host-id: fzdy1914 + author-display-name: WANG CHAO + author-git-author-name: WANG CHAO + author-emails: + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - + file-formats: + - override:java + - md + - fxml ignore-glob-list: - + ignore-standalone-config: false + ignore-commits-list: + - ignore-authors-list: - + is-shallow-cloning: false + is-find-previous-authors: false diff --git a/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java b/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java new file mode 100644 index 0000000000..af5d41662f --- /dev/null +++ b/src/main/java/reposense/model/reportconfig/ReportAuthorDetails.java @@ -0,0 +1,94 @@ +package reposense.model.reportconfig; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents an author's details in the report-config.yaml file. + */ +public class ReportAuthorDetails { + public static final List DEFAULT_INSTANCES = new ArrayList<>(); + + public static final List DEFAULT_AUTHOR_EMAIL = List.of("john@john.com", "johny@mail.com", "j@domain.com"); + public static final String DEFAULT_GIT_HOST_ID = "johnDoe"; + public static final String DEFAULT_DISPLAY_NAME = "John Doe"; + public static final String DEFAULT_GIT_AUTHOR_NAME = "my home PC"; + + private static final List DEFAULT_AUTHOR_EMAIL_1 = List.of("1229983126@qq.com"); + private static final String DEFAULT_GIT_HOST_ID_1 = "fzdy1914"; + private static final String DEFAULT_DISPLAY_NAME_1 = "WANG CHAO"; + private static final String DEFAULT_GIT_AUTHOR_NAME_1 = "WANG CHAO"; + private static final List DEFAULT_AUTHOR_EMAIL_2 = List.of(""); + private static final String DEFAULT_GIT_HOST_ID_2 = "FH-30"; + private static final String DEFAULT_DISPLAY_NAME_2 = "Francis Hodianto"; + private static final String DEFAULT_GIT_AUTHOR_NAME_2 = "Francis Hodianto"; + + static { + ReportAuthorDetails rad1 = new ReportAuthorDetails(); + ReportAuthorDetails rad2 = new ReportAuthorDetails(); + + rad1.authorEmails = DEFAULT_AUTHOR_EMAIL_1; + rad1.authorGitHostId = DEFAULT_GIT_HOST_ID_1; + rad1.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_1; + rad1.authorDisplayName = DEFAULT_DISPLAY_NAME_1; + + rad2.authorEmails = DEFAULT_AUTHOR_EMAIL_2; + rad2.authorGitHostId = DEFAULT_GIT_HOST_ID_2; + rad2.authorGitAuthorName = DEFAULT_GIT_AUTHOR_NAME_2; + rad2.authorDisplayName = DEFAULT_DISPLAY_NAME_2; + + DEFAULT_INSTANCES.add(rad1); + DEFAULT_INSTANCES.add(rad2); + } + + @JsonProperty("author-emails") + private List authorEmails; + + @JsonProperty("author-git-host-id") + private String authorGitHostId; + + @JsonProperty("author-display-name") + private String authorDisplayName; + + @JsonProperty("author-git-author-name") + private String authorGitAuthorName; + + public ReportAuthorDetails() { + + } + + public List getAuthorEmails() { + return authorEmails == null ? DEFAULT_AUTHOR_EMAIL : authorEmails; + } + + public String getAuthorGitHostId() { + return authorGitHostId == null ? DEFAULT_GIT_HOST_ID : authorGitHostId; + } + + public String getAuthorDisplayName() { + return authorDisplayName == null ? DEFAULT_DISPLAY_NAME : authorDisplayName; + } + + public String getAuthorGitAuthorName() { + return authorGitAuthorName == null ? DEFAULT_GIT_AUTHOR_NAME : authorGitAuthorName; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof ReportAuthorDetails) { + ReportAuthorDetails rad = (ReportAuthorDetails) obj; + return rad.getAuthorEmails().equals(this.getAuthorEmails()) + && rad.getAuthorGitHostId().equals(this.getAuthorGitHostId()) + && rad.getAuthorDisplayName().equals(this.getAuthorDisplayName()) + && rad.getAuthorGitAuthorName().equals(this.getAuthorGitAuthorName()); + } + + return false; + } +} diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java index 27d7e07377..88cf71ef62 100644 --- a/src/main/java/reposense/model/reportconfig/ReportBranchData.java +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -1,5 +1,6 @@ package reposense.model.reportconfig; +import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,51 +10,106 @@ */ public class ReportBranchData { public static final String DEFAULT_BRANCH = "main"; - public static final String DEFAULT_BLURB = ""; + public static final List DEFAULT_REPORT_AUTHOR_DETAILS = new ArrayList<>( + ReportAuthorDetails.DEFAULT_INSTANCES + ); + public static final List DEFAULT_FILE_FORMATS = List.of( + "override:java", "md", "fxml" + ); public static final List DEFAULT_IGNORE_GLOB_LIST = List.of( "docs**" ); + public static final List DEFAULT_IGNORE_COMMITS_LIST = List.of( + "2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7", + "c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151", + "cd7f610e0becbdf331d5231887d8010a689f87c7", + "768015345e70f06add2a8b7d1f901dc07bf70582" + ); public static final List DEFAULT_IGNORE_AUTHORS_LIST = List.of( "author1", "author2" ); + public static final boolean DEFAULT_IS_FIND_PREVIOUS_AUTHOR = false; + public static final boolean DEFAULT_IS_SHALLOW_CLONING = true; + public static final boolean DEFAULT_IS_IGNORE_STANDALONE_CONFIG = true; + public static final ReportBranchData DEFAULT_INSTANCE = new ReportBranchData(); static { DEFAULT_INSTANCE.branch = ReportBranchData.DEFAULT_BRANCH; - DEFAULT_INSTANCE.blurb = ReportBranchData.DEFAULT_BLURB; + DEFAULT_INSTANCE.fileFormats = ReportBranchData.DEFAULT_FILE_FORMATS; DEFAULT_INSTANCE.ignoreGlobList = ReportBranchData.DEFAULT_IGNORE_GLOB_LIST; + DEFAULT_INSTANCE.ignoreCommitList = ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST; DEFAULT_INSTANCE.ignoreAuthorList = ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST; + DEFAULT_INSTANCE.isFindPreviousAuthor = ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR; + DEFAULT_INSTANCE.isShallowCloning = ReportBranchData.DEFAULT_IS_SHALLOW_CLONING; + DEFAULT_INSTANCE.isIgnoreStandaloneConfig = ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG; + DEFAULT_INSTANCE.reportAuthorDetails = ReportAuthorDetails.DEFAULT_INSTANCES; } @JsonProperty("branch") private String branch; - @JsonProperty("blurb") - private String blurb; + @JsonProperty("authors") + private List reportAuthorDetails; + + @JsonProperty("file-formats") + private List fileFormats; @JsonProperty("ignore-glob-list") private List ignoreGlobList; + @JsonProperty("ignore-standalone-config") + private Boolean isIgnoreStandaloneConfig; + + @JsonProperty("ignore-commits-list") + private List ignoreCommitList; + @JsonProperty("ignore-authors-list") private List ignoreAuthorList; + @JsonProperty("is-shallow-cloning") + private Boolean isShallowCloning; + + @JsonProperty("is-find-previous-authors") + private Boolean isFindPreviousAuthor; + public String getBranch() { return branch == null ? DEFAULT_BRANCH : branch; } - public String getBlurb() { - return blurb == null ? DEFAULT_BLURB : blurb; + public List getReportAuthorDetails() { + return reportAuthorDetails == null ? DEFAULT_REPORT_AUTHOR_DETAILS : reportAuthorDetails; + } + + public List getFileFormats() { + return fileFormats == null ? DEFAULT_FILE_FORMATS : fileFormats; } public List getIgnoreGlobList() { - return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : ignoreGlobList; + return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : fileFormats; + } + + public boolean getIsIgnoreStandaloneConfig() { + return isIgnoreStandaloneConfig == null ? DEFAULT_IS_IGNORE_STANDALONE_CONFIG : isIgnoreStandaloneConfig; + } + + public List getIgnoreCommitList() { + return ignoreCommitList == null ? DEFAULT_IGNORE_COMMITS_LIST : ignoreCommitList; } public List getIgnoreAuthorList() { return ignoreAuthorList == null ? DEFAULT_IGNORE_AUTHORS_LIST : ignoreAuthorList; } + public boolean getIsShallowCloning() { + return isShallowCloning == null ? DEFAULT_IS_SHALLOW_CLONING : isShallowCloning; + } + + public boolean getIsFindPreviousAuthor() { + return isFindPreviousAuthor == null ? DEFAULT_IS_FIND_PREVIOUS_AUTHOR : isFindPreviousAuthor; + } + @Override public boolean equals(Object obj) { if (obj == this) { @@ -63,9 +119,14 @@ public boolean equals(Object obj) { if (obj instanceof ReportBranchData) { ReportBranchData rbd = (ReportBranchData) obj; return this.getBranch().equals(rbd.getBranch()) - && this.getBlurb().equals(rbd.getBlurb()) + && this.getReportAuthorDetails().equals(rbd.getReportAuthorDetails()) + && this.getFileFormats().equals(rbd.getFileFormats()) && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) - && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()); + && this.getIsIgnoreStandaloneConfig() == rbd.getIsIgnoreStandaloneConfig() + && this.getIgnoreCommitList().equals(rbd.getIgnoreCommitList()) + && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()) + && this.getIsShallowCloning() == rbd.getIsShallowCloning() + && this.getIsFindPreviousAuthor() == rbd.getIsFindPreviousAuthor(); } return false; diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index fdcdf7cb9f..f0eb63aafc 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -15,9 +15,28 @@ repos: - "**.md" branches: - branch: main - blurb: + authors: + - author-git-host-id: johnDoe + author-display-name: John Doe + author-git-author-name: my home PC + author-emails: + - john@john.com + - johny@mail.com + - j@domain.com + file-formats: + - override:java + - md + - fxml ignore-glob-list: - "docs**" + ignore-standalone-config: true + ignore-commits-list: + - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 + - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 + - cd7f610e0becbdf331d5231887d8010a689f87c7 + - 768015345e70f06add2a8b7d1f901dc07bf70582 ignore-authors-list: - author1 - author2 + is-shallow-cloning: true + is-find-previous-authors: false diff --git a/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java b/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java new file mode 100644 index 0000000000..1e066fbde1 --- /dev/null +++ b/src/test/java/reposense/model/reportconfig/ReportAuthorDetailsTest.java @@ -0,0 +1,30 @@ +package reposense.model.reportconfig; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ReportAuthorDetailsTest { + @Test + public void getAuthorEmails_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorEmails(), + ReportAuthorDetails.DEFAULT_AUTHOR_EMAIL); + } + + @Test + public void getAuthorGitHostId_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorGitHostId(), + ReportAuthorDetails.DEFAULT_GIT_HOST_ID); + } + + @Test + public void getAuthorDisplayName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorDisplayName(), + ReportAuthorDetails.DEFAULT_DISPLAY_NAME); + } + + @Test + public void getAuthorGitAuthorName_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportAuthorDetails().getAuthorGitAuthorName(), + ReportAuthorDetails.DEFAULT_GIT_AUTHOR_NAME); + } +} diff --git a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java index 79b9a49ef6..70302084c2 100644 --- a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java @@ -9,17 +9,46 @@ public void getBranch_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getBranch(), ReportBranchData.DEFAULT_BRANCH); } + @Test + public void getFileFormats_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getFileFormats(), ReportBranchData.DEFAULT_FILE_FORMATS); + } + @Test public void getIgnoreGlobList_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getIgnoreGlobList(), ReportBranchData.DEFAULT_IGNORE_GLOB_LIST); } + @Test + public void getIsIgnoreStandaloneConfig_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsIgnoreStandaloneConfig(), + ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG); + } + + @Test + public void getIgnoreCommitList_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIgnoreCommitList(), + ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST); + } + @Test public void getIgnoreAuthorList_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getIgnoreAuthorList(), ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST); } + @Test + public void getIsShallowCloning_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsShallowCloning(), + ReportBranchData.DEFAULT_IS_SHALLOW_CLONING); + } + + @Test + public void getIsFindPreviousAuthor_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportBranchData().getIsFindPreviousAuthor(), + ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR); + } + @Test public void equals_defaultInstancesAreEqual_success() { Assertions.assertEquals(new ReportBranchData(), new ReportBranchData()); diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index 3957c75ec8..dea7a91415 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -15,8 +15,27 @@ repos: - "**.md" branches: - branch: master - blurb: + authors: + - author-git-host-id: fzdy1914 + author-display-name: WANG CHAO + author-git-author-name: WANG CHAO + author-emails: + - 1229983126@qq.com + - author-git-host-id: FH-30 + author-display-name: Francis Hodianto + author-git-author-name: Francis Hodianto + author-emails: + - + file-formats: + - override:java + - md + - fxml ignore-glob-list: - + ignore-standalone-config: false + ignore-commits-list: + - ignore-authors-list: - + is-shallow-cloning: false + is-find-previous-authors: false From 645b4c78023a636b9c79dc355b6247b175eac289 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sun, 14 Jul 2024 18:25:08 +0800 Subject: [PATCH 11/12] Update Report Configuration YAML File Format --- config/report-config.yaml | 10 +-- .../model/reportconfig/ReportBranchData.java | 61 +------------------ .../reportconfig/ReportRepoConfiguration.java | 10 +++ .../ConfigSystemTest/report-config.yaml | 13 +--- .../reportconfig/ReportBranchDataTest.java | 28 --------- .../ReportRepoConfigurationTest.java | 5 ++ .../report-config-invalid.yaml | 1 + .../report-config-valid.yaml | 10 +-- 8 files changed, 21 insertions(+), 117 deletions(-) diff --git a/config/report-config.yaml b/config/report-config.yaml index 71b1bc3e00..e410a3629a 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -1,6 +1,7 @@ title: RepoSense Report repos: - repo: https://github.com/reposense/testrepo-Delta.git + blurb: "My project" groups: - group-name: code globs: @@ -26,16 +27,7 @@ repos: author-git-author-name: Francis Hodianto author-emails: - - file-formats: - - override:java - - md - - fxml ignore-glob-list: - - ignore-standalone-config: false - ignore-commits-list: - - ignore-authors-list: - - is-shallow-cloning: false - is-find-previous-authors: false diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java index 88cf71ef62..b77db292f8 100644 --- a/src/main/java/reposense/model/reportconfig/ReportBranchData.java +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -13,37 +13,20 @@ public class ReportBranchData { public static final List DEFAULT_REPORT_AUTHOR_DETAILS = new ArrayList<>( ReportAuthorDetails.DEFAULT_INSTANCES ); - public static final List DEFAULT_FILE_FORMATS = List.of( - "override:java", "md", "fxml" - ); public static final List DEFAULT_IGNORE_GLOB_LIST = List.of( "docs**" ); - public static final List DEFAULT_IGNORE_COMMITS_LIST = List.of( - "2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7", - "c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151", - "cd7f610e0becbdf331d5231887d8010a689f87c7", - "768015345e70f06add2a8b7d1f901dc07bf70582" - ); public static final List DEFAULT_IGNORE_AUTHORS_LIST = List.of( "author1", "author2" ); - public static final boolean DEFAULT_IS_FIND_PREVIOUS_AUTHOR = false; - public static final boolean DEFAULT_IS_SHALLOW_CLONING = true; - public static final boolean DEFAULT_IS_IGNORE_STANDALONE_CONFIG = true; public static final ReportBranchData DEFAULT_INSTANCE = new ReportBranchData(); static { DEFAULT_INSTANCE.branch = ReportBranchData.DEFAULT_BRANCH; - DEFAULT_INSTANCE.fileFormats = ReportBranchData.DEFAULT_FILE_FORMATS; DEFAULT_INSTANCE.ignoreGlobList = ReportBranchData.DEFAULT_IGNORE_GLOB_LIST; - DEFAULT_INSTANCE.ignoreCommitList = ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST; DEFAULT_INSTANCE.ignoreAuthorList = ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST; - DEFAULT_INSTANCE.isFindPreviousAuthor = ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR; - DEFAULT_INSTANCE.isShallowCloning = ReportBranchData.DEFAULT_IS_SHALLOW_CLONING; - DEFAULT_INSTANCE.isIgnoreStandaloneConfig = ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG; DEFAULT_INSTANCE.reportAuthorDetails = ReportAuthorDetails.DEFAULT_INSTANCES; } @@ -53,27 +36,12 @@ public class ReportBranchData { @JsonProperty("authors") private List reportAuthorDetails; - @JsonProperty("file-formats") - private List fileFormats; - @JsonProperty("ignore-glob-list") private List ignoreGlobList; - @JsonProperty("ignore-standalone-config") - private Boolean isIgnoreStandaloneConfig; - - @JsonProperty("ignore-commits-list") - private List ignoreCommitList; - @JsonProperty("ignore-authors-list") private List ignoreAuthorList; - @JsonProperty("is-shallow-cloning") - private Boolean isShallowCloning; - - @JsonProperty("is-find-previous-authors") - private Boolean isFindPreviousAuthor; - public String getBranch() { return branch == null ? DEFAULT_BRANCH : branch; } @@ -82,34 +50,14 @@ public List getReportAuthorDetails() { return reportAuthorDetails == null ? DEFAULT_REPORT_AUTHOR_DETAILS : reportAuthorDetails; } - public List getFileFormats() { - return fileFormats == null ? DEFAULT_FILE_FORMATS : fileFormats; - } - public List getIgnoreGlobList() { - return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : fileFormats; - } - - public boolean getIsIgnoreStandaloneConfig() { - return isIgnoreStandaloneConfig == null ? DEFAULT_IS_IGNORE_STANDALONE_CONFIG : isIgnoreStandaloneConfig; - } - - public List getIgnoreCommitList() { - return ignoreCommitList == null ? DEFAULT_IGNORE_COMMITS_LIST : ignoreCommitList; + return ignoreGlobList == null ? DEFAULT_IGNORE_GLOB_LIST : ignoreGlobList; } public List getIgnoreAuthorList() { return ignoreAuthorList == null ? DEFAULT_IGNORE_AUTHORS_LIST : ignoreAuthorList; } - public boolean getIsShallowCloning() { - return isShallowCloning == null ? DEFAULT_IS_SHALLOW_CLONING : isShallowCloning; - } - - public boolean getIsFindPreviousAuthor() { - return isFindPreviousAuthor == null ? DEFAULT_IS_FIND_PREVIOUS_AUTHOR : isFindPreviousAuthor; - } - @Override public boolean equals(Object obj) { if (obj == this) { @@ -120,13 +68,8 @@ public boolean equals(Object obj) { ReportBranchData rbd = (ReportBranchData) obj; return this.getBranch().equals(rbd.getBranch()) && this.getReportAuthorDetails().equals(rbd.getReportAuthorDetails()) - && this.getFileFormats().equals(rbd.getFileFormats()) && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) - && this.getIsIgnoreStandaloneConfig() == rbd.getIsIgnoreStandaloneConfig() - && this.getIgnoreCommitList().equals(rbd.getIgnoreCommitList()) - && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()) - && this.getIsShallowCloning() == rbd.getIsShallowCloning() - && this.getIsFindPreviousAuthor() == rbd.getIsFindPreviousAuthor(); + && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()); } return false; diff --git a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java index 9d14d2a5df..f817c7b913 100644 --- a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java @@ -10,6 +10,7 @@ */ public class ReportRepoConfiguration { public static final String DEFAULT_REPO = "https://github.com/user/repo"; + public static final String DEFAULT_BLURB = "My project"; public static final List DEFAULT_GROUP_DETAILS = ReportGroupNameAndGlobs.DEFAULT_INSTANCES; public static final List DEFAULT_BRANCHES = List.of( ReportBranchData.DEFAULT_INSTANCE @@ -18,6 +19,7 @@ public class ReportRepoConfiguration { static { DEFAULT_INSTANCE.repo = DEFAULT_REPO; + DEFAULT_INSTANCE.blurb = DEFAULT_BLURB; DEFAULT_INSTANCE.groups = DEFAULT_GROUP_DETAILS; DEFAULT_INSTANCE.branches = DEFAULT_BRANCHES; } @@ -25,6 +27,9 @@ public class ReportRepoConfiguration { @JsonProperty("repo") private String repo; + @JsonProperty("blurb") + private String blurb; + @JsonProperty("groups") private List groups; @@ -35,6 +40,10 @@ public String getRepo() { return repo == null ? DEFAULT_REPO : repo; } + public String getBlurb() { + return blurb == null ? DEFAULT_BLURB : blurb; + } + public List getGroupDetails() { return groups == null ? DEFAULT_GROUP_DETAILS : groups; } @@ -52,6 +61,7 @@ public boolean equals(Object obj) { if (obj instanceof ReportRepoConfiguration) { ReportRepoConfiguration rrc = (ReportRepoConfiguration) obj; return rrc.getRepo().equals(this.getRepo()) + && rrc.getBlurb().equals(this.getBlurb()) && rrc.getGroupDetails().equals(this.getGroupDetails()) && rrc.getBranches().equals(this.getBranches()); } diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index f0eb63aafc..fc5e2ee765 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -1,6 +1,7 @@ title: RepoSense Report Test Title repos: - repo: https://github.com/user/repo.git + blurb: "My project" groups: - group-name: code globs: @@ -23,20 +24,8 @@ repos: - john@john.com - johny@mail.com - j@domain.com - file-formats: - - override:java - - md - - fxml ignore-glob-list: - "docs**" - ignore-standalone-config: true - ignore-commits-list: - - 2fb6b9b2dd9fa40bf0f9815da2cb0ae8731436c7 - - c5a6dc774e22099cd9ddeb0faff1e75f9cf4f151 - - cd7f610e0becbdf331d5231887d8010a689f87c7 - - 768015345e70f06add2a8b7d1f901dc07bf70582 ignore-authors-list: - author1 - author2 - is-shallow-cloning: true - is-find-previous-authors: false diff --git a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java index 70302084c2..72da4d190e 100644 --- a/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportBranchDataTest.java @@ -9,27 +9,11 @@ public void getBranch_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getBranch(), ReportBranchData.DEFAULT_BRANCH); } - @Test - public void getFileFormats_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getFileFormats(), ReportBranchData.DEFAULT_FILE_FORMATS); - } - @Test public void getIgnoreGlobList_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportBranchData().getIgnoreGlobList(), ReportBranchData.DEFAULT_IGNORE_GLOB_LIST); } - @Test - public void getIsIgnoreStandaloneConfig_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsIgnoreStandaloneConfig(), - ReportBranchData.DEFAULT_IS_IGNORE_STANDALONE_CONFIG); - } - - @Test - public void getIgnoreCommitList_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIgnoreCommitList(), - ReportBranchData.DEFAULT_IGNORE_COMMITS_LIST); - } @Test public void getIgnoreAuthorList_equalsDefaultReturnValue_success() { @@ -37,18 +21,6 @@ public void getIgnoreAuthorList_equalsDefaultReturnValue_success() { ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST); } - @Test - public void getIsShallowCloning_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsShallowCloning(), - ReportBranchData.DEFAULT_IS_SHALLOW_CLONING); - } - - @Test - public void getIsFindPreviousAuthor_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportBranchData().getIsFindPreviousAuthor(), - ReportBranchData.DEFAULT_IS_FIND_PREVIOUS_AUTHOR); - } - @Test public void equals_defaultInstancesAreEqual_success() { Assertions.assertEquals(new ReportBranchData(), new ReportBranchData()); diff --git a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java index 0c5b589e3c..fbc4174bd3 100644 --- a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java @@ -9,6 +9,11 @@ public void getRepo_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getRepo(), ReportRepoConfiguration.DEFAULT_REPO); } + @Test + public void getBlurb_equalsDefaultReturnValue_success() { + Assertions.assertSame(new ReportRepoConfiguration().getBlurb(), ReportRepoConfiguration.DEFAULT_BLURB); + } + @Test public void getBranches_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getBranches(), ReportRepoConfiguration.DEFAULT_BRANCHES); diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml index bd6058f6c4..f4b2300daf 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-invalid.yaml @@ -1,6 +1,7 @@ titles: RepoSense Report repo: - repos: https://github.com/reposense/testrepo-Delta.git + blurbs: "The main branch" group: - grame: code globs: diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index dea7a91415..ff8994253d 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -1,6 +1,7 @@ title: RepoSense Report Test Repo repos: - repo: https://github.com/reposense/testrepo-Delta.git + blurb: "The main branch" groups: - group-name: code globs: @@ -26,16 +27,7 @@ repos: author-git-author-name: Francis Hodianto author-emails: - - file-formats: - - override:java - - md - - fxml ignore-glob-list: - - ignore-standalone-config: false - ignore-commits-list: - - ignore-authors-list: - - is-shallow-cloning: false - is-find-previous-authors: false From 42d167de4562d466600f1f30aeffec0aa330a16b Mon Sep 17 00:00:00 2001 From: George Tay Date: Mon, 15 Jul 2024 09:20:33 +0800 Subject: [PATCH 12/12] Implement One-Stop Config File Feature --- config/report-config.yaml | 2 +- src/main/java/reposense/model/BlurbMap.java | 5 ++ .../java/reposense/model/CliArguments.java | 45 ++++++++++- .../model/OneStopConfigRunConfiguration.java | 77 ++++++++++++++++++ .../model/RunConfigurationDecider.java | 5 ++ .../model/reportconfig/ReportBranchData.java | 10 +++ .../reportconfig/ReportConfiguration.java | 37 +++++++-- .../reportconfig/ReportGroupNameAndGlobs.java | 19 +++-- .../reportconfig/ReportRepoConfiguration.java | 79 ++++++++++++++++--- .../java/reposense/parser/ArgsParser.java | 5 +- .../ConfigSystemTest/report-config.yaml | 2 +- .../ReportRepoConfigurationTest.java | 5 -- .../report-config-valid.yaml | 2 +- 13 files changed, 260 insertions(+), 33 deletions(-) create mode 100644 src/main/java/reposense/model/OneStopConfigRunConfiguration.java diff --git a/config/report-config.yaml b/config/report-config.yaml index e410a3629a..968a172699 100644 --- a/config/report-config.yaml +++ b/config/report-config.yaml @@ -1,7 +1,6 @@ title: RepoSense Report repos: - repo: https://github.com/reposense/testrepo-Delta.git - blurb: "My project" groups: - group-name: code globs: @@ -16,6 +15,7 @@ repos: - "**.md" branches: - branch: master + blurb: "My project" authors: - author-git-host-id: fzdy1914 author-display-name: WANG CHAO diff --git a/src/main/java/reposense/model/BlurbMap.java b/src/main/java/reposense/model/BlurbMap.java index 478a3d0c1f..94874f1c30 100644 --- a/src/main/java/reposense/model/BlurbMap.java +++ b/src/main/java/reposense/model/BlurbMap.java @@ -16,6 +16,11 @@ public BlurbMap() { this.urlBlurbMap = new HashMap<>(); } + /** + * Return a copy of the mapping between the repo URL to the associated blurb. + * + * @return a {@code Map} containing the mapping between the repo URL to the associated blurb. + */ public Map getAllMappings() { return new HashMap<>(this.urlBlurbMap); } diff --git a/src/main/java/reposense/model/CliArguments.java b/src/main/java/reposense/model/CliArguments.java index dad1d3563a..3e8e0eafd6 100644 --- a/src/main/java/reposense/model/CliArguments.java +++ b/src/main/java/reposense/model/CliArguments.java @@ -40,6 +40,8 @@ public class CliArguments { private double originalityThreshold; private boolean isTestMode = ArgsParser.DEFAULT_IS_TEST_MODE; private boolean isFreshClonePerformed = ArgsParser.DEFAULT_SHOULD_FRESH_CLONE; + private boolean isBlurbMapOverriding; + private boolean isOneStopConfigSpecified; private List locations; private boolean isViewModeOnly; @@ -167,6 +169,14 @@ public BlurbMap getBlurbMap() { return blurbMap; } + public boolean isBlurbMapOverriding() { + return isBlurbMapOverriding; + } + + public boolean isOneStopConfigSpecified() { + return isOneStopConfigSpecified; + } + public boolean isViewModeOnly() { return isViewModeOnly; } @@ -219,7 +229,8 @@ public boolean equals(Object other) { && Objects.equals(this.reportConfigFilePath, otherCliArguments.reportConfigFilePath) && Objects.equals(this.blurbMap, otherCliArguments.blurbMap) && this.isAuthorshipAnalyzed == otherCliArguments.isAuthorshipAnalyzed - && Objects.equals(this.originalityThreshold, otherCliArguments.originalityThreshold); + && Objects.equals(this.originalityThreshold, otherCliArguments.originalityThreshold) + && this.isBlurbMapOverriding == otherCliArguments.isBlurbMapOverriding; } /** @@ -504,6 +515,38 @@ public Builder blurbMap(BlurbMap blurbMap) { return this; } + /** + * Mark the {@code blurbMap} as overriding. + */ + public Builder markAsBlurbMapOverriding() { + this.cliArguments.isBlurbMapOverriding = true; + return this; + } + + /** + * Unmark the {@code blurbMap} as overriding. + */ + public Builder unmarkAsBlurbMapOverriding() { + this.cliArguments.isBlurbMapOverriding = false; + return this; + } + + /** + * Mark the {@code oneStopConfig} as specified. + */ + public Builder markAsOneStopConfigSpecified() { + this.cliArguments.isOneStopConfigSpecified = true; + return this; + } + + /** + * Unmark the {@code oneStopConfig} as specified. + */ + public Builder unmarkAsOneStopConfigSpecified() { + this.cliArguments.isOneStopConfigSpecified = false; + return this; + } + /** * Builds CliArguments. * diff --git a/src/main/java/reposense/model/OneStopConfigRunConfiguration.java b/src/main/java/reposense/model/OneStopConfigRunConfiguration.java new file mode 100644 index 0000000000..5e61ca64a2 --- /dev/null +++ b/src/main/java/reposense/model/OneStopConfigRunConfiguration.java @@ -0,0 +1,77 @@ +package reposense.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import reposense.model.reportconfig.ReportAuthorDetails; +import reposense.model.reportconfig.ReportBranchData; +import reposense.model.reportconfig.ReportConfiguration; +import reposense.model.reportconfig.ReportRepoConfiguration; +import reposense.parser.exceptions.InvalidLocationException; +import reposense.system.LogsManager; + +/** + * Represents RepoSense run configured by the one-stop configuration file. + */ +public class OneStopConfigRunConfiguration implements RunConfiguration { + private static final Logger logger = LogsManager.getLogger(OneStopConfigRunConfiguration.class); + + private final CliArguments cliArguments; + + public OneStopConfigRunConfiguration(CliArguments cliArguments) { + this.cliArguments = cliArguments; + } + + /** + * Constructs a list of {@link RepoConfiguration}. + * + * @throws InvalidLocationException if the location specified in the config file is invalid. + */ + @Override + public List getRepoConfigurations() throws InvalidLocationException { + ReportConfiguration reportConfiguration = this.cliArguments.getReportConfiguration(); + List repoConfigs = new ArrayList<>(); + List authorConfigs = new ArrayList<>(); + List groupConfigs = new ArrayList<>(); + + for (ReportRepoConfiguration rrc : reportConfiguration.getReportRepoConfigurations()) { + logger.info("Parsing " + rrc.getRepo() + "..."); + RepoLocation repoLocation = new RepoLocation(rrc.getRepo()); + groupConfigs.add(rrc.getGroupConfiguration(repoLocation)); + + // iterate for each branch and for each author + for (ReportBranchData rbd : rrc.getBranches()) { + logger.info("Parsing " + rbd.getBranch() + "..."); + for (ReportAuthorDetails rad : rbd.getReportAuthorDetails()) { + logger.info("Parsing " + rad.getAuthorGitHostId() + "..."); + // create the repoconfiguration object + // we will need to add the group configuration details to the repo configuration builder + RepoConfiguration.Builder builder = new RepoConfiguration.Builder() + .location(repoLocation); + + // set the relevant branch details for the repo + builder = builder.branch(rbd.getBranch()) + .ignoreGlobList(rbd.getIgnoreGlobList()) + .ignoredAuthorsList(rbd.getIgnoreAuthorList()); + + // prepare the author details + Author author = new Author(rad.getAuthorGitHostId()); + author.setEmails(rad.getAuthorEmails()); + author.setDisplayName(rad.getAuthorDisplayName()); + author.setAuthorAliases(List.of(rad.getAuthorGitAuthorName())); + authorConfigs.add(new AuthorConfiguration(repoLocation, rbd.getBranch())); + + repoConfigs.add(builder.build()); + } + } + } + + logger.info("Merging author, group and repo configurations..."); + RepoConfiguration.merge(repoConfigs, authorConfigs); + RepoConfiguration.setGroupConfigsToRepos(repoConfigs, groupConfigs); + + logger.info("Finished parsing OneStopConfigRunConfiguration!"); + return repoConfigs; + } +} diff --git a/src/main/java/reposense/model/RunConfigurationDecider.java b/src/main/java/reposense/model/RunConfigurationDecider.java index c4bd07c85b..9fd6cb2c20 100644 --- a/src/main/java/reposense/model/RunConfigurationDecider.java +++ b/src/main/java/reposense/model/RunConfigurationDecider.java @@ -6,8 +6,13 @@ public class RunConfigurationDecider { public static RunConfiguration getRunConfiguration(CliArguments cliArguments) { if (cliArguments.getLocations() != null) { + if (cliArguments.isOneStopConfigSpecified()) { + return new OneStopConfigRunConfiguration(cliArguments); + } + return new CliRunConfiguration(cliArguments); } + return new ConfigRunConfiguration(cliArguments); } } diff --git a/src/main/java/reposense/model/reportconfig/ReportBranchData.java b/src/main/java/reposense/model/reportconfig/ReportBranchData.java index b77db292f8..f1027640f0 100644 --- a/src/main/java/reposense/model/reportconfig/ReportBranchData.java +++ b/src/main/java/reposense/model/reportconfig/ReportBranchData.java @@ -10,6 +10,7 @@ */ public class ReportBranchData { public static final String DEFAULT_BRANCH = "main"; + public static final String DEFAULT_BLURB = "My project"; public static final List DEFAULT_REPORT_AUTHOR_DETAILS = new ArrayList<>( ReportAuthorDetails.DEFAULT_INSTANCES ); @@ -25,6 +26,7 @@ public class ReportBranchData { static { DEFAULT_INSTANCE.branch = ReportBranchData.DEFAULT_BRANCH; + DEFAULT_INSTANCE.blurb = DEFAULT_BLURB; DEFAULT_INSTANCE.ignoreGlobList = ReportBranchData.DEFAULT_IGNORE_GLOB_LIST; DEFAULT_INSTANCE.ignoreAuthorList = ReportBranchData.DEFAULT_IGNORE_AUTHORS_LIST; DEFAULT_INSTANCE.reportAuthorDetails = ReportAuthorDetails.DEFAULT_INSTANCES; @@ -33,6 +35,9 @@ public class ReportBranchData { @JsonProperty("branch") private String branch; + @JsonProperty("blurb") + private String blurb; + @JsonProperty("authors") private List reportAuthorDetails; @@ -46,6 +51,10 @@ public String getBranch() { return branch == null ? DEFAULT_BRANCH : branch; } + public String getBlurb() { + return blurb == null ? DEFAULT_BLURB : blurb; + } + public List getReportAuthorDetails() { return reportAuthorDetails == null ? DEFAULT_REPORT_AUTHOR_DETAILS : reportAuthorDetails; } @@ -67,6 +76,7 @@ public boolean equals(Object obj) { if (obj instanceof ReportBranchData) { ReportBranchData rbd = (ReportBranchData) obj; return this.getBranch().equals(rbd.getBranch()) + && this.getBlurb().equals(rbd.getBlurb()) && this.getReportAuthorDetails().equals(rbd.getReportAuthorDetails()) && this.getIgnoreGlobList().equals(rbd.getIgnoreGlobList()) && this.getIgnoreAuthorList().equals(rbd.getIgnoreAuthorList()); diff --git a/src/main/java/reposense/model/reportconfig/ReportConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java index b91f4d4a08..8315b25b16 100644 --- a/src/main/java/reposense/model/reportconfig/ReportConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportConfiguration.java @@ -2,9 +2,14 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import com.fasterxml.jackson.annotation.JsonProperty; +import reposense.model.BlurbMap; +import reposense.system.LogsManager; + /** * Class that contains information on a report's configurations. * This class is used mainly for quickly setting up one's personal code portfolio. @@ -12,9 +17,14 @@ public class ReportConfiguration { public static final String DEFAULT_TITLE = "RepoSense Report"; public static final List DEFAULT_REPORT_REPO_CONFIGS = new ArrayList<>(); + public static final ReportConfiguration DEFAULT_INSTANCE = new ReportConfiguration(); + + private static final Logger logger = LogsManager.getLogger(ReportConfiguration.class); static { DEFAULT_REPORT_REPO_CONFIGS.add(ReportRepoConfiguration.DEFAULT_INSTANCE); + ReportConfiguration.DEFAULT_INSTANCE.title = DEFAULT_TITLE; + ReportConfiguration.DEFAULT_INSTANCE.reportRepoConfigurations = DEFAULT_REPORT_REPO_CONFIGS; } @JsonProperty("title") @@ -23,6 +33,28 @@ public class ReportConfiguration { @JsonProperty("repos") private List reportRepoConfigurations; + /** + * Converts the {@code ReportRepoConfiguration} list into a {@code BlurbMap}. + * + * @return {@code BlurbMap} containing the repository name and its associated blurb. + */ + public BlurbMap getBlurbMap() { + BlurbMap blurbMap = new BlurbMap(); + + for (ReportRepoConfiguration repoConfig : reportRepoConfigurations) { + try { + for (ReportRepoConfiguration.MapEntry repoNameBlurbPair + : repoConfig.getFullyQualifiedRepoNamesWithBlurbs()) { + blurbMap.withRecord(repoNameBlurbPair.getKey(), repoNameBlurbPair.getValue()); + } + } catch (IllegalArgumentException ex) { + logger.log(Level.WARNING, ex.getMessage(), ex); + } + } + + return blurbMap; + } + public String getTitle() { return title == null ? DEFAULT_TITLE : title; } @@ -45,9 +77,4 @@ public boolean equals(Object obj) { return false; } - - @Override - public String toString() { - return title + "\n" + reportRepoConfigurations; - } } diff --git a/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java b/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java index f3403d31ab..ba78c61c6c 100644 --- a/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java +++ b/src/main/java/reposense/model/reportconfig/ReportGroupNameAndGlobs.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; +import reposense.model.FileType; + /** * Contains details about each report group and the corresponding globs. */ @@ -47,6 +49,18 @@ public List getGlobs() { return globs == null ? DEFAULT_GLOBS : globs; } + /** + * Converts this {@code ReportGroupNameAndGlobs} into a {@code FileType}. + * + * @return Adapted {@code FileType} object. + */ + public FileType toFileType() { + return new FileType( + this.getGroupName(), + this.getGlobs() + ); + } + @Override public boolean equals(Object obj) { if (obj == this) { @@ -61,9 +75,4 @@ public boolean equals(Object obj) { return false; } - - @Override - public String toString() { - return "RGNAG { group-name: " + this.groupName + ", globs: " + this.globs + "}"; - } } diff --git a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java index f817c7b913..5c24b59b54 100644 --- a/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java +++ b/src/main/java/reposense/model/reportconfig/ReportRepoConfiguration.java @@ -1,16 +1,21 @@ package reposense.model.reportconfig; +import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.fasterxml.jackson.annotation.JsonProperty; +import reposense.model.GroupConfiguration; +import reposense.model.RepoLocation; + /** * Represents a single repository configuration in the overall report * configuration. */ public class ReportRepoConfiguration { public static final String DEFAULT_REPO = "https://github.com/user/repo"; - public static final String DEFAULT_BLURB = "My project"; public static final List DEFAULT_GROUP_DETAILS = ReportGroupNameAndGlobs.DEFAULT_INSTANCES; public static final List DEFAULT_BRANCHES = List.of( ReportBranchData.DEFAULT_INSTANCE @@ -19,7 +24,6 @@ public class ReportRepoConfiguration { static { DEFAULT_INSTANCE.repo = DEFAULT_REPO; - DEFAULT_INSTANCE.blurb = DEFAULT_BLURB; DEFAULT_INSTANCE.groups = DEFAULT_GROUP_DETAILS; DEFAULT_INSTANCE.branches = DEFAULT_BRANCHES; } @@ -27,27 +31,82 @@ public class ReportRepoConfiguration { @JsonProperty("repo") private String repo; - @JsonProperty("blurb") - private String blurb; - @JsonProperty("groups") private List groups; @JsonProperty("branches") private List branches; + /** + * Represents a single mapped entry between a fully qualified repository name and its associated blurb. + */ + public static final class MapEntry { + private final String key; + private final String value; + + public MapEntry(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + } + public String getRepo() { return repo == null ? DEFAULT_REPO : repo; } - public String getBlurb() { - return blurb == null ? DEFAULT_BLURB : blurb; + /** + * Returns the repository name from the {@code repo} URL. Each entry is represented by a list containing + * the fully qualified repository name and the associated blurb. + * + * @return {@code List} containing the fully qualified repository name and the associated blurb. + * @throws IllegalArgumentException if the {@code repo} URL is not in the correct format. + */ + public List getFullyQualifiedRepoNamesWithBlurbs() { + List repoNames = new ArrayList<>(); + Pattern pattern = Pattern.compile(".git"); + Matcher matcher = pattern.matcher(getRepo()); + + if (!matcher.find()) { + // no point continuing if there are no blurbs + throw new IllegalArgumentException("Repo URL: " + this.getRepo() + " is not in the correct format. " + + "Skipping..."); + } + + for (ReportBranchData rbd : this.getBranches()) { + String qualifiedName = getRepo().substring(0, matcher.start()) + "/" + rbd.getBranch(); + repoNames.add(new MapEntry(qualifiedName, rbd.getBlurb())); + } + + return repoNames; } public List getGroupDetails() { return groups == null ? DEFAULT_GROUP_DETAILS : groups; } + /** + * Merges all {@code ReportGroupNameAndGlobs} objects in {@code groups} into a {@code GroupConfiguration} object. + * + * @param location {@code RepoLocation} object. + * @return Adapted {@code GroupConfiguration} object. + */ + public GroupConfiguration getGroupConfiguration(RepoLocation location) { + GroupConfiguration groupConfiguration = new GroupConfiguration(location); + + this.getGroupDetails() + .forEach(x -> groupConfiguration.addGroup(x.toFileType())); + + return groupConfiguration; + } + public List getBranches() { return branches == null ? DEFAULT_BRANCHES : branches; } @@ -61,16 +120,10 @@ public boolean equals(Object obj) { if (obj instanceof ReportRepoConfiguration) { ReportRepoConfiguration rrc = (ReportRepoConfiguration) obj; return rrc.getRepo().equals(this.getRepo()) - && rrc.getBlurb().equals(this.getBlurb()) && rrc.getGroupDetails().equals(this.getGroupDetails()) && rrc.getBranches().equals(this.getBranches()); } return false; } - - @Override - public String toString() { - return repo + "\n" + groups + "\n" + branches; - } } diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 0529c350ce..5ef3ae7e82 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -390,6 +390,7 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names try { reportConfig = new ReportConfigYamlParser().parse(reportConfigFilePath); + builder = builder.markAsOneStopConfigSpecified(); } catch (JsonSyntaxException jse) { logger.warning(String.format(MESSAGE_INVALID_CONFIG_PATH, reportConfigFilePath)); } catch (IllegalArgumentException iae) { @@ -397,6 +398,7 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names } catch (IOException ioe) { // IOException thrown as report-config.yaml is not found. // Ignore exception as the file is optional. + builder = builder.unmarkAsOneStopConfigSpecified(); } } @@ -418,11 +420,12 @@ private static void addBlurbMapToBuilder(CliArguments.Builder builder, Namespace try { blurbMap = new BlurbMarkdownParser(blurbConfigPath).parse(); + builder = builder.markAsBlurbMapOverriding(); } catch (InvalidMarkdownException ex) { logger.warning(String.format(MESSAGE_INVALID_MARKDOWN_BLURBS, ex.getMessage())); } catch (IOException ioe) { // IOException thrown as blurbs.md is not found. - // Ignore exception as the file is optional. + builder = builder.unmarkAsBlurbMapOverriding(); } builder.blurbMap(blurbMap); diff --git a/src/systemtest/resources/ConfigSystemTest/report-config.yaml b/src/systemtest/resources/ConfigSystemTest/report-config.yaml index fc5e2ee765..925686c29f 100644 --- a/src/systemtest/resources/ConfigSystemTest/report-config.yaml +++ b/src/systemtest/resources/ConfigSystemTest/report-config.yaml @@ -1,7 +1,6 @@ title: RepoSense Report Test Title repos: - repo: https://github.com/user/repo.git - blurb: "My project" groups: - group-name: code globs: @@ -16,6 +15,7 @@ repos: - "**.md" branches: - branch: main + blurb: "My project" authors: - author-git-host-id: johnDoe author-display-name: John Doe diff --git a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java index fbc4174bd3..0c5b589e3c 100644 --- a/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java +++ b/src/test/java/reposense/model/reportconfig/ReportRepoConfigurationTest.java @@ -9,11 +9,6 @@ public void getRepo_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getRepo(), ReportRepoConfiguration.DEFAULT_REPO); } - @Test - public void getBlurb_equalsDefaultReturnValue_success() { - Assertions.assertSame(new ReportRepoConfiguration().getBlurb(), ReportRepoConfiguration.DEFAULT_BLURB); - } - @Test public void getBranches_equalsDefaultReturnValue_success() { Assertions.assertSame(new ReportRepoConfiguration().getBranches(), ReportRepoConfiguration.DEFAULT_BRANCHES); diff --git a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml index ff8994253d..934f50536a 100644 --- a/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml +++ b/src/test/resources/ReportConfigYamlParserTest/report-config-valid.yaml @@ -1,7 +1,6 @@ title: RepoSense Report Test Repo repos: - repo: https://github.com/reposense/testrepo-Delta.git - blurb: "The main branch" groups: - group-name: code globs: @@ -16,6 +15,7 @@ repos: - "**.md" branches: - branch: master + blurb: "The main branch" authors: - author-git-host-id: fzdy1914 author-display-name: WANG CHAO