Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

fix(#29): trim #30

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
const core = require("@actions/core");
const { context, GitHub } = require("@actions/github");

const MAP = {
"issue_comment": {
"key": "comment"
},
"pull_request_comment": {
"key": "pull_request"
}
}

async function run() {
const trigger = core.getInput("trigger", { required: true });

Expand All @@ -12,18 +21,13 @@ async function run() {
core.setFailed('If "reaction" is supplied, GITHUB_TOKEN is required');
return;
}
const {eventName, payload} = context;
const body = payload[MAP[eventName]["key"]].body.trim();

const body =
(context.eventName === "issue_comment"
// For comments on pull requests
? context.payload.comment.body
// For the initial pull request description
: context.payload.pull_request.body) || '';
core.setOutput('comment_body', body);

if (
context.eventName === "issue_comment" &&
!context.payload.issue.pull_request
eventName === "issue_comment" &&
!payload.issue.pull_request
) {
// not a pull-request comment, aborting
core.setOutput("triggered", "false");
Expand Down