Skip to content

Commit

Permalink
expose the new issue via action outputs (#24)
Browse files Browse the repository at this point in the history
* expose issue object

* tweak outputs names

* tweak tests

* update test.yml

* quote issue?
  • Loading branch information
dacbd authored May 1, 2022
1 parent a5590b8 commit 7d17997
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ name: Auto Issue closer
on:
issues:
types:
- labeled
- opened
concurrency:
group: ${{ github.event.issue.number }}
jobs:
delete-test-issues:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'test')
steps:
- run: |
is_test=$(echo '${{ toJSON(github.event) }}' | jq '.issue.labels[].name == "test"' | grep true)
if [[ -z "$is_test" ]]; then
curl --slient --show-error \
--request PATCH \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: token ${{ secrets.PAT }}" \
--url "https://api.github.com/repos/dacbd/create-issue-action/issues/${{ github.event.issue.number }}" \
--data '{"state":"closed"}'
fi
curl --slient --show-error \
--request PATCH \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: token ${{ secrets.PAT }}" \
--url "https://api.github.com/repos/dacbd/create-issue-action/issues/${{ github.event.issue.number }}" \
--data '{"state":"closed"}'
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: test
id: new-issue
uses: ./
with:
token: ${{ secrets.PAT }}
Expand All @@ -39,6 +40,13 @@ jobs:
multiline
labels: test,bot
assignees: dacbd
- name: View action outputs
run: |
echo "${{ steps.new-issue.outputs.number }}"
echo "${{ steps.new-issue.outputs.html_url }}"
echo '${{ steps.new-issue.outputs.json }}' | jq
echo '${{ steps.new-issue.outputs.json }}' | jq .state
echo '${{ steps.new-issue.outputs.json }}' | jq .labels[].name
push-test:
if: github.event_name == 'push'
needs: [build]
Expand Down
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ options for `with:`
| labels | | A comma seperated list of labels |
| assignees | | A comma seperated list of GitHub usernames to assign the issue to |

## Outputs
| output | value |
| ------ | ----- |
| json | [See Response](https://docs.github.com/en/rest/issues/issues#create-an-issue) |
| html_url | the issue's web url |
| number | the issue's number |

## Usage
Limited testing has been done, and only on `ubuntu-latest`

Basic Usage:
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: create an issue
uses: dacbd/create-issue-action@main
with:
Expand All @@ -34,7 +41,7 @@ steps:
The reason for being usage:
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Something that might fail
run: exit 1
- name: Create Issue on Failed workflow
Expand All @@ -52,6 +59,48 @@ steps:
status - `${{ job.status }}`
assignees: SomeUsername,AnotherUsername
```
## Other examples
Using outputs:
```yml
...
steps:
- uses: actions/checkout@v3
- uses: dacbd/create-issue-action@v1
id: new-issue
with:
token: ${{ github.token }}
title: Simple test issue
body: my new issue
- run: |
echo "${{ steps.new-issue.outputs.json }}" | jq
echo "${{ steps.new-issue.outputs.json }}" | jq .state
echo "${{ steps.new-issue.outputs.json }}" | jq .labels[].name
```
Transpose issues to a private repo:
```yml
name: transpose issue
issues:
types: [labeled]
job:
transpose:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'backend')
steps:
- name: Copy Issue
uses: dacbd/create-issue-action@v1
with:
token: ${{ secrets.PAT }}
org: octo-org
repo: private-backend-service
title: ${{ github.event.issue.title }}
body: |
Closes: ${{ github.event.issue.html_url }}
# Body
${{ github.event.issue.body }}
```
## Issues & debugging
If you encounter issues with my action feel free to create an issue or a PR, happy to take improvements or requests.
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ inputs:
assignees:
description: CSV of github usernames to assign (e.x. 'dacbd,nlf')
required: false
outputs:
json:
description: The JSON for the new created issue returned from the GitHub API
html_url:
description: The web url of the new issue
number:
description: "The new issue's number"
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8608,6 +8608,9 @@ const listToArray = (str) => {
// https://docs.github.com/en/rest/reference/issues#create-an-issue
const newIssue = await octokit.rest.issues.create(opts);
Core.info(`Created: ${newIssue.data.html_url}`)
Core.setOutput("json", JSON.stringify(newIssue.data));
Core.setOutput("number", newIssue.data.number);
Core.setOutput("html_url", newIssue.data.html_url);
} catch (err) {

Core.error(err);
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const listToArray = (str) => {
// https://docs.github.com/en/rest/reference/issues#create-an-issue
const newIssue = await octokit.rest.issues.create(opts);
Core.info(`Created: ${newIssue.data.html_url}`)
Core.setOutput("json", JSON.stringify(newIssue.data));
Core.setOutput("number", newIssue.data.number);
Core.setOutput("html_url", newIssue.data.html_url);
} catch (err) {

Core.error(err);
Expand Down

0 comments on commit 7d17997

Please sign in to comment.