22/// <reference types="@actions/github-script" />
33
44const { getErrorMessage } = require ( "./error_helpers.cjs" ) ;
5+ const { getMessages } = require ( "./messages_core.cjs" ) ;
56
67/**
78 * Update the activation comment with a link to the created pull request or issue
@@ -44,13 +45,9 @@ async function updateActivationCommentWithMessage(github, context, core, message
4445 const commentId = process . env . GH_AW_COMMENT_ID ;
4546 const commentRepo = process . env . GH_AW_COMMENT_REPO ;
4647
47- // If no comment was created in activation, skip updating
48- if ( ! commentId ) {
49- core . info ( "No activation comment to update (GH_AW_COMMENT_ID not set)" ) ;
50- return ;
51- }
52-
53- core . info ( `Updating activation comment ${ commentId } ` ) ;
48+ // Check if append-only-comments is enabled
49+ const messagesConfig = getMessages ( ) ;
50+ const appendOnlyComments = messagesConfig ?. appendOnlyComments === true ;
5451
5552 // Parse comment repo (format: "owner/repo") with validation
5653 let repoOwner = context . repo . owner ;
@@ -65,6 +62,98 @@ async function updateActivationCommentWithMessage(github, context, core, message
6562 }
6663 }
6764
65+ // Append-only mode: create a new comment instead of updating the activation comment
66+ if ( appendOnlyComments ) {
67+ core . info ( "Append-only-comments enabled: creating a new comment" ) ;
68+ try {
69+ const eventName = context . eventName ;
70+
71+ // Discussions: create a new discussion comment (threaded reply for discussion_comment)
72+ if ( eventName === "discussion" || eventName === "discussion_comment" ) {
73+ const discussionNumber = context . payload ?. discussion ?. number ;
74+ if ( ! discussionNumber ) {
75+ core . warning ( "Unable to determine discussion number for append-only comment; skipping" ) ;
76+ return ;
77+ }
78+
79+ const { repository } = await github . graphql (
80+ `
81+ query($owner: String!, $repo: String!, $num: Int!) {
82+ repository(owner: $owner, name: $repo) {
83+ discussion(number: $num) {
84+ id
85+ }
86+ }
87+ }` ,
88+ { owner : repoOwner , repo : repoName , num : discussionNumber }
89+ ) ;
90+
91+ const discussionId = repository ?. discussion ?. id ;
92+ if ( ! discussionId ) {
93+ core . warning ( "Unable to resolve discussion id for append-only comment; skipping" ) ;
94+ return ;
95+ }
96+
97+ const replyToId = eventName === "discussion_comment" ? context . payload ?. comment ?. node_id : null ;
98+ const mutation = replyToId
99+ ? `mutation($dId: ID!, $body: String!, $replyToId: ID!) {
100+ addDiscussionComment(input: { discussionId: $dId, body: $body, replyToId: $replyToId }) {
101+ comment { id url }
102+ }
103+ }`
104+ : `mutation($dId: ID!, $body: String!) {
105+ addDiscussionComment(input: { discussionId: $dId, body: $body }) {
106+ comment { id url }
107+ }
108+ }` ;
109+
110+ const variables = replyToId ? { dId : discussionId , body : message , replyToId } : { dId : discussionId , body : message } ;
111+ const result = await github . graphql ( mutation , variables ) ;
112+ const created = result ?. addDiscussionComment ?. comment ;
113+ const successMessage = label ? `Successfully created append-only discussion comment with ${ label } link` : "Successfully created append-only discussion comment" ;
114+ core . info ( successMessage ) ;
115+ if ( created ?. id ) core . info ( `Comment ID: ${ created . id } ` ) ;
116+ if ( created ?. url ) core . info ( `Comment URL: ${ created . url } ` ) ;
117+ return ;
118+ }
119+
120+ // Issues/PRs: determine issue number from event payload and create a new issue comment
121+ const issueNumber = context . payload ?. issue ?. number || context . payload ?. pull_request ?. number ;
122+ if ( ! issueNumber ) {
123+ core . warning ( "Unable to determine issue/PR number for append-only comment; skipping" ) ;
124+ return ;
125+ }
126+
127+ const response = await github . request ( "POST /repos/{owner}/{repo}/issues/{issue_number}/comments" , {
128+ owner : repoOwner ,
129+ repo : repoName ,
130+ issue_number : issueNumber ,
131+ body : message ,
132+ headers : {
133+ Accept : "application/vnd.github+json" ,
134+ } ,
135+ } ) ;
136+
137+ const successMessage = label ? `Successfully created append-only comment with ${ label } link` : "Successfully created append-only comment" ;
138+ core . info ( successMessage ) ;
139+ if ( response ?. data ?. id ) core . info ( `Comment ID: ${ response . data . id } ` ) ;
140+ if ( response ?. data ?. html_url ) core . info ( `Comment URL: ${ response . data . html_url } ` ) ;
141+ return ;
142+ } catch ( error ) {
143+ // Don't fail the workflow if we can't create the comment - just log a warning
144+ core . warning ( `Failed to create append-only comment: ${ getErrorMessage ( error ) } ` ) ;
145+ return ;
146+ }
147+ }
148+
149+ // Standard mode: update the existing activation comment
150+ // If no comment was created in activation, skip updating
151+ if ( ! commentId ) {
152+ core . info ( "No activation comment to update (GH_AW_COMMENT_ID not set)" ) ;
153+ return ;
154+ }
155+
156+ core . info ( `Updating activation comment ${ commentId } ` ) ;
68157 core . info ( `Updating comment in ${ repoOwner } /${ repoName } ` ) ;
69158
70159 // Check if this is a discussion comment (GraphQL node ID format)
0 commit comments