Skip to content

Commit

Permalink
feat: add actions output variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thollander committed Oct 7, 2023
1 parent a56dba3 commit 9ffcced
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:

- name: Comment PR with message
uses: ./
id: nrt_message
with:
message: |
Current branch is `${{ github.head_ref }}`.
Expand Down Expand Up @@ -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
18 changes: 14 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
? `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`
: null;
Expand Down Expand Up @@ -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') {
Expand All @@ -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) {
Expand Down
34 changes: 28 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? `<!-- thollander/actions-comment-pull-request "${comment_tag}" -->`
: null;
Expand Down Expand Up @@ -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.');
Expand All @@ -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);
Expand Down

0 comments on commit 9ffcced

Please sign in to comment.