Skip to content

Commit

Permalink
Turns missing pr in workflow_run into warning. (#5)
Browse files Browse the repository at this point in the history
* Turns missing pr in workflow_run into warning.

Sometimes (quite often really) when PR gets approved, the PR
gets merged rather quickly, without waiting for result of this
action. Or a new PR gets pushed quickly. In those cases PR will
not be found. But this is usually not a problem then and rather
than failing, we should simply print a warning and exit.

* fixup! Turns missing pr in workflow_run into warning.

Co-authored-by: Tobiasz Kędzierski <[email protected]>
  • Loading branch information
potiuk and Tobiasz Kędzierski authored Nov 1, 2020
1 parent 7872312 commit 4c5190f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,9 +1625,14 @@ function run() {
}
else if (eventName === 'workflow_run') {
if (pullRequestNumberInput === 'not set') {
throw Error(`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.`);
core.warning(`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.\n` +
`It might be missing because the pull request might have been already merged or a fixup pushed to` +
`the PR branch. None of the outputs will be set as we cannot find the right PR.`);
return;
}
else {
pullRequestNumber = parseInt(pullRequestNumberInput);
}
pullRequestNumber = parseInt(pullRequestNumberInput);
}
else {
throw Error(`This action is only useful in "pull_request_review" or "workflow_run" triggered runs and you used it in "${eventName}"`);
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ async function run(): Promise<void> {
}
} else if (eventName === 'workflow_run') {
if (pullRequestNumberInput === 'not set') {
throw Error(
`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.`
core.warning(
`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.\n` +
`It might be missing because the pull request might have been already merged or a fixup pushed to` +
`the PR branch. None of the outputs will be set as we cannot find the right PR.`
)
return
} else {
pullRequestNumber = parseInt(pullRequestNumberInput)
}
pullRequestNumber = parseInt(pullRequestNumberInput)
} else {
throw Error(
`This action is only useful in "pull_request_review" or "workflow_run" triggered runs and you used it in "${eventName}"`
Expand Down

0 comments on commit 4c5190f

Please sign in to comment.