@@ -7,9 +7,9 @@ const { generateWorkflowIdMarker } = require("./generate_footer.cjs");
77const { sanitizeContent } = require ( "./sanitize_content.cjs" ) ;
88const { ERR_API , ERR_NOT_FOUND , ERR_VALIDATION } = require ( "./error_codes.cjs" ) ;
99const { buildWorkflowRunUrl } = require ( "./workflow_metadata_helpers.cjs" ) ;
10- const { resolveTopLevelDiscussionCommentId } = require ( "./github_api_helpers.cjs" ) ;
10+ const { createDiscussionComment , resolveTopLevelDiscussionCommentId } = require ( "./github_api_helpers.cjs" ) ;
1111const { resolveInvocationContext } = require ( "./invocation_context_helpers.cjs" ) ;
12- const { addReaction, addDiscussionReaction, getDiscussionNodeId } = require ( "./add_reaction.cjs" ) ;
12+ const { addReaction, addDiscussionReaction, getDiscussionNodeId, REACTION_MAP } = require ( "./add_reaction.cjs" ) ;
1313
1414/**
1515 * Event type descriptions for comment messages
@@ -25,7 +25,7 @@ const EVENT_TYPE_DESCRIPTIONS = {
2525} ;
2626
2727/** Valid GitHub reaction types */
28- const VALID_REACTIONS = Object . freeze ( [ "+1" , "-1" , "laugh" , "confused" , "heart" , "hooray" , "rocket" , "eyes" ] ) ;
28+ const VALID_REACTIONS = Object . freeze ( Object . keys ( REACTION_MAP ) ) ;
2929
3030/**
3131 * Resolve the reaction and comment API endpoints for a given event.
@@ -140,7 +140,14 @@ async function resolveEventEndpoints(eventName, owner, repo, payload) {
140140async function main ( ) {
141141 const reaction = process . env . GH_AW_REACTION || "eyes" ;
142142 const commandsJSON = process . env . GH_AW_COMMANDS ;
143- const command = commandsJSON ? ( JSON . parse ( commandsJSON ) [ 0 ] ?? null ) : null ; // Only present for command workflows
143+ let command = null ; // Only present for command workflows
144+ if ( commandsJSON ) {
145+ try {
146+ command = JSON . parse ( commandsJSON ) [ 0 ] ?? null ;
147+ } catch ( err ) {
148+ throw new Error ( "Failed to parse GH_AW_COMMANDS: " + getErrorMessage ( err ) , { cause : err } ) ;
149+ }
150+ }
144151 const invocationContext = resolveInvocationContext ( context ) ;
145152 const runUrl = buildWorkflowRunUrl ( context , invocationContext . workflowRepo ) ;
146153
@@ -250,19 +257,7 @@ async function addCommentWithWorkflowLink(endpoint, runUrl, eventName, invocatio
250257 // For discussion_comment events, thread the reply under the triggering comment.
251258 // GitHub Discussions only supports two nesting levels, so resolve the top-level parent node ID.
252259 const replyToId = eventName === "discussion_comment" ? await resolveTopLevelDiscussionCommentId ( github , eventPayload ?. comment ?. node_id ) : null ;
253- const mutation = replyToId
254- ? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
255- addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
256- comment { id url }
257- }
258- }`
259- : `mutation($dId: ID!, $body: String!) {
260- addDiscussionComment(input: { discussionId: $dId, body: $body }) {
261- comment { id url }
262- }
263- }` ;
264- const result = await github . graphql ( mutation , { dId : discussionId , body : commentBody , ...( replyToId ? { replyToId } : { } ) } ) ;
265- const comment = result . addDiscussionComment . comment ;
260+ const comment = await createDiscussionComment ( github , discussionId , commentBody , replyToId ) ;
266261 setCommentOutputs ( comment . id , comment . url , eventRepo ) ;
267262 return ;
268263 }
0 commit comments