mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 14:20:32 +11:00
Multiline message-path and concatenation (#88)
This commit is contained in:
parent
a0c6c0cbf4
commit
4a541a260f
14 changed files with 249 additions and 54 deletions
|
|
@ -3,11 +3,16 @@ import * as github from '@actions/github'
|
|||
import { WebhookPayload } from '@actions/github/lib/interfaces'
|
||||
import { rest } from 'msw'
|
||||
import { setupServer } from 'msw/node'
|
||||
import * as fs from 'node:fs/promises'
|
||||
import * as path from 'node:path'
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import run from '../src/main'
|
||||
import apiResponse from './sample-pulls-api-response.json'
|
||||
|
||||
const messagePath1Fixture = path.resolve(__dirname, './message-part-1.txt')
|
||||
const messagePath1FixturePayload = await fs.readFile(messagePath1Fixture, 'utf-8')
|
||||
const messagePath2Fixture = path.resolve(__dirname, './message-part-2.txt')
|
||||
|
||||
const repoToken = '12345'
|
||||
const commitSha = 'abc123'
|
||||
const simpleMessage = 'hello world'
|
||||
|
|
@ -89,12 +94,19 @@ const handlers = [
|
|||
const server = setupServer(...handlers)
|
||||
|
||||
describe('add-pr-comment action', () => {
|
||||
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
|
||||
beforeAll(() => {
|
||||
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())
|
||||
|
||||
beforeEach(() => {
|
||||
inputs = { ...defaultInputs }
|
||||
issueNumber = defaultIssueNumber
|
||||
messagePayload = undefined
|
||||
|
||||
vi.resetModules()
|
||||
|
||||
|
|
@ -141,17 +153,46 @@ describe('add-pr-comment action', () => {
|
|||
|
||||
it('creates a comment with a message-path', async () => {
|
||||
inputs.message = undefined
|
||||
inputs['message-path'] = path.resolve(__dirname, './message.txt')
|
||||
inputs['message-path'] = messagePath1Fixture
|
||||
inputs['allow-repeats'] = 'true'
|
||||
|
||||
await expect(run()).resolves.not.toThrow()
|
||||
expect(`<!-- add-pr-comment:add-pr-comment -->\n\n${messagePath1FixturePayload}`).toEqual(
|
||||
messagePayload?.body,
|
||||
)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
|
||||
})
|
||||
|
||||
it('creates a comment with multiple message-paths concatenated', async () => {
|
||||
inputs.message = undefined
|
||||
inputs['message-path'] = `${messagePath1Fixture}\n${messagePath2Fixture}`
|
||||
inputs['allow-repeats'] = 'true'
|
||||
|
||||
await expect(run()).resolves.not.toThrow()
|
||||
expect(
|
||||
`<!-- add-pr-comment:add-pr-comment -->\n\n${messagePath1FixturePayload}\n${messagePath1FixturePayload}`,
|
||||
).toEqual(messagePayload?.body)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
|
||||
})
|
||||
|
||||
it('supports globs in message paths', async () => {
|
||||
inputs.message = undefined
|
||||
inputs['message-path'] = `${path.resolve(__dirname)}/message-part-*.txt`
|
||||
inputs['allow-repeats'] = 'true'
|
||||
|
||||
await expect(run()).resolves.not.toThrow()
|
||||
expect(
|
||||
`<!-- add-pr-comment:add-pr-comment -->\n\n${messagePath1FixturePayload}\n${messagePath1FixturePayload}`,
|
||||
).toEqual(messagePayload?.body)
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
|
||||
})
|
||||
|
||||
it('fails when both message and message-path are defined', async () => {
|
||||
inputs.message = 'foobar'
|
||||
inputs['message-path'] = path.resolve(__dirname, './message.txt')
|
||||
inputs['message-path'] = messagePath1Fixture
|
||||
|
||||
await expect(run()).resolves.not.toThrow()
|
||||
expect(core.setFailed).toHaveBeenCalledWith('must specify only one, message or message-path')
|
||||
|
|
|
|||
7
__tests__/message-part-2.txt
Normal file
7
__tests__/message-part-2.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
## [Preview link](https://antares-blog-staging-pr-${{ github.event.number }}.azurewebsites.net)
|
||||
|
||||
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
|
||||
- The preview site shows any future-dated articles. Don't worry, if you are publishing a future-dated article, it will not show on the production site until the file's specified date.
|
||||
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
|
||||
|
||||
> *This is an automated message.*
|
||||
Loading…
Add table
Add a link
Reference in a new issue