Preformatted messages (#97)

* refactor message creation
This commit is contained in:
Michael Shick 2023-05-05 16:02:36 -04:00 committed by GitHub
parent ef723874d4
commit a251f051d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 154 additions and 85 deletions

View file

@ -30,6 +30,7 @@ type Inputs = {
'message-cancelled'?: string
'message-skipped'?: string
'update-only'?: string
preformatted?: string
status?: 'success' | 'failure' | 'cancelled' | 'skipped'
}
@ -41,6 +42,7 @@ const defaultInputs: Inputs = {
'repo-token': repoToken,
'message-id': 'add-pr-comment',
'allow-repeats': 'false',
status: 'success',
}
const defaultIssueNumber = 1
@ -95,10 +97,10 @@ const server = setupServer(...handlers)
describe('add-pr-comment action', () => {
beforeAll(() => {
vi.spyOn(console, 'log').mockImplementation(() => {})
vi.spyOn(core, 'debug').mockImplementation(() => {})
vi.spyOn(core, 'info').mockImplementation(() => {})
vi.spyOn(core, 'warning').mockImplementation(() => {})
// vi.spyOn(console, 'log').mockImplementation(() => {})
// vi.spyOn(core, 'debug').mockImplementation(() => {})
// vi.spyOn(core, 'info').mockImplementation(() => {})
// vi.spyOn(core, 'warning').mockImplementation(() => {})
server.listen({ onUnhandledRequest: 'error' })
})
afterAll(() => server.close())
@ -392,4 +394,17 @@ describe('add-pr-comment action', () => {
await run()
expect(messagePayload?.body).toContain('666')
})
it('wraps a message in a codeblock if preformatted is true', async () => {
inputs.message = undefined
inputs['preformatted'] = 'true'
inputs['message-path'] = messagePath1Fixture
await expect(run()).resolves.not.toThrow()
expect(
`<!-- add-pr-comment:add-pr-comment -->\n\n\`\`\`\n${messagePath1FixturePayload}\n\`\`\``,
).toEqual(messagePayload?.body)
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
})
})