-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move the try catch to the bottom of the script
This is mostly for my readability. I found this to be a nice flow when recently working on our planningcenter/plus-one-action GitHub action.
- Loading branch information
Showing
1 changed file
with
26 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
|
||
const run = async () => { | ||
try { | ||
const githubToken = core.getInput('github_token') | ||
async function run() { | ||
const githubToken = core.getInput('github_token') | ||
|
||
if (!githubToken) throw Error(`input 'github_token' is required`) | ||
if (!githubToken) throw Error(`input 'github_token' is required`) | ||
|
||
const client = github.getOctokit(githubToken) | ||
const owner = github.context.payload.repository.owner.login | ||
const repo = github.context.payload.repository.name | ||
const issue_number = github.context.payload.pull_request.number | ||
const client = github.getOctokit(githubToken) | ||
const owner = github.context.payload.repository.owner.login | ||
const repo = github.context.payload.repository.name | ||
const issue_number = github.context.payload.pull_request.number | ||
|
||
const pr = github.context.payload.pull_request | ||
const assignees = pr.assignees | ||
const author = pr.user | ||
const pr = github.context.payload.pull_request | ||
const assignees = pr.assignees | ||
const author = pr.user | ||
|
||
console.log(`pr: ${JSON.stringify(pr, undefined, 2)}`) | ||
console.log(`pr: ${JSON.stringify(pr, undefined, 2)}`) | ||
|
||
if ( | ||
(!assignees || assignees.length === 0) && | ||
!author.is_bot | ||
) { | ||
await client.request( | ||
`POST /repos/${owner}/${repo}/issues/${issue_number}/assignees`, | ||
{ owner, repo, issue_number, assignees: [author.login] } | ||
) | ||
} | ||
} catch (error) { | ||
console.log('Error:', error) | ||
core.error(error) | ||
core.setFailed(error) | ||
if ( | ||
(!assignees || assignees.length === 0) && | ||
!author.is_bot | ||
) { | ||
await client.request( | ||
`POST /repos/${owner}/${repo}/issues/${issue_number}/assignees`, | ||
{ owner, repo, issue_number, assignees: [author.login] } | ||
) | ||
} | ||
} | ||
|
||
run() | ||
try { | ||
run() | ||
} catch (error) { | ||
console.log('Error:', error) | ||
core.error(error) | ||
core.setFailed(error.message) | ||
} |