Skip to content

Commit 08d1e09

Browse files
[#2308] Add blurbs for charts (#2350)
Add support for chart blurbs RepoSense currently only supports repository and author blurbs. Adding chart blurbs allows developers to include more details in the chart views. Co-authored-by: CYX22222003 <e1155533@u.nus.edu> Co-authored-by: CHEN YIXUN <138369841+CYX22222003@users.noreply.github.com>
1 parent ce8e3a7 commit 08d1e09

File tree

42 files changed

+495
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+495
-38
lines changed

config/chart-blurbs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://github.com/reposense/testrepo-Alpha/tree/master|nbriannl
2+
Test for chart-blurbs.md

docs/ug/chart-blurbs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
https://github.com/reposense/testrepo-Alpha/tree/master|author1
2+
I contributed to this repository by adding a new feature to the project.
3+
<!--chart-->------------------------------------
4+
https://github.com/reposense/testrepo-Beta/tree/master|author2
5+
I contributed to this repository by fixing a bug in the project.

docs/ug/configFiles.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,14 @@ This file allows you to specify blurbs for authors. These blurbs will be display
291291
* Sample: [author-blurbs.md](https://github.com/reposense/RepoSense/blob/master/docs/ug/author-blurbs.md)
292292
</div>
293293

294+
### `chart-blurbs.md`
295+
<div id="section-chart-blurbs">
296+
297+
This file allow you to specify blurbs for specific charts. These blurbs will be displayed with the charts.
298+
299+
**Format**:
300+
* First line in section: Link to the repository branch|Author's Git Host ID. (Note the `|` between repository's link and author's Git Host ID)
301+
* Second line onwards: Blurb content.
302+
* Delimiter: `<!--chart-->`. Everything on the line after the delimiter will be ignored.
303+
* Sample: [chart-blurbs.md](https://github.com/reposense/RepoSense/blob/master/docs/ug/chart-blurbs.md))
304+
</div>

docs/ug/customizingReports.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Do note that the width of the title is bound by the width of the left panel.
109109

110110
For more information on how to use Markdown, see the [Markdown Guide](https://www.markdownguide.org/).
111111

112-
#### Add blurbs for branches or authors
112+
#### Add blurbs for branches, authors or charts
113113
A blurb can be added for a repository or author by creating the respective blurb markdown files in the config directory.
114114
- For a repository:
115115
- Create a file titled `repo-blurbs.md` in the config directory. The format of the file is given below:
@@ -119,6 +119,9 @@ A blurb can be added for a repository or author by creating the respective blurb
119119
- Create a file titled `author-blurbs.md` in the config directory. The format of the file is given below:
120120
{{ embed("Appendix: **Config files format**", "configFiles.md#section-author-blurbs") }}
121121
- The blurbs will be visible when grouping by `Author`.
122+
- For a chart:
123+
- Create a file titled `chart-blurbs.md` in the config directory. The format of the file is given below:
124+
{{ embed("Appendix: **Config files format**", "configFiles.md#section-chart-blurbs") }}
122125

123126
Specifying the config directory can be done as follows:
124127
{{ embed("Appendix: **CLI syntax reference → `config` flag**", "cli.md#section-config") }}

docs/ug/reportConfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pageNav: 3
99

1010
<h1 class="display-4"><md>{{ title }}</md></h1>
1111

12-
RepoSense allows you to easily showcase your coding portfolio by generating visualization reports of your contributions across different repositories.
12+
RepoSense allows you to easily showcase your coding portfolio by generating visualization reports of your contributions across different repositories.
1313
This guide will help you set up your first RepoSense report using the `report-config.yaml` file.
1414

1515
## What is `report-config.yaml`?

src/main/java/reposense/RepoSense.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.sourceforge.argparse4j.helper.HelpScreenException;
1111
import reposense.git.GitConfig;
1212
import reposense.model.AuthorBlurbMap;
13+
import reposense.model.ChartBlurbMap;
1314
import reposense.model.CliArguments;
1415
import reposense.model.RepoBlurbMap;
1516
import reposense.model.RepoConfiguration;
@@ -48,6 +49,7 @@ public static void main(String[] args) {
4849
ReportConfiguration reportConfig = new ReportConfiguration();
4950
RepoBlurbMap repoBlurbMap = new RepoBlurbMap();
5051
AuthorBlurbMap authorBlurbMap = new AuthorBlurbMap();
52+
ChartBlurbMap chartBlurbMap = new ChartBlurbMap();
5153

5254
if (cliArguments.isViewModeOnly()) {
5355
ReportServer.startServer(SERVER_PORT_NUMBER, cliArguments.getReportDirectoryPath().toAbsolutePath());
@@ -58,6 +60,7 @@ public static void main(String[] args) {
5860
reportConfig = cliArguments.getReportConfiguration();
5961
repoBlurbMap = cliArguments.mergeWithReportConfigRepoBlurbMap();
6062
authorBlurbMap = cliArguments.getAuthorBlurbMap();
63+
chartBlurbMap = cliArguments.getChartBlurbMap();
6164

6265
RepoConfiguration.setFormatsToRepoConfigs(configs, cliArguments.getFormats());
6366
RepoConfiguration.setDatesToRepoConfigs(configs, cliArguments.getSinceDate(), cliArguments.getUntilDate());
@@ -80,7 +83,7 @@ public static void main(String[] args) {
8083

8184
ReportGenerator reportGenerator = new ReportGenerator();
8285
List<Path> reportFoldersAndFiles = reportGenerator.generateReposReport(configs,
83-
cliArguments, reportConfig, repoBlurbMap, authorBlurbMap);
86+
cliArguments, reportConfig, repoBlurbMap, authorBlurbMap, chartBlurbMap);
8487

8588
FileUtil.handleZipFilesAndFolders(reportFoldersAndFiles, cliArguments.getOutputFilePath().toAbsolutePath(),
8689
cliArguments.isOnlyTextRefreshed(), ".json");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package reposense.model;
2+
3+
/**
4+
* Represents the mapping between the charts to the associated blurb.
5+
*/
6+
public class ChartBlurbMap extends AbstractBlurbMap {
7+
8+
public ChartBlurbMap() {
9+
super();
10+
}
11+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class CliArguments {
5555
private ReportConfiguration reportConfiguration;
5656
private RepoBlurbMap repoBlurbMap;
5757
private AuthorBlurbMap authorBlurbMap;
58+
private ChartBlurbMap chartBlurbMap;
5859

5960
/**
6061
* Constructs a {@code CliArguments} object without any parameters.
@@ -165,6 +166,10 @@ public AuthorBlurbMap getAuthorBlurbMap() {
165166
return authorBlurbMap;
166167
}
167168

169+
public ChartBlurbMap getChartBlurbMap() {
170+
return chartBlurbMap;
171+
}
172+
168173
/**
169174
* Merges the {@code blurbMap} from the blurbs file with the blurb map in {@code reportConfiguration}.
170175
*
@@ -244,6 +249,7 @@ public boolean equals(Object other) {
244249
&& Objects.equals(this.reportConfigFilePath, otherCliArguments.reportConfigFilePath)
245250
&& Objects.equals(this.repoBlurbMap, otherCliArguments.repoBlurbMap)
246251
&& Objects.equals(this.authorBlurbMap, otherCliArguments.authorBlurbMap)
252+
&& Objects.equals(this.chartBlurbMap, otherCliArguments.chartBlurbMap)
247253
&& this.isAuthorshipAnalyzed == otherCliArguments.isAuthorshipAnalyzed
248254
&& Objects.equals(this.originalityThreshold, otherCliArguments.originalityThreshold)
249255
&& this.isPortfolio == otherCliArguments.isPortfolio
@@ -518,6 +524,14 @@ public Builder authorBlurbMap(AuthorBlurbMap authorBlurbMap) {
518524
return this;
519525
}
520526

527+
/**
528+
* Adds the {@code chartBlurbMap} to CliArguments.
529+
*/
530+
public Builder chartBlurbMap(ChartBlurbMap chartBlurbMap) {
531+
this.cliArguments.chartBlurbMap = chartBlurbMap;
532+
return this;
533+
}
534+
521535
/**
522536
* Adds the {@code isPortfolio} to CLIArguments.
523537
*

src/main/java/reposense/parser/ArgsParser.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.sourceforge.argparse4j.inf.Namespace;
2727
import reposense.RepoSense;
2828
import reposense.model.AuthorBlurbMap;
29+
import reposense.model.ChartBlurbMap;
2930
import reposense.model.CliArguments;
3031
import reposense.model.FileType;
3132
import reposense.model.RepoBlurbMap;
@@ -345,6 +346,7 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars
345346
addReportConfigToBuilder(cliArgumentsBuilder, results);
346347
addRepoBlurbMapToBuilder(cliArgumentsBuilder, results);
347348
addAuthorBlurbMapToBuilder(cliArgumentsBuilder, results);
349+
addChartBlurbMapToBuilder(cliArgumentsBuilder, results);
348350
addAnalysisDatesToBuilder(cliArgumentsBuilder, results);
349351

350352
boolean isViewModeOnly = reportFolderPath != null
@@ -390,7 +392,7 @@ private static void addReportConfigToBuilder(CliArguments.Builder builder, Names
390392
}
391393

392394
/**
393-
* Adds the repoblurbMap field to the given {@code builder}.
395+
* Adds the repoBlurbMap field to the given {@code builder}.
394396
*
395397
* @param builder Builder to be supplied with the reportConfig field.
396398
* @param results Parsed results of the user-supplied CLI arguments.
@@ -415,7 +417,7 @@ private static void addRepoBlurbMapToBuilder(CliArguments.Builder builder, Names
415417
}
416418

417419
/**
418-
* Adds the authorblurbMap field to the given {@code builder}.
420+
* Adds the authorBlurbMap field to the given {@code builder}.
419421
*
420422
* @param builder Builder to be supplied with the reportConfig field.
421423
* @param results Parsed results of the user-supplied CLI arguments.
@@ -439,6 +441,31 @@ private static void addAuthorBlurbMapToBuilder(CliArguments.Builder builder, Nam
439441
builder.authorBlurbMap(authorBlurbMap);
440442
}
441443

444+
/**
445+
* Adds the chartBlurbMap field to the given {@code builder}.
446+
*
447+
* @param builder Builder to be supplied with the reportConfig field.
448+
* @param results Parsed results of the user-supplied CLI arguments.
449+
*/
450+
private static void addChartBlurbMapToBuilder(CliArguments.Builder builder, Namespace results) {
451+
ChartBlurbMap chartBlurbMap = new ChartBlurbMap();
452+
Path configFolderPath = results.get(CONFIG_FLAGS[0]);
453+
454+
// Blurbs are parsed regardless
455+
Path blurbConfigPath = configFolderPath.resolve(ChartBlurbMarkdownParser.DEFAULT_BLURB_FILENAME);
456+
457+
try {
458+
chartBlurbMap = new ChartBlurbMarkdownParser(blurbConfigPath).parse();
459+
} catch (InvalidMarkdownException ex) {
460+
logger.warning(String.format(MESSAGE_INVALID_MARKDOWN_BLURBS, ex.getMessage()));
461+
} catch (IOException ioe) {
462+
// IOException thrown as blurbs.md is not found.
463+
// Ignore exception as the file is optional.
464+
}
465+
466+
builder.chartBlurbMap(chartBlurbMap);
467+
}
468+
442469
/**
443470
* Adds the sinceDate and untilDate fields for analysis to the given {@code builder}.
444471
*
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package reposense.parser;
2+
3+
import java.io.FileNotFoundException;
4+
import java.net.MalformedURLException;
5+
import java.net.URISyntaxException;
6+
import java.net.URL;
7+
import java.nio.file.Path;
8+
import java.util.List;
9+
import java.util.regex.Pattern;
10+
11+
import reposense.model.ChartBlurbMap;
12+
import reposense.parser.exceptions.InvalidMarkdownException;
13+
14+
/**
15+
* Parses the Markdown file and retrieves the mappings from (repoURL|authorGitId) to blurbs from the blurbs
16+
* configuration file.
17+
*/
18+
public class ChartBlurbMarkdownParser extends BlurbMarkdownParser<ChartBlurbMap, String> {
19+
public static final Pattern DELIMITER = Pattern.compile("<!--chart-->(.*)");
20+
public static final String DEFAULT_BLURB_FILENAME = "chart-blurbs.md";
21+
22+
public ChartBlurbMarkdownParser(Path markdownPath) throws FileNotFoundException {
23+
super(markdownPath, DELIMITER, DEFAULT_BLURB_FILENAME);
24+
}
25+
26+
@Override
27+
protected ChartBlurbMap createBlurbMap() {
28+
return new ChartBlurbMap();
29+
}
30+
31+
@Override
32+
protected KeyRecord<String> extractKey(List<String> lines, int position) throws InvalidMarkdownException {
33+
// Extract the key (repoURL|authorGitId)
34+
String key = "";
35+
36+
while (key.length() == 0) {
37+
38+
if (position >= lines.size()) {
39+
return null;
40+
}
41+
42+
// Skip delimiter lines
43+
if (DELIMITER.matcher(lines.get(position)).matches()) {
44+
position++;
45+
continue;
46+
}
47+
48+
key = lines.get(position++).strip();
49+
}
50+
51+
// Validate the key
52+
if (!isValidKey(key)) {
53+
throw new InvalidMarkdownException("Invalid key format: " + key);
54+
}
55+
56+
return new KeyRecord<>(key, position);
57+
}
58+
59+
/**
60+
* Validates the key (repoURL|authorGitId) format.
61+
* The repoURL should be a valid URL and the authorGitId should be present.
62+
*
63+
* @param key The key to validate.
64+
* @return true if the key is valid, false otherwise.
65+
* @throws InvalidMarkdownException if the key format is invalid.
66+
*/
67+
private boolean isValidKey(String key) throws InvalidMarkdownException {
68+
String[] parts = key.split("\\|");
69+
70+
// Check if the key has exactly 2 parts (repoURL and authorGitId)
71+
if (parts.length != 2) {
72+
return false;
73+
}
74+
75+
String repoUrl = parts[0].strip();
76+
String authorGitId = parts[1].strip();
77+
78+
// Check if the repoURL is a valid URL
79+
if (repoUrl.isEmpty() || authorGitId.isEmpty()) {
80+
return false;
81+
}
82+
83+
// Validate the repoURL format
84+
// Adapted from https://www.baeldung.com/java-validate-url
85+
try {
86+
new URL(repoUrl).toURI();
87+
return true;
88+
} catch (MalformedURLException | URISyntaxException e) {
89+
return false;
90+
}
91+
}
92+
93+
@Override
94+
protected void addRecord(ChartBlurbMap blurbMap, String key, String blurb) {
95+
blurbMap.withRecord(key, blurb);
96+
}
97+
}

0 commit comments

Comments
 (0)