From c4ffc74b36ad4516d2e904d8df5282c150aae7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9rence=20Hollander?= Date: Sat, 7 Oct 2023 15:42:45 +0200 Subject: [PATCH] feat: add actions output variables --- lib/index.js | 18 ++++++++++++++---- src/main.ts | 34 ++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1969ff31..e4ddf78e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9582,6 +9582,18 @@ async function run() { }); })); } + async function createComment({ owner, repo, issue_number, body, }) { + const { data: comment } = await octokit.rest.issues.createComment({ + owner, + repo, + issue_number, + body, + }); + core.setOutput('body', comment.body); + core.setOutput('url', comment.url); + await addReactions(comment.id, reactions); + return comment; + } const comment_tag_pattern = comment_tag ? `` : null; @@ -9611,12 +9623,11 @@ async function run() { ...context.repo, comment_id: comment.id, }); - const { data: newComment } = await octokit.rest.issues.createComment({ + await createComment({ ...context.repo, issue_number, body, }); - await addReactions(newComment.id, reactions); return; } else if (mode === 'delete') { @@ -9635,12 +9646,11 @@ async function run() { return; } } - const { data: comment } = await octokit.rest.issues.createComment({ + await createComment({ ...context.repo, issue_number, body, }); - await addReactions(comment.id, reactions); } catch (error) { if (error instanceof Error) { diff --git a/src/main.ts b/src/main.ts index 4e05a8c9..74ddfa25 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,6 +55,32 @@ async function run() { ); } + async function createComment({ + owner, + repo, + issue_number, + body, + }: { + owner: string; + repo: string; + issue_number: number; + body: string; + }) { + const { data: comment } = await octokit.rest.issues.createComment({ + owner, + repo, + issue_number, + body, + }); + + core.setOutput('body', comment.body); + core.setOutput('url', comment.url); + + await addReactions(comment.id, reactions); + + return comment; + } + const comment_tag_pattern = comment_tag ? `` : null; @@ -88,13 +114,11 @@ async function run() { comment_id: comment.id, }); - const { data: newComment } = await octokit.rest.issues.createComment({ + await createComment({ ...context.repo, issue_number, body, }); - - await addReactions(newComment.id, reactions); return; } else if (mode === 'delete') { core.debug('Registering this comment to be deleted.'); @@ -112,13 +136,11 @@ async function run() { } } - const { data: comment } = await octokit.rest.issues.createComment({ + await createComment({ ...context.repo, issue_number, body, }); - - await addReactions(comment.id, reactions); } catch (error) { if (error instanceof Error) { core.setFailed(error.message);