diff --git a/action.yml b/action.yml index 0e38ae7..d7106fb 100644 --- a/action.yml +++ b/action.yml @@ -11,5 +11,5 @@ outputs: pre_release: description: 'Whether it is a release candidate' runs: - using: 'node12' + using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 9e1c48f..4ad0eee 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12958,9 +12958,9 @@ function run() { approved = true; } } - core.info(JSON.stringify(reviews.data)); if (!approved) { - core.setFailed('An approval is required to generate a release candidate.'); + yield addComment(pr.number, `:warning: An approval is required to create a release candidate. :warning:`); + core.setFailed('An approval is required to create a release candidate.'); return; } yield createTag(pr); @@ -12973,13 +12973,7 @@ function run() { // Opened: if (prPayload.action === 'opened') { yield addLabel(prPayload.pull_request); - const params = { - repo, - issue_number: prPayload.number, - owner, - body: `Add a comment including \`#tag\` to create a release candidate tag.` - }; - yield octokit.issues.createComment(params); + yield addComment(prPayload.number, `Add a comment including \`#tag\` to create a release candidate tag.`); return; } // Continue only when PR is closed and merged: @@ -13012,6 +13006,17 @@ function addLabel(pr) { }); }); } +function addComment(prNumber, body) { + return __awaiter(this, void 0, void 0, function* () { + const params = { + repo, + issue_number: prNumber, + owner, + body + }; + yield octokit.issues.createComment(params); + }); +} function bash(cmd) { return __awaiter(this, void 0, void 0, function* () { return new Promise(function (resolve, reject) { @@ -13119,13 +13124,7 @@ function createTag(pr) { core.setOutput("new_tag", newTag); core.setOutput("pre_release", preRelease); // Create comment - const params = { - repo, - issue_number: prNumber, - owner, - body: `:label: ${preRelease ? 'Pre-release' : 'Release'} \`${newTag}\` created. [See build.](https://circleci.com/gh/mercadolibre/${repo})` - }; - const new_comment = yield octokit.issues.createComment(params); + yield addComment(prNumber, `:label: ${preRelease ? 'Pre-release' : 'Release'} \`${newTag}\` created. [See build.](https://circleci.com/gh/mercadolibre/${repo})`); }); } run(); diff --git a/index.ts b/index.ts index ce23f76..9cf92b4 100755 --- a/index.ts +++ b/index.ts @@ -50,9 +50,9 @@ async function run() { approved = true } } - core.info(JSON.stringify(reviews.data)) if(!approved) { - core.setFailed('An approval is required to generate a release candidate.'); + await addComment(pr.number, `:warning: An approval is required to create a release candidate. :warning:`); + core.setFailed('An approval is required to create a release candidate.'); return } @@ -67,13 +67,7 @@ async function run() { // Opened: if (prPayload.action === 'opened') { await addLabel(prPayload.pull_request) - const params = { - repo, - issue_number: prPayload.number, - owner, - body: `Add a comment including \`#tag\` to create a release candidate tag.` - }; - await octokit.issues.createComment(params); + await addComment(prPayload.number, `Add a comment including \`#tag\` to create a release candidate tag.`) return } // Continue only when PR is closed and merged: @@ -104,6 +98,16 @@ async function addLabel(pr: WebhookPayloadPullRequestPullRequest) { }) } +async function addComment(prNumber:number, body:string) { + const params = { + repo, + issue_number: prNumber, + owner, + body + }; + await octokit.issues.createComment(params); +} + async function bash(cmd) { return new Promise<{stdout: string, stderr:string}>(function (resolve, reject) { exec(cmd, (err, stdout, stderr) => { @@ -208,13 +212,7 @@ async function createTag(pr: WebhookPayloadPullRequestPullRequest) { core.setOutput("pre_release", preRelease); // Create comment - const params = { - repo, - issue_number: prNumber, - owner, - body: `:label: ${preRelease ? 'Pre-release' : 'Release'} \`${newTag}\` created. [See build.](https://circleci.com/gh/mercadolibre/${repo})` - }; - const new_comment = await octokit.issues.createComment(params); + await addComment(prNumber, `:label: ${preRelease ? 'Pre-release' : 'Release'} \`${newTag}\` created. [See build.](https://circleci.com/gh/mercadolibre/${repo})`) } run()