Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[#2161] One-Stop Config File for Code Portfolio #2172

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2db2ac0
Update with report config YAML files
asdfghjkxd Mar 25, 2024
202d247
Undo SummaryJson changes
asdfghjkxd Mar 25, 2024
f64f6ed
Update ReportConfiguration to support branches
asdfghjkxd Mar 27, 2024
356299a
Update Report Configuration docs
asdfghjkxd Mar 27, 2024
ffd4912
Merge branch 'master' into 2161-code-portfolio
asdfghjkxd Mar 27, 2024
2cbb662
Update YAML format
asdfghjkxd Mar 28, 2024
9190fb0
Fix environmental error
asdfghjkxd Apr 1, 2024
b611f29
Implement Markdown Parser
asdfghjkxd Apr 2, 2024
6573637
Fix test cases
asdfghjkxd Apr 2, 2024
6c5e401
Add blurbs on frontend (#2186)
sopa301 Apr 4, 2024
4259db3
Merge branch 'master' into 2161-code-portfolio
asdfghjkxd Apr 4, 2024
43f1c14
Add tests for BlurbMap and ReportConfiguration
asdfghjkxd Apr 4, 2024
d5fd31a
Remove manual testing artefact
sopa301 Apr 4, 2024
6e58493
Upgrade checkstyle and fix checkstyle errors
asdfghjkxd Apr 5, 2024
7924629
Revert "Upgrade checkstyle and fix checkstyle errors"
asdfghjkxd Apr 5, 2024
cbf622d
Update regex
asdfghjkxd Apr 8, 2024
fa95f75
Remove unused methods
asdfghjkxd Apr 8, 2024
4299ff2
Update Regex to accept 0 or more characters
asdfghjkxd Apr 8, 2024
1145f8e
Modify css
sopa301 Apr 8, 2024
7c94fea
Merge branch '2161-code-portfolio' of https://github.com/reposense/Re…
sopa301 Apr 8, 2024
6ee3249
Update Yaml file format
asdfghjkxd Apr 8, 2024
48c873b
Add blurbs to frontend files
sopa301 Apr 8, 2024
50f6ec6
Fix style
sopa301 Apr 8, 2024
941f420
Fix style
sopa301 Apr 8, 2024
6dd383b
Move blurb parsing into ArgsParser
asdfghjkxd Apr 11, 2024
d628e85
Merge branch '2161-code-portfolio' of https://github.com/reposense/Re…
asdfghjkxd Apr 11, 2024
68ea84e
Fix tests
sopa301 Apr 11, 2024
28d9c84
Change config files
sopa301 Apr 11, 2024
83329cf
Update blurb map parsing
asdfghjkxd Apr 11, 2024
f70ead4
Merge branch '2161-code-portfolio' of https://github.com/reposense/Re…
asdfghjkxd Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/report-config.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions docs/ug/configFiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

<!-- ==================================================================================================== -->

Expand Down
3 changes: 0 additions & 3 deletions docs/ug/report-config.json

This file was deleted.

11 changes: 11 additions & 0 deletions docs/ug/report-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repoUrl: github.com/user/repo
reportTitle: RepoSense Report
authorDisplayName: Sample Author
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damithc Sure thing, will remove these from the YAML file and other associated classes in a future commit.

authorGithubId: Sample Author Github ID
branches:
- name: Branch 1
blurb: Blurb 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blurb should allow a few paragraph of markdown text. So, yml might not be the right format for this config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damithc There are ways to incorporate multi-line strings into YAML files here, we could perhaps include this into the docs to let users know how they can tailor the blurbs to suit their use cases (multi-paragraph vs long single paragraph text)

- name: Branch 2
blurb: Blurb 2
startDate: 2020-01-01
endDate: 9999-12-31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2161 (comment) for an example that seems intuitive from the user POV

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damithc Just wanted to clarify, do you mean that we should include the configs within the markdown files itself, and have the backend parse the markdown files and then generate the reports, or that the overall order/style/keys in the YAML file should match what was used in the example provided?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asdfghjkxd I wasn't specifically using markdown either. It is just a custom format that makes sense from the user's point of view. I'm fine if something close can be achieved by YAML or some other commonly-used format, provided it makes sense from the user (i.e., the user shouldn't have to do a lot of extra work just to conform to the file format)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damithc I see, sure thing, we will try to design a user-friendly and convenient config file format and update this PR and parent issue with any new findings/improvements!

9 changes: 7 additions & 2 deletions src/main/java/reposense/model/CliArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.
Expand Down Expand Up @@ -155,6 +155,10 @@
return reportConfigFilePath;
}

public ReportConfiguration getReportYamlConfiguration() {
return reportConfiguration;

Check warning on line 159 in src/main/java/reposense/model/CliArguments.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/reposense/model/CliArguments.java#L159

Added line #L159 was not covered by tests
}

public ReportConfiguration getReportConfiguration() {
return reportConfiguration;
}
Expand Down Expand Up @@ -441,7 +445,8 @@
this.cliArguments.groupConfigFilePath = configFolderPath.resolve(
GroupConfigCsvParser.GROUP_CONFIG_FILENAME);
this.cliArguments.reportConfigFilePath = configFolderPath.resolve(
ReportConfigJsonParser.REPORT_CONFIG_FILENAME);
ReportConfigYamlParser.REPORT_CONFIG_FILENAME);

return this;
}

Expand Down
82 changes: 77 additions & 5 deletions src/main/java/reposense/model/ReportConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,85 @@
package reposense.model;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents configuration information from JSON config file for generated report.
* 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 {
private static final String DEFAULT_TITLE = "RepoSense Report";
private String title;
public static final String DEFAULT_REPO_URL = "github.com/user/repo";
public static final String DEFAULT_TITLE = "RepoSense Report";
public static final String DEFAULT_AUTHOR_DISPLAY_NAME = "Sample Author";
public static final String DEFAULT_AUTHOR_GITHUB_ID = "Sample Author Github ID";
public static final List<Map<String, String>> DEFAULT_BRANCHES_WITH_BLURBS = new ArrayList<>();
public static final LocalDate DEFAULT_START_DATE = LocalDate.of(2020, 1, 1);
public static final LocalDate DEFAULT_END_DATE = LocalDate.of(9999, 12, 31);

private static final HashMap<String, String> DEFAULT_BRANCH_ONE = new HashMap<>();
private static final HashMap<String, String> DEFAULT_BRANCH_TWO = new HashMap<>();

@JsonProperty("repoUrl")
private String repoUrl;

@JsonProperty("reportTitle")
private String reportTitle;

@JsonProperty("authorDisplayName")
private String authorDisplayName;

@JsonProperty("authorGithubId")
private String authorGithubId;

@JsonProperty("startDate")
private LocalDate startDate;

@JsonProperty("endDate")
private LocalDate endDate;

@JsonProperty("branches")
private List<Map<String, String>> branchesWithBlurbs;

// SIB to set the default values in the maps
static {
DEFAULT_BRANCH_ONE.put("name", "Branch 1");
DEFAULT_BRANCH_ONE.put("blurb", "Blurb 1");
DEFAULT_BRANCH_TWO.put("name", "Branch 2");
DEFAULT_BRANCH_TWO.put("blurb", "Blurb 2");
DEFAULT_BRANCHES_WITH_BLURBS.add(DEFAULT_BRANCH_ONE);
DEFAULT_BRANCHES_WITH_BLURBS.add(DEFAULT_BRANCH_TWO);
}

public String getReportTitle() {
return reportTitle == null ? DEFAULT_TITLE : reportTitle;
}

public String getAuthorDisplayName() {
return authorDisplayName == null ? DEFAULT_AUTHOR_DISPLAY_NAME : authorDisplayName;
}

public String getAuthorGithubId() {
return authorGithubId == null ? DEFAULT_AUTHOR_GITHUB_ID : authorGithubId;
}

public LocalDate getStartDate() {
return startDate == null ? DEFAULT_START_DATE : startDate;
}

public LocalDate getEndDate() {
return endDate == null ? DEFAULT_END_DATE : endDate;
}

public String getRepoUrl() {
return repoUrl == null ? DEFAULT_REPO_URL : repoUrl;
}

public String getTitle() {
return (title == null) ? DEFAULT_TITLE : title;
public List<Map<String, String>> getBranchesWithBlurbs() {
return branchesWithBlurbs == null ? DEFAULT_BRANCHES_WITH_BLURBS : branchesWithBlurbs;
}
}
4 changes: 2 additions & 2 deletions src/main/java/reposense/parser/ArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/reposense/parser/ReportConfigJsonParser.java

This file was deleted.

59 changes: 59 additions & 0 deletions src/main/java/reposense/parser/ReportConfigYamlParser.java
Original file line number Diff line number Diff line change
@@ -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.ReportConfiguration;
import reposense.system.LogsManager;

/**
* YAML Parser for report-config.yaml files.
*/
public class ReportConfigYamlParser extends JsonParser<ReportConfiguration> {
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;

Check warning on line 27 in src/main/java/reposense/parser/ReportConfigYamlParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/reposense/parser/ReportConfigYamlParser.java#L27

Added line #L27 was not covered by tests
}

@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);

Check warning on line 37 in src/main/java/reposense/parser/ReportConfigYamlParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/reposense/parser/ReportConfigYamlParser.java#L37

Added line #L37 was not covered by tests
}

@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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/reposense/report/ReportGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class ReportGenerator {
private static final String LOG_ERROR_CLONING_OR_BRANCHING = "Exception met while cloning or checking out.";
private static final String LOG_UNEXPECTED_ERROR = "Unexpected error stack trace for %s:\n>%s";
private static final List<String> assetsFilesWhiteList =
Collections.unmodifiableList(Arrays.asList(new String[] {"favicon.ico", "title.md"}));
Collections.unmodifiableList(Arrays.asList("favicon.ico", "title.md"));

private LocalDateTime earliestSinceDate = null;
private ProgressTracker progressTracker = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/reposense/report/SummaryJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SummaryJson(List<RepoConfiguration> repos, ReportConfiguration reportConf
this.repos = repos;
this.reportGeneratedTime = reportGeneratedTime;
this.reportGenerationTime = reportGenerationTime;
this.reportTitle = reportConfig.getTitle();
this.reportTitle = reportConfig.getReportTitle();
this.sinceDate = sinceDate;
this.untilDate = untilDate;
this.isSinceDateProvided = isSinceDateProvided;
Expand Down

This file was deleted.

11 changes: 11 additions & 0 deletions src/systemtest/resources/ConfigSystemTest/report-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repoUrl: github.com/user/repo
reportTitle: RepoSense Report Test Title
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
38 changes: 0 additions & 38 deletions src/test/java/reposense/parser/ReportConfigJsonParserTest.java

This file was deleted.

Loading
Loading