diff --git a/README.md b/README.md index 33522b4..6fc9e5c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ matching comments are immediately deleted. ## Usage -Create a `reaction-comments.yml` workflow file in the `.github/workflows` +Create the `reaction-comments.yml` workflow file in the `.github/workflows` directory, use one of the [example workflows](#examples) to get started. ### Inputs @@ -37,8 +37,8 @@ The action can be configured using [input parameters](https://docs.github.com/en secret that contains a [personal access token](#using-a-personal-access-token) - Optional, defaults to `${{ github.token }}` - **`exempt-issue-labels`** - - Do not process comments on issues with these labels, value must be - a comma separated list of labels + - Do not process comments on issues with any of these labels, + value must be a comma separated list of labels - Optional, defaults to `''` - **`issue-comment`** - Replace reaction comments on issues with this message, @@ -46,8 +46,8 @@ The action can be configured using [input parameters](https://docs.github.com/en - Optional, defaults to `:wave: @{comment-author}, would you like to leave a reaction instead?` - **`exempt-pr-labels`** - - Do not process comments on pull requests with these labels, value must be - a comma separated list of labels + - Do not process comments on pull requests with any of these labels, + value must be a comma separated list of labels - Optional, defaults to `''` - **`pr-comment`** - Replace reaction comments on pull requests with this message, @@ -58,6 +58,9 @@ The action can be configured using [input parameters](https://docs.github.com/en - Process comments only on issues or pull requests, value must be either `issues` or `prs` - Optional, defaults to `''` +- **`log-output`** + - Log output parameters, value must be either `true` or `false` + - Optional, defaults to `false` ### Outputs @@ -136,6 +139,7 @@ jobs: :wave: @{comment-author}, would you like to leave a reaction instead? process-only: '' + log-output: false ``` ### Ignoring comments diff --git a/action.yml b/action.yml index 891ae75..f8cd7c1 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,9 @@ inputs: process-only: description: 'Process comments only on issues or pull requests, value must be either `issues` or `prs`' default: '' + log-output: + description: 'Log output parameters, value must be either `true` or `false`' + default: false outputs: comments: description: 'Comments that have been either deleted or scheduled for removal, value is a JSON string' diff --git a/src/index.js b/src/index.js index d1cca48..6055710 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,8 @@ const zip = require('adm-zip'); const schema = require('./schema'); -const reactionRx = /^(?:\s*(?:\+1|-1|:(?:\+1|-1|thumbsup|thumbsdown|smile|tada|confused|heart|rocket|eyes):|\u{1f44d}(?:\u{1f3fb}|\u{1f3fc}|\u{1f3fd}|\u{1f3fe}|\u{1f3ff})?|\u{1f44e}(?:\u{1f3fb}|\u{1f3fc}|\u{1f3fd}|\u{1f3fe}|\u{1f3ff})?|\u{1f604}|\u{1f389}|\u{1f615}|\u{2764}\u{fe0f}|\u{1f680}|\u{1f440})\s*)+$/u; +const reactionRx = + /^(?:\s*(?:\+1|-1|:(?:\+1|-1|thumbsup|thumbsdown|smile|tada|confused|heart|rocket|eyes):|\u{1f44d}(?:\u{1f3fb}|\u{1f3fc}|\u{1f3fd}|\u{1f3fe}|\u{1f3ff})?|\u{1f44e}(?:\u{1f3fb}|\u{1f3fc}|\u{1f3fd}|\u{1f3fe}|\u{1f3ff})?|\u{1f604}|\u{1f389}|\u{1f615}|\u{2764}\u{fe0f}|\u{1f680}|\u{1f440})\s*)+$/u; async function run() { try { @@ -23,9 +24,16 @@ async function run() { output = await app.processNewComment(); } - if (output) { - core.debug('Setting output (comments)'); + core.debug('Setting output (comments)'); + if (output && output.length) { core.setOutput('comments', JSON.stringify(output)); + + if (config['log-output']) { + core.info('Output (comments):'); + core.info(JSON.stringify(output, null, 2)); + } + } else { + core.setOutput('comments', ''); } } catch (err) { core.setFailed(err); diff --git a/src/schema.js b/src/schema.js index 96929d8..8024fae 100644 --- a/src/schema.js +++ b/src/schema.js @@ -1,36 +1,40 @@ const Joi = require('joi'); -const extendedJoi = Joi.extend({ - type: 'stringList', - base: Joi.array(), - coerce: { - from: 'string', - method(value) { - value = value.trim(); - if (value) { - value = value - .split(',') - .map(item => item.trim()) - .filter(Boolean); - } +const extendedJoi = Joi.extend(joi => { + return { + type: 'stringList', + base: joi.array(), + coerce: { + from: 'string', + method(value) { + value = value.trim(); + if (value) { + value = value + .split(',') + .map(item => item.trim()) + .filter(Boolean); + } - return {value}; - } - } -}).extend({ - type: 'processOnly', - base: Joi.string(), - coerce: { - from: 'string', - method(value) { - value = value.trim(); - if (['issues', 'prs'].includes(value)) { - value = value.slice(0, -1); + return {value}; } + } + }; +}).extend(joi => { + return { + type: 'processOnly', + base: joi.string(), + coerce: { + from: 'string', + method(value) { + value = value.trim(); + if (['issues', 'prs'].includes(value)) { + value = value.slice(0, -1); + } - return {value}; + return {value}; + } } - } + }; }); const schema = Joi.object({ @@ -76,7 +80,12 @@ const schema = Joi.object({ ':wave: @{comment-author}, would you like to leave a reaction instead?' ), - 'process-only': extendedJoi.processOnly().valid('issue', 'pr', '').default('') + 'process-only': extendedJoi + .processOnly() + .valid('issue', 'pr', '') + .default(''), + + 'log-output': Joi.boolean().default(false) }); module.exports = schema;