Skip to content

Commit

Permalink
set action inputs to required if they have defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mshick committed Apr 23, 2023
1 parent 9c1e156 commit 7ca8398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
14 changes: 1 addition & 13 deletions __tests__/add-pr-comment.test.ts
Expand Up @@ -29,7 +29,7 @@ type Inputs = {
const defaultInputs: Inputs = {
message: '',
'message-path': undefined,
'repo-token': '',
'repo-token': repoToken,
'message-id': 'add-pr-comment',
'allow-repeats': 'false',
}
Expand Down Expand Up @@ -130,7 +130,6 @@ describe('add-pr-comment action', () => {

it('creates a comment with message text', async () => {
inputs.message = simpleMessage
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'true'

await expect(run()).resolves.not.toThrow()
Expand All @@ -141,7 +140,6 @@ 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['repo-token'] = repoToken
inputs['allow-repeats'] = 'true'

await expect(run()).resolves.not.toThrow()
Expand All @@ -152,18 +150,14 @@ describe('add-pr-comment action', () => {
it('fails when both message and message-path are defined', async () => {
inputs.message = 'foobar'
inputs['message-path'] = path.resolve(__dirname, './message.txt')
inputs['repo-token'] = repoToken

await expect(run()).resolves.not.toThrow()
expect(core.setFailed).toHaveBeenCalledWith('must specify only one, message or message-path')
})

it('creates a comment in an existing PR', async () => {
process.env['GITHUB_TOKEN'] = repoToken

inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'true'

github.context.payload = {
Expand Down Expand Up @@ -204,7 +198,6 @@ describe('add-pr-comment action', () => {
it('creates a message when the message id does not exist', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'
inputs['message-id'] = 'custom-id'

Expand All @@ -224,7 +217,6 @@ describe('add-pr-comment action', () => {
it('identifies an existing message by id and updates it', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'

const commentId = 123
Expand All @@ -250,7 +242,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a success message on success', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'
inputs['message-success'] = '666'
inputs.status = 'success'
Expand All @@ -273,7 +264,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a failure message on failure', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'
inputs['message-failure'] = '666'
inputs.status = 'failure'
Expand All @@ -296,7 +286,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a cancelled message on cancelled', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'
inputs['message-cancelled'] = '666'
inputs.status = 'cancelled'
Expand All @@ -319,7 +308,6 @@ describe('add-pr-comment action', () => {
it('overrides the default message with a skipped message on skipped', async () => {
inputs.message = simpleMessage
inputs['message-path'] = undefined
inputs['repo-token'] = repoToken
inputs['allow-repeats'] = 'false'
inputs['message-skipped'] = '666'
inputs.status = 'skipped'
Expand Down
10 changes: 5 additions & 5 deletions action.yml
Expand Up @@ -10,26 +10,26 @@ inputs:
message-id:
description: "An optional id to use for this message."
default: "add-pr-comment"
required: false
required: true
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."
default: "false"
required: false
required: true
repo-token:
description: "A GitHub token for API access. Defaults to {{ github.token }}."
default: "${{ github.token }}"
required: false
required: true
allow-repeats:
description: "Allow messages to be repeated."
default: "false"
required: false
required: true
proxy-url:
description: "Proxy URL for comment creation"
required: false
status:
description: "A job status for status headers. Defaults to {{ job.status }}."
default: "${{ job.status }}"
required: false
required: true
message-success:
description: "Override the message when a run is successful."
required: false
Expand Down

0 comments on commit 7ca8398

Please sign in to comment.