Skip to content

Commit

Permalink
Update YAML Format
Browse files Browse the repository at this point in the history
  • Loading branch information
georgetayqy committed Jun 9, 2024
1 parent 66cd719 commit 18772f0
Show file tree
Hide file tree
Showing 17 changed files with 590 additions and 161 deletions.
4 changes: 1 addition & 3 deletions config/report-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
title: RepoSense Report
group-details:
repos:
- repo: https://github.com/reposense/testrepo-Delta.git
groups:
- group-name: code
Expand All @@ -13,8 +13,6 @@ group-details:
- "docs**"
- "**.adoc"
- "**.md"
repos:
- repo: https://github.com/reposense/testrepo-Delta.git
branches:
- branch: master
authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,22 @@
*/
public class ReportConfiguration {
public static final String DEFAULT_TITLE = "RepoSense Report";
public static final List<ReportGroupDetails> DEFAULT_REPORT_GROUP_DETAILS = new ArrayList<>();
public static final List<ReportRepoConfiguration> 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<ReportGroupDetails> groupDetails;

@JsonProperty("repos")
private List<ReportRepoConfiguration> reportRepoConfigurations;

public String getTitle() {
return title == null ? DEFAULT_TITLE : title;
}

public List<ReportGroupDetails> getGroupDetails() {
return groupDetails == null ? DEFAULT_REPORT_GROUP_DETAILS : groupDetails;
}

public List<ReportRepoConfiguration> getReportRepoConfigurations() {
return reportRepoConfigurations == null ? DEFAULT_REPORT_REPO_CONFIGS : reportRepoConfigurations;
}
Expand All @@ -54,4 +45,9 @@ public boolean equals(Object obj) {

return false;
}

@Override
public String toString() {
return title + "\n" + reportRepoConfigurations;
}
}
49 changes: 0 additions & 49 deletions src/main/java/reposense/model/reportconfig/ReportGroupDetails.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,35 @@
*/
public class ReportRepoConfiguration {
public static final String DEFAULT_REPO = "https://github.com/user/repo";
public static final List<ReportGroupNameAndGlobs> DEFAULT_GROUP_DETAILS = ReportGroupNameAndGlobs.DEFAULT_INSTANCES;
public static final List<ReportBranchData> DEFAULT_BRANCHES = List.of(
ReportBranchData.DEFAULT_INSTANCE
);
public static final ReportRepoConfiguration DEFAULT_INSTANCE = new 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<ReportGroupNameAndGlobs> groups;

@JsonProperty("branches")
private List<ReportBranchData> branches;

public String getRepo() {
return repo == null ? DEFAULT_REPO : repo;
}

public List<ReportGroupNameAndGlobs> getGroupDetails() {
return groups == null ? DEFAULT_GROUP_DETAILS : groups;
}

public List<ReportBranchData> getBranches() {
return branches == null ? DEFAULT_BRANCHES : branches;
}
Expand All @@ -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;
}
}
24 changes: 8 additions & 16 deletions src/main/java/reposense/parser/ReportConfigYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReportConfiguration> {
public class ReportConfigYamlParser extends YamlParser<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;
}

/**
* 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;

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/reposense/parser/YamlParser.java
Original file line number Diff line number Diff line change
@@ -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 <T> Type {@code T} that this parser can parse and return as an object
*/
public abstract class YamlParser<T> {
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;
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading

0 comments on commit 18772f0

Please sign in to comment.