Skip to content

Commit

Permalink
Add PR title & body outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tlvenn committed Oct 17, 2019
1 parent af6590c commit aa8f2b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ If the event is a `pull_request`, it's very easy to get the current PR number
from the context via `${{ github.event.number }}`, but unfortunately this
information does not seem to be readily available for a `push` event. This
action sends a request to GitHub to find the PR associated with the current SHA,
and returns it in the `pr` output. `pr` will be an empty string if there is no
and returns its number in the `number` output. `number` will be an empty string if there is no
PR.

Additionnaly, `title` and `body` outputs are available as well to get the respective title and body of the PR.

## Usage

```yaml
Expand All @@ -21,7 +23,7 @@ PR.
github-token: ${{ secrets.GITHUB_TOKEN }}
# This will echo "Your PR is 7", or be skipped if there is no current PR.
- run: echo "Your PR is ${PR}"
if: success() && steps.findPr.outputs.pr
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
```
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ inputs:
required: false
outputs:
pr:
description: The PR if one was found. (e.g. '345' for #345)
description: The PR if one was found. (e.g. '345' for #345) [Deprecated: Please use number instead]
number:
description: The PR's number if the PR was found (e.g. '345' for #345)
title:
description: The PR's title if the PR was found
body:
description: The PR's body if the PR was found
runs:
using: node12
main: 'main.js'
Expand Down
7 changes: 5 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ async function main() {
commit_sha: sha || context.sha,
});

const pr = result.data.length > 0 && result.data[0].number;
const pr = result.data.length > 0 && result.data[0];

core.setOutput('pr', pr || '');
core.setOutput('pr', pr && pr.number || '');
core.setOutput('number', pr && pr.number || '');
core.setOutput('title', pr && pr.title || '');
core.setOutput('body', pr && pr.body || '');
}

main().catch(err => core.setFailed(err.message));

0 comments on commit aa8f2b1

Please sign in to comment.