Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 7 additions & 10 deletions actions/setup/js/add_reaction_and_edit_comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ async function main() {
const command = process.env.GH_AW_COMMAND; // Only present for command workflows
const runId = context.runId;
const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com";
const runUrl = context.payload.repository
? `${context.payload.repository.html_url}/actions/runs/${runId}`
: `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;

core.info(`Reaction type: ${reaction}`);
core.info(`Command name: ${command || "none"}`);
Expand All @@ -26,7 +24,10 @@ async function main() {
return;
}

const { eventName, repo: { owner, repo } } = context;
const {
eventName,
repo: { owner, repo },
} = context;
let reactionEndpoint;
let commentUpdateEndpoint;
const shouldCreateComment = true; // Always create comments for all events
Expand Down Expand Up @@ -122,9 +123,7 @@ async function main() {

// Add reaction first (use GraphQL for discussions, REST for others)
const isDiscussionEvent = eventName === "discussion" || eventName === "discussion_comment";
await (isDiscussionEvent
? addDiscussionReaction(reactionEndpoint, reaction)
: addReaction(reactionEndpoint, reaction));
await (isDiscussionEvent ? addDiscussionReaction(reactionEndpoint, reaction) : addReaction(reactionEndpoint, reaction));

// Then add comment
core.info(`Comment endpoint: ${commentUpdateEndpoint}`);
Expand Down Expand Up @@ -217,8 +216,6 @@ async function getDiscussionId(owner, repo, discussionNumber) {
return repository.discussion;
}



/**
* Add a comment with a workflow run link
* @param {string} endpoint - The GitHub API endpoint to create the comment (or special format for discussions)
Expand Down Expand Up @@ -286,7 +283,7 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName) {

const discussionId = repository.discussion.id;
const mutationParams = { dId: discussionId, body: commentBody };

// Add replyToId for comment threads
if (eventName === "discussion_comment") {
mutationParams.replyToId = context.payload?.comment?.node_id;
Expand Down
2 changes: 1 addition & 1 deletion actions/setup/js/add_reaction_and_edit_comment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const mockCore = {
(global.context.eventName = "discussion_comment"),
(global.context.payload = { discussion: { number: 10 }, comment: { id: 123 }, repository: { html_url: "https://github.com/testowner/testrepo" } }),
await eval(`(async () => { ${reactionScript}; await main(); })()`),
expect(mockCore.setFailed).toHaveBeenCalledWith("Discussion comment node ID not found in event payload"),
expect(mockCore.setFailed).toHaveBeenCalledWith("Discussion or comment information not found in event payload"),
expect(mockGithub.graphql).not.toHaveBeenCalled());
}));
}),
Expand Down