set action inputs to required if they have defaults

This commit is contained in:
Michael Shick 2023-04-23 09:13:45 -04:00
parent 9c1e156588
commit 7ca8398d28
No known key found for this signature in database
GPG key ID: ADF5BC9704BB4A61
2 changed files with 6 additions and 18 deletions

View file

@ -29,7 +29,7 @@ type Inputs = {
const defaultInputs: Inputs = { const defaultInputs: Inputs = {
message: '', message: '',
'message-path': undefined, 'message-path': undefined,
'repo-token': '', 'repo-token': repoToken,
'message-id': 'add-pr-comment', 'message-id': 'add-pr-comment',
'allow-repeats': 'false', 'allow-repeats': 'false',
} }
@ -130,7 +130,6 @@ describe('add-pr-comment action', () => {
it('creates a comment with message text', async () => { it('creates a comment with message text', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'true' inputs['allow-repeats'] = 'true'
await expect(run()).resolves.not.toThrow() await expect(run()).resolves.not.toThrow()
@ -141,7 +140,6 @@ describe('add-pr-comment action', () => {
it('creates a comment with a message-path', async () => { it('creates a comment with a message-path', async () => {
inputs.message = undefined inputs.message = undefined
inputs['message-path'] = path.resolve(__dirname, './message.txt') inputs['message-path'] = path.resolve(__dirname, './message.txt')
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'true' inputs['allow-repeats'] = 'true'
await expect(run()).resolves.not.toThrow() await expect(run()).resolves.not.toThrow()
@ -152,18 +150,14 @@ describe('add-pr-comment action', () => {
it('fails when both message and message-path are defined', async () => { it('fails when both message and message-path are defined', async () => {
inputs.message = 'foobar' inputs.message = 'foobar'
inputs['message-path'] = path.resolve(__dirname, './message.txt') inputs['message-path'] = path.resolve(__dirname, './message.txt')
inputs['repo-token'] = repoToken
await expect(run()).resolves.not.toThrow() await expect(run()).resolves.not.toThrow()
expect(core.setFailed).toHaveBeenCalledWith('must specify only one, message or message-path') expect(core.setFailed).toHaveBeenCalledWith('must specify only one, message or message-path')
}) })
it('creates a comment in an existing PR', async () => { it('creates a comment in an existing PR', async () => {
process.env['GITHUB_TOKEN'] = repoToken
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'true' inputs['allow-repeats'] = 'true'
github.context.payload = { github.context.payload = {
@ -204,7 +198,6 @@ describe('add-pr-comment action', () => {
it('creates a message when the message id does not exist', async () => { it('creates a message when the message id does not exist', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
inputs['message-id'] = 'custom-id' inputs['message-id'] = 'custom-id'
@ -224,7 +217,6 @@ describe('add-pr-comment action', () => {
it('identifies an existing message by id and updates it', async () => { it('identifies an existing message by id and updates it', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
const commentId = 123 const commentId = 123
@ -250,7 +242,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a success message on success', async () => { it('overrides the default message with a success message on success', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
inputs['message-success'] = '666' inputs['message-success'] = '666'
inputs.status = 'success' inputs.status = 'success'
@ -273,7 +264,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a failure message on failure', async () => { it('overrides the default message with a failure message on failure', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
inputs['message-failure'] = '666' inputs['message-failure'] = '666'
inputs.status = 'failure' inputs.status = 'failure'
@ -296,7 +286,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a cancelled message on cancelled', async () => { it('overrides the default message with a cancelled message on cancelled', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
inputs['message-cancelled'] = '666' inputs['message-cancelled'] = '666'
inputs.status = 'cancelled' inputs.status = 'cancelled'
@ -319,7 +308,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a skipped message on skipped', async () => { it('overrides the default message with a skipped message on skipped', async () => {
inputs.message = simpleMessage inputs.message = simpleMessage
inputs['message-path'] = undefined inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false' inputs['allow-repeats'] = 'false'
inputs['message-skipped'] = '666' inputs['message-skipped'] = '666'
inputs.status = 'skipped' inputs.status = 'skipped'

View file

@ -10,26 +10,26 @@ inputs:
message-id: message-id:
description: "An optional id to use for this message." description: "An optional id to use for this message."
default: "add-pr-comment" default: "add-pr-comment"
required: false required: true
refresh-message-position: refresh-message-position:
description: "If a message with the same id, this option allow to refresh the position of the message to be the last one posted." description: "If a message with the same id, this option allow to refresh the position of the message to be the last one posted."
default: "false" default: "false"
required: false required: true
repo-token: repo-token:
description: "A GitHub token for API access. Defaults to {{ github.token }}." description: "A GitHub token for API access. Defaults to {{ github.token }}."
default: "${{ github.token }}" default: "${{ github.token }}"
required: false required: true
allow-repeats: allow-repeats:
description: "Allow messages to be repeated." description: "Allow messages to be repeated."
default: "false" default: "false"
required: false required: true
proxy-url: proxy-url:
description: "Proxy URL for comment creation" description: "Proxy URL for comment creation"
required: false required: false
status: status:
description: "A job status for status headers. Defaults to {{ job.status }}." description: "A job status for status headers. Defaults to {{ job.status }}."
default: "${{ job.status }}" default: "${{ job.status }}"
required: false required: true
message-success: message-success:
description: "Override the message when a run is successful." description: "Override the message when a run is successful."
required: false required: false