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 c4ffc74
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
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 c4ffc74

Please sign in to comment.