Skip to content

Commit

Permalink
feat: add option for logging output parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Oct 2, 2021
1 parent c034188 commit 0e746c9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,17 +37,17 @@ 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,
`{comment-author}` is an optional placeholder
- 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,
Expand All @@ -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

Expand Down Expand Up @@ -136,6 +139,7 @@ jobs:
:wave: @{comment-author}, would you like to leave
a reaction instead?
process-only: ''
log-output: false
```
### Ignoring comments
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
65 changes: 37 additions & 28 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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;

0 comments on commit 0e746c9

Please sign in to comment.