Skip to content

Commit 53399bb

Browse files
authored
dev: get ready for v1 (#133)
* dev: add reason sanitizer * dev: sanitize newline out of reason * dev: clean report text * dev: add todo for adding closed issue test
1 parent b8e7124 commit 53399bb

File tree

11 files changed

+54
-27
lines changed

11 files changed

+54
-27
lines changed

__tests__/octo.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("octo test suite", () => {
5252
.get(IssueScope).reply(200, [
5353
{
5454
number: 1,
55+
state: "open",
5556
title: "test title",
5657
},
5758
]);
@@ -72,8 +73,8 @@ describe("octo test suite", () => {
7273
.reply(200, { token: "test" });
7374
nock(GitHubEndpoint)
7475
.get(IssueScope).reply(200, [
75-
{ title: "test title 1", number: 0 },
76-
{ title: "test title 2", number: 1 },
76+
{ title: "test title 1", number: 0, state: "open" },
77+
{ title: "test title 2", number: 1, state: "open" },
7778
]);
7879
return expect(octo.matchIssueTitle(
7980
"test title 1",
@@ -88,8 +89,8 @@ describe("octo test suite", () => {
8889
.reply(200, { token: "test" });
8990
nock(GitHubEndpoint)
9091
.get(IssueScope).reply(200, [
91-
{ title: "test title 1", number: 0 },
92-
{ title: "test title 2", number: 1 },
92+
{ title: "test title 1", number: 0, state: "open" },
93+
{ title: "test title 2", number: 1, state: "open" },
9394
]);
9495
return expect(octo.matchIssueTitle(
9596
"test title 1",
@@ -107,8 +108,8 @@ describe("octo test suite", () => {
107108
.reply(200, { token: "test" });
108109
nock(GitHubEndpoint)
109110
.get(IssueScope).reply(200, [
110-
{ title: "test title 1", number: 0 },
111-
{ title: "test title 2", number: 1 },
111+
{ title: "test title 1", number: 0, state: "open" },
112+
{ title: "test title 2", number: 1, state: "open" },
112113
]);
113114
return expect(octo.matchIssueTitle(
114115
"test title no match",
@@ -119,4 +120,6 @@ describe("octo test suite", () => {
119120
issueNumber: -1,
120121
});
121122
});
123+
124+
// TODO(tianhaoz95): add test for closed issues
122125
});

__tests__/report.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ describe("Report test suite", () => {
55
expect(() => {
66
report.composeReportMetadataToParagraph({
77
en: [
8-
"test suggestion 1",
9-
"test suggestion 2",
8+
{
9+
index: 10,
10+
offset: 5,
11+
reason: "test rocks!",
12+
},
13+
{
14+
index: 20,
15+
offset: 3,
16+
reason: "ahhh I am hungry...",
17+
},
1018
],
1119
fileContent: "test full context",
1220
filename: "test filename",
21+
relativePath: "test relative path",
1322
});
1423
}).not.toThrow();
1524
});
@@ -22,7 +31,7 @@ describe("Report test suite", () => {
2231
relativePath: "test relative path",
2332
});
2433
expect(reportContent).toContain("test relative path");
25-
expect(reportContent).toContain("English Language Report");
34+
expect(reportContent).toContain("Report for");
2635
});
2736

2837
it("generate report lang entry", () => {

__tests__/util.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,14 @@ describe("Utility test suite", () => {
212212
it("test file ref parser block invalid ref", () => {
213213
expect(util.parseFileLinkRef("i/am/not/a/ref")).toBe("not supported");
214214
});
215+
216+
it("test reason sanitizer no crash", () => {
217+
expect(() => {
218+
util.sanitizeReason("this test\nhas newline");
219+
}).not.toThrow();
220+
});
221+
222+
it("test reason sanitizer replaces newline", () => {
223+
expect(util.sanitizeReason("this test\nhas newline")).toBe("this test has newline");
224+
});
215225
});

package-lock.json

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

src/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function lintWorkspace() {
2929
reportsMetadata.push(reportEntry);
3030
}
3131
}
32-
let finalReport = "final report";
32+
let finalReport = "";
3333
for (const reportMetadata of reportsMetadata) {
3434
const reportEntry = report.composeReportMetadataToParagraph(reportMetadata);
3535
// TODO(tianhaoz95): let the compose take the responsibility of decisiding

src/octo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function matchIssueTitle(
2424
});
2525
for (const issue of allIssues.data) {
2626
const issueTitle = issue.title;
27-
if (title === issueTitle) {
27+
if (title === issueTitle && issue.state === "open") {
2828
return {
2929
found: true,
3030
issueNumber: issue.number,

src/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function composeReportMetadataToParagraph(reportMetadata): string {
1717
const repo = util.getGitHubRepoId();
1818
const relativePath = reportMetadata.relativePath;
1919
for (const suggestion of reportMetadata.en) {
20-
const suggestionContent = suggestion.reason;
20+
const suggestionContent = util.sanitizeReason(suggestion.reason);
2121
const suggestionIndex = suggestion.index;
2222
const suggestionOffset = suggestion.offset;
2323
const fullText = reportMetadata.fileContent;

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,12 @@ export function sanitizeMarkdown(rawText) {
224224
sanitizedMarkdown = sanitizedMarkdown.replace(/\n/gi, "");
225225
return sanitizedMarkdown;
226226
}
227+
228+
/**
229+
* This function sanitizes the reason output
230+
*/
231+
export function sanitizeReason(rawReason: string): string {
232+
let sanitizedReason = rawReason;
233+
sanitizedReason = sanitizedReason.replace(/\n/ig, " ");
234+
return sanitizedReason;
235+
}

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 <code>{{{filename}}}</code>
3+
Report for <code>{{{filename}}}</code>
44
</summary>
55

6+
<br/>
7+
68
{{{link}}}
79

810
{{{content}}}

template/langSuggestion.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
<details>
2-
<summary>Suggestion for snippet @ index:{{{index}}} & offset:{{{offset}}}</summary>
3-
4-
...
5-
6-
{{{snippet}}}
7-
8-
...
9-
</details>
10-
11-
> suggestion: {{{suggestion}}}
1+
Suggestion: {{{suggestion}}}
2+
> @ index:{{{index}}} & offset:{{{offset}}}

0 commit comments

Comments
 (0)