@@ -178,6 +178,7 @@ function getAndValidateArgs() {
178178 useCheck: (0, core_1.getBooleanInput)('use-check'),
179179 checkFailMode: (0, core_1.getInput)('check-fail-mode', { required: true }),
180180 outputBehaviour: (0, core_1.getInput)('output-behaviour'),
181+ commentBehaviour: (0, core_1.getInput)('comment-behaviour'),
181182 debug: (0, core_1.getBooleanInput)('debug')
182183 };
183184 if (![
@@ -194,6 +195,12 @@ function getAndValidateArgs() {
194195 ].includes(args.outputBehaviour)) {
195196 throw new Error(`Invalid value ${args.outputBehaviour} for input output-behaviour`);
196197 }
198+ if (![
199+ "new" /* COMMENT_BEHAVIOUR.NEW */,
200+ "edit" /* COMMENT_BEHAVIOUR.EDIT */,
201+ ].includes(args.commentBehaviour)) {
202+ throw new Error(`Invalid value ${args.commentBehaviour} for input comment-behaviour`);
203+ }
197204 return args;
198205}
199206exports.getAndValidateArgs = getAndValidateArgs;
@@ -207,11 +214,12 @@ exports.getAndValidateArgs = getAndValidateArgs;
207214"use strict";
208215
209216Object.defineProperty(exports, "__esModule", ({ value: true }));
210- exports.escapeForMarkdown = exports.getBodyComment = void 0;
217+ exports.escapeForMarkdown = exports.getBodyComment = exports.COMMENT_TITLE = void 0;
211218const BLANK_LINE = ' \n';
219+ exports.COMMENT_TITLE = '## Typescript errors check';
212220function getBodyComment({ errorsInProjectBefore, errorsInProjectAfter, errorsInModifiedFiles, newErrorsInProject }) {
213221 const delta = errorsInProjectAfter.length - errorsInProjectBefore.length;
214- let s = `## Typescript errors check \n`;
222+ let s = `${exports.COMMENT_TITLE} \n`;
215223 const areStillErrors = !!errorsInProjectAfter.length;
216224 if (areStillErrors) {
217225 if (delta < 0) {
@@ -485,9 +493,10 @@ async function run() {
485493 }
486494 if (["comment" /* OUTPUT_BEHAVIOUR.COMMENT */, "both" /* OUTPUT_BEHAVIOUR.COMMENT_AND_ANNOTATE */].includes(args.outputBehaviour)) {
487495 (0, core_1.startGroup)(`Creating comment`);
496+ const issueNumber = github_1.context.payload.pull_request.number;
488497 const commentInfo = {
489498 ...github_1.context.repo,
490- issue_number: github_1.context.payload.pull_request.number
499+ issue_number: issueNumber
491500 };
492501 const comment = {
493502 ...commentInfo,
@@ -501,7 +510,17 @@ async function run() {
501510 };
502511 (0, core_1.info)(`comment body obtained`);
503512 try {
504- await octokit.rest.issues.createComment(comment);
513+ const existingComments = await octokit.rest.issues.listComments({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, issue_number: issueNumber });
514+ const existingComment = existingComments.data.find(c => { var _a; return !!((_a = c.body) === null || _a === void 0 ? void 0 : _a.includes(getBodyComment_1.COMMENT_TITLE)); });
515+ if (args.commentBehaviour === "edit" /* COMMENT_BEHAVIOUR.EDIT */ && existingComment) {
516+ await octokit.rest.issues.updateComment({
517+ comment_id: existingComment.id,
518+ ...comment
519+ });
520+ }
521+ else {
522+ await octokit.rest.issues.createComment(comment);
523+ }
505524 }
506525 catch (e) {
507526 (0, core_1.info)(`Error creating comment: ${e.message}`);
0 commit comments