11name : Add Comment
2- description : " Posts a comment on the pull-request"
2+ description : " Posts a comment on the pull-request or updates an existing one "
33
44inputs :
55 commentMessage :
66 description : " Message that will be put as a comment"
77 required : true
8+ commentId :
9+ description : " Optional comment ID to update instead of creating new one"
10+ required : false
11+
12+ outputs :
13+ commentId :
14+ description : " The ID of the created or updated comment"
15+ value : ${{ steps.comment-and-check.outputs.comment-id }}
816
917runs :
1018 using : composite
@@ -14,11 +22,13 @@ runs:
1422 uses : actions/github-script@v7
1523 env :
1624 MESSAGE : ${{ inputs.commentMessage }}
25+ COMMENT_ID : ${{ inputs.commentId }}
1726 with :
1827 script : |
1928 const {owner, repo} = context.repo;
2029
2130 const msg = process.env.MESSAGE
31+ const commentId = process.env.COMMENT_ID
2232 let sha = undefined
2333 let prNumber = undefined;
2434
@@ -38,14 +48,29 @@ runs:
3848 } else {
3949 sha ||= context.sha;
4050 }
41-
42- core.info(`Going to put a comment to PR “ ${prNumber}” (“ ${sha}” ) - ” ${msg}” `);
51+
52+ core.info(`Going to put a comment to PR " ${prNumber}" (" ${sha}" ) - " ${msg}" `);
4353
4454 //------------------------------------------------------------------
4555 // 2) Add / update PR comment
4656 //------------------------------------------------------------------
4757 if (prNumber) {
48- await github.rest.issues.createComment({
49- owner, repo, issue_number: prNumber, body: msg
50- });
58+ // Update existing comment if commentId provided
59+ if (commentId) {
60+ core.info(`Updating existing comment ${commentId}`);
61+ await github.rest.issues.updateComment({
62+ owner,
63+ repo,
64+ comment_id: commentId,
65+ body: msg
66+ });
67+ core.setOutput('comment-id', commentId);
68+ } else {
69+ // Create new comment
70+ core.info(`Creating new comment`);
71+ const comment = await github.rest.issues.createComment({
72+ owner, repo, issue_number: prNumber, body: msg
73+ });
74+ core.setOutput('comment-id', comment.data.id);
75+ }
5176 }
0 commit comments