Skip to content

Commit

Permalink
Escape filename in line blob URL (Fixes #10)
Browse files Browse the repository at this point in the history
adds template testcase
update dependencies
  • Loading branch information
Julian Bildner committed Mar 19, 2022
1 parent 4588f48 commit 1abe13e
Show file tree
Hide file tree
Showing 8 changed files with 11,406 additions and 8,944 deletions.
13,712 changes: 6,873 additions & 6,839 deletions dist/index.js

Large diffs are not rendered by default.

6,588 changes: 4,488 additions & 2,100 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async function generateTodosFromCommit() {
type: change.type,
keyword: matches.groups.keyword,
filename: file.to,
escapedFilename: encodeURI(file.to as string),
sha: process.env.GITHUB_SHA,
bodyComment,
changedLine,
Expand All @@ -109,6 +110,8 @@ export declare type Todo = {
keyword: string
bodyComment: string
filename: string
escapedFilename: string
sha: string
changedLine: number
title: string
chunk: Chunk
Expand Down
2 changes: 1 addition & 1 deletion src/templates/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = `## {{ title }}
{{/if}}
{{#if range}}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ filename }}#{{ range }}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ escapedFilename }}#{{ range }}
---
Expand Down
2 changes: 1 addition & 1 deletion src/templates/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = `{{#if body}}
{{/if}}
{{#if range}}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ filename }}#{{ range }}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ escapedFilename }}#{{ range }}
---
Expand Down
2 changes: 1 addition & 1 deletion src/templates/issueFromMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = `{{#if body}}
{{/if}}
{{#if range}}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ filename }}#{{ range }}
https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ escapedFilename }}#{{ range }}
---
Expand Down
4 changes: 2 additions & 2 deletions src/templates/reopenClosed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = `This issue has been reopened because the **\`{{ keyword }}\`** comment still exists in [**{{ filename }}**](https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ filename }}), as of {{ sha }}.
module.exports = `This issue has been reopened because the **\`{{ keyword }}\`** comment still exists in [**{{ filename }}**](https://{{ githubHost }}/{{ owner }}/{{ repo }}/blob/{{ sha }}/{{ escapedFilename }}), as of {{ sha }}.
---
###### If this was not intentional, just remove the comment from your code. You can also set the [\`reopenClosed\`](https://github.com/JasonEtco/todo#configuring-for-your-project) config if you don't want this to happen at all anymore.`
###### If this was not intentional, just remove the comment from your code. You can also set the [\`reopenClosed\`](https://github.com/DerJuulsn/todo-issue#available-options) config if you don't want this to happen at all anymore.`
37 changes: 37 additions & 0 deletions tests/template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {template} from "../src/templates";
import {Todo} from "../src/Todo";

describe("Check comment generation", () => {

it("matches desired comment template - file with whitespace name", async () => {

let filename = "some file.txt";

const body = template.issue(
{
repo: "todo-issue",
owner: "DerJuulsn",
body: "Test Comment",
...{
escapedFilename: encodeURI(filename),
filename,
keyword: "TODO",
assignedToString: "@DerJuulsn",
sha: "SHA",
range: "L1",
} as Todo
});

expect(body).toEqual(
"Test Comment\n" +
"\n" +
"---\n" +
"\n" +
"https://github.com/DerJuulsn/todo-issue/blob/SHA/some%20file.txt#L1\n" +
"\n" +
"---\n" +
"\n" +
"###### This issue was generated by [todo-issue](https://github.com/DerJuulsn/todo-issue) based on a `TODO` comment in SHA.@DerJuulsn");
})

})

0 comments on commit 1abe13e

Please sign in to comment.