mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-28 16:38:51 +00:00
feat: support combining path and message inputs using $path placeholder
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
This commit is contained in:
parent
5b837e833d
commit
981267b215
3 changed files with 69 additions and 4 deletions
|
|
@ -255,4 +255,61 @@ describe("getBody", () => {
|
|||
})
|
||||
expect(await config.getBody()).toBe("hello there\n```")
|
||||
})
|
||||
|
||||
test("embeds file content in message when $path placeholder is used", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "```\n$path\n```"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("```\nhi there\n\n```")
|
||||
})
|
||||
|
||||
test("replaces all $path occurrences in message with file content", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "$path\n---\n$path"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("hi there\n\n---\nhi there\n")
|
||||
})
|
||||
|
||||
test("uses file content as body when path is provided but message has no $path placeholder", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "no placeholder here"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("hi there\n")
|
||||
})
|
||||
|
||||
test("embeds multiple files content in message when $path placeholder is used", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/*"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "```\n$path\n```"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi
|
||||
.fn()
|
||||
.mockResolvedValue([
|
||||
resolve("__tests__/assets/result"),
|
||||
resolve("__tests__/assets/result2"),
|
||||
]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("```\nhi there\n\nhey there\n\n```")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue