Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reading from body-file #462

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/commenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ Frontend:
- [ ] Do this
- [ ] And this
- [ ] And that

Prelude:
where:
path:
matches: "backend/**/*"
6 changes: 6 additions & 0 deletions .github/commenter/Prelude.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
You've modified our Prelude!

Please read the following links:

- ...
- ...
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ CommentOnAutomatedUpdate:
integrity of the packages being updated.
```

## Reading the Comment Body from a File

If `body` is omitted, a file named `.github/commenter/{name}.md` is read from
the default branch for the comment contents. The `.github/commenter/` prefix can
be changed via `inputs.body-file-prefix`. The complete path, or just the name
part, can be specified via the `body-file` and `body-file-name` attributes of
the configuration, respectively.

## Acknowledgements

This action was highly inspired by (and began as a copy of)
Expand Down
4 changes: 4 additions & 0 deletions __tests__/fixtures/body_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Prelude:
where:
path:
matches: "Prelude.hs"
25 changes: 23 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const yamlFixtures = {
"all_conditions.yml": fs.readFileSync(
"__tests__/fixtures/all_conditions.yml",
),
"body_file.yml": fs.readFileSync("__tests__/fixtures/body_file.yml"),
};

afterAll(() => jest.restoreAllMocks());
Expand Down Expand Up @@ -185,11 +186,31 @@ describe("run", () => {
body: "This change requires human review\n",
});
});

it("adds comments from file contents", async () => {
usingConfigYaml("body_file.yml");
mockGitHubResponseGetContentOnce("Some content\n");
mockGitHubResponseChangedFiles("Prelude.hs");

await run();

expect(createCommentMock).toHaveBeenCalledTimes(1);
expect(createCommentMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
issue_number: 123,
body: "Some content\n",
});
});
});

function usingConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
reposMock.mockResolvedValue(<any>{
data: { content: yamlFixtures[fixtureName], encoding: "utf8" },
mockGitHubResponseGetContentOnce(yamlFixtures[fixtureName]);
}

function mockGitHubResponseGetContentOnce(content: string): void {
reposMock.mockResolvedValueOnce(<any>{
data: { content, encoding: "utf8" },
});
}

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: "The path for the comment configurations"
default: ".github/commenter.yml"
required: false
body-file-prefix:
description: "The path for finding body markdown files"
default: ".github/commenter/"
required: false

runs:
using: "node20"
Expand Down
Loading