Skip to content

Commit

Permalink
Add filter prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dovyski committed Jan 16, 2020
1 parent 2c937eb commit 173d489
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
uses: ./ # Uses an action in the root directory
id: extract
with:
filter_push: '.pusher.name'
filter_pull_request: '.pull_request'
filter_push: '.commits'
filter_pull_request: '.pull_request.commits'
# Use the output from the `infos` step
- name: Show output
run: |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: 'Filter to be applied to the webhook payload object in case of a pull request.'
required: false
default: '.pull_request.'
filter_prefix:
description: 'String to be prefixed to all filters.'
required: false
default: '.[]'
output:
description: 'Type of output. It can be "pretty", "json", "compact", or "string".'
required: false
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require('path');
try {
const filterPush = core.getInput('filter_push');
const filterPullRequest = core.getInput('filter_pull_request');
const filterPrefix = core.getInput('filter_prefix');
const shouldDump = core.getInput('dump');
const dumpPath = core.getInput('dump_path');
const shouldPrint = core.getInput('print');
Expand All @@ -16,13 +17,12 @@ try {

const isPullRequest = github.context.payload.pull_request !== undefined;
const branch = isPullRequest ? github.context.payload.pull_request.head.ref : path.basename(github.context.payload.ref);
const filter = isPullRequest ? filterPullRequest : filterPush;
const filter = filterPrefix + (isPullRequest ? filterPullRequest : filterPush);

core.setOutput('pull_request', JSON.stringify(isPullRequest));
core.setOutput('branch', branch);

console.log(`Filter: ${filter}`);
console.debug(JSON.stringify(github.context.payload));

jq.run(filter, JSON.stringify(github.context.payload), {
input: 'string',
Expand All @@ -41,7 +41,9 @@ try {
const payload = JSON.stringify(github.context.payload, undefined, 2);

if(shouldPrint) {
console.log(`Payload: ${payload}`);
core.startGroup('Payload');
console.log(payload);
core.endGroup()
}

if(shouldDump) {
Expand Down

0 comments on commit 173d489

Please sign in to comment.