Skip to content

Commit b8e7124

Browse files
authored
dev: move file link a level up (#128)
* dev: init link to file template * dev: add file link to lvl up * dev: add relative file path * dev: fix test
1 parent dbf1fb1 commit b8e7124

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

__tests__/report.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ describe("Report test suite", () => {
1919
en: [],
2020
fileContent: "test full context",
2121
filename: "test filename",
22+
relativePath: "test relative path",
2223
});
23-
expect(reportContent).toContain("test filename");
24+
expect(reportContent).toContain("test relative path");
2425
expect(reportContent).toContain("English Language Report");
2526
});
2627

package-lock.json

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/report.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as util from "./util";
1010
export function composeReportMetadataToParagraph(reportMetadata): string {
1111
let reportContent = "";
1212
const reportTemplate = util.loadTemplate("langReport");
13+
const fileLinkTemplate = util.loadTemplate("linkToFile");
1314
const suggestionTemplate = util.loadTemplate("langSuggestion");
1415
const filename = reportMetadata.filename;
1516
const owner = util.getGitHubRepoOwner();
@@ -30,20 +31,23 @@ export function composeReportMetadataToParagraph(reportMetadata): string {
3031
const suggestionRenderContent = {
3132
index: suggestionIndex,
3233
offset: suggestionOffset,
33-
owner,
34-
path: relativePath,
35-
ref: "master", /** TODO(tianhao95): get this programmatically */
36-
repo,
3734
snippet: snippetContent,
3835
suggestion: suggestionContent,
3936
};
4037
const suggestionEntryContent = mustache.render(suggestionTemplate, suggestionRenderContent);
4138
reportContent += suggestionEntryContent;
4239
reportContent += "\n\n";
4340
}
41+
const link = mustache.render(fileLinkTemplate, {
42+
owner,
43+
path: relativePath,
44+
ref: "master", /** TODO(tianhao95): get this programmatically */
45+
repo,
46+
});
4447
const finalReport = mustache.render(reportTemplate, {
4548
content: reportContent,
46-
filename,
49+
filename: relativePath,
50+
link,
4751
});
4852
return finalReport;
4953
}

src/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export function loadTemplate(template: string) {
220220
*/
221221
export function sanitizeMarkdown(rawText) {
222222
/** Clean out unicode */
223-
const sanitizedMarkdown = rawText.replace(/`/gi, "`");
223+
let sanitizedMarkdown = rawText.replace(/`/gi, "`");
224+
sanitizedMarkdown = sanitizedMarkdown.replace(/\n/gi, "");
224225
return sanitizedMarkdown;
225226
}

template/langReport.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<details>
22
<summary>
3-
English Language Report for {{{filename}}}
3+
English Language Report for <code>{{{filename}}}</code>
44
</summary>
55

6+
{{{link}}}
7+
68
{{{content}}}
79

810
</details>

template/langSuggestion.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<details>
22
<summary>Suggestion for snippet @ index:{{{index}}} & offset:{{{offset}}}</summary>
33

4-
[go to file](https://github.com/{{{owner}}}/{{{repo}}}/blob/{{{ref}}}/{{{path}}})
5-
64
...
75

86
{{{snippet}}}

template/linkToFile.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[go to file](https://github.com/{{{owner}}}/{{{repo}}}/blob/{{{ref}}}/{{{path}}})

0 commit comments

Comments
 (0)