diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6dd879c..ec486d2c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,6 +15,7 @@ jobs: - name: Comment PR with message uses: ./ + id: nrt_message with: message: | Current branch is `${{ github.head_ref }}`. @@ -55,5 +56,8 @@ jobs: comment_tag: nrt_create_if_not_exists create_if_not_exists: false + - name: Check output + run: echo "${{steps.nrt_message.outputs.body}}" + - name: (AFTER) Setup test cases run: rm /tmp/foobar.txt \ No newline at end of file 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);