Skip to content

Commit

Permalink
Add debug logging (#20)
Browse files Browse the repository at this point in the history
* add debug logging

* npm run build

* one try block

* auto-closer patch

* auto-closer patch

* prettier printing
  • Loading branch information
dacbd committed Apr 23, 2022
1 parent 5b965ff commit a5590b8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ on:
types:
- labeled
- opened
concurrency:
group: ${{ github.event.issue.number }}
jobs:
delete-test-issues:
runs-on: ubuntu-latest
steps:
- run: |
is_test=$(echo "${{ toJSON(github.event) }}" | jq '.issue.labels[].name == "test"' | grep true)
is_test=$(echo '${{ toJSON(github.event) }}' | jq '.issue.labels[].name == "test"' | grep true)
if [[ -z "$is_test" ]]; then
curl --slient --show-error \
--request PATCH \
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ steps:
status - `${{ job.status }}`
assignees: SomeUsername,AnotherUsername
```
## Issues & debugging
If you encounter issues with my action feel free to create an issue or a PR, happy to take improvements or requests.
More verbose logging can be enabled via GitHub Actions feature: [`ACTIONS_STEP_DEBUG`](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging)
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8573,18 +8573,26 @@ const listToArray = (str) => {

const rtrue = { required: true };
const token = Core.getInput('token', rtrue);
Core.debug(`Using token: ${token}`);

// required but defaults not handled by action.yml
const repoContext = Github.context.repo;
const owner = Core.getInput('owner') || repoContext.owner;
const repo = Core.getInput('repo') || repoContext.repo;
const title = Core.getInput('title', rtrue);
Core.debug(`Using owner: ${owner}`);
Core.debug(`Using repo: ${repo}`);
Core.debug(`Using title: ${title}`);

// optional
const body = Core.getInput('body');
const milestone = Core.getInput('milestone');
const labels = Core.getInput('labels');
const assignees = Core.getInput('assignees');
Core.debug(`Using body: """${body}"""`);
Core.debug(`Using milestone: ${milestone}`);
Core.debug(`Using labels: ${labels}`);
Core.debug(`Using assignees: ${assignees}`);

const octokit = Github.getOctokit(token);
const opts = Object.fromEntries(Object.entries({
Expand All @@ -8596,13 +8604,14 @@ const listToArray = (str) => {
labels: labels ? listToArray(labels) : null,
assignees: assignees ? listToArray(assignees) : null
}).filter(([_, v]) => v != null));

Core.debug(`Object for new issue: """${JSON.stringify(opts, null, 2)}"""`)
// https://docs.github.com/en/rest/reference/issues#create-an-issue
const newIssue = await octokit.rest.issues.create(opts);
console.log('Created:', newIssue.data.html_url);
Core.info(`Created: ${newIssue.data.html_url}`)
} catch (err) {

Core.setFailed(err.message);
Core.error(err);
Core.setFailed('Request to create new issue failed');
}
})();

Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ const listToArray = (str) => {

const rtrue = { required: true };
const token = Core.getInput('token', rtrue);
Core.debug(`Using token: ${token}`);

// required but defaults not handled by action.yml
const repoContext = Github.context.repo;
const owner = Core.getInput('owner') || repoContext.owner;
const repo = Core.getInput('repo') || repoContext.repo;
const title = Core.getInput('title', rtrue);
Core.debug(`Using owner: ${owner}`);
Core.debug(`Using repo: ${repo}`);
Core.debug(`Using title: ${title}`);

// optional
const body = Core.getInput('body');
const milestone = Core.getInput('milestone');
const labels = Core.getInput('labels');
const assignees = Core.getInput('assignees');
Core.debug(`Using body: """${body}"""`);
Core.debug(`Using milestone: ${milestone}`);
Core.debug(`Using labels: ${labels}`);
Core.debug(`Using assignees: ${assignees}`);

const octokit = Github.getOctokit(token);
const opts = Object.fromEntries(Object.entries({
Expand All @@ -38,12 +46,13 @@ const listToArray = (str) => {
labels: labels ? listToArray(labels) : null,
assignees: assignees ? listToArray(assignees) : null
}).filter(([_, v]) => v != null));

Core.debug(`Object for new issue: """${JSON.stringify(opts, null, 2)}"""`)
// https://docs.github.com/en/rest/reference/issues#create-an-issue
const newIssue = await octokit.rest.issues.create(opts);
console.log('Created:', newIssue.data.html_url);
Core.info(`Created: ${newIssue.data.html_url}`)
} catch (err) {

Core.setFailed(err.message);
Core.error(err);
Core.setFailed('Request to create new issue failed');
}
})();

0 comments on commit a5590b8

Please sign in to comment.