diff --git a/src/core/domain/codeBase/contracts/CommentManagerService.contract.ts b/src/core/domain/codeBase/contracts/CommentManagerService.contract.ts index b512deaf3..c90df6549 100644 --- a/src/core/domain/codeBase/contracts/CommentManagerService.contract.ts +++ b/src/core/domain/codeBase/contracts/CommentManagerService.contract.ts @@ -144,4 +144,13 @@ export interface ICommentManagerService { pullRequestMessagesConfig?: IPullRequestMessages, dryRun?: CodeReviewPipelineContext['dryRun'], ): Promise; + + createNoChangesComment( + organizationAndTeamData: OrganizationAndTeamData, + prNumber: number, + repository: { name: string; id: string }, + platformType: string, + language: string, + dryRun?: CodeReviewPipelineContext['dryRun'], + ): Promise; } diff --git a/src/core/infrastructure/adapters/services/codeBase/codeReviewPipeline/stages/fetch-changed-files.stage.ts b/src/core/infrastructure/adapters/services/codeBase/codeReviewPipeline/stages/fetch-changed-files.stage.ts index bd3b62731..d9dc2cc4f 100644 --- a/src/core/infrastructure/adapters/services/codeBase/codeReviewPipeline/stages/fetch-changed-files.stage.ts +++ b/src/core/infrastructure/adapters/services/codeBase/codeReviewPipeline/stages/fetch-changed-files.stage.ts @@ -4,6 +4,10 @@ import { IPullRequestManagerService, PULL_REQUEST_MANAGER_SERVICE_TOKEN, } from '@/core/domain/codeBase/contracts/PullRequestManagerService.contract'; +import { + ICommentManagerService, + COMMENT_MANAGER_SERVICE_TOKEN, +} from '@/core/domain/codeBase/contracts/CommentManagerService.contract'; import { CodeReviewPipelineContext } from '../context/code-review-pipeline.context'; import { PinoLoggerService } from '../../../logger/pino.service'; import { @@ -24,8 +28,10 @@ export class FetchChangedFilesStage extends BasePipelineStage s.clusteringInformation?.type === ClusteringType.RELATED && s.clusteringInformation?.parentSuggestionId === - suggestion.id, + suggestion.id, ); const occurrences = [ @@ -1318,11 +1318,11 @@ ${reviewOptions} ): string { return platformType === PlatformType.BITBUCKET ? markdown - .replace( - /(<\/?details>)|(<\/?summary>)|((\n|\\n)?​)/g, - '', - ) - .trim() + .replace( + /(<\/?details>)|(<\/?summary>)|((\n|\\n)?​)/g, + '', + ) + .trim() : markdown; } @@ -1706,4 +1706,56 @@ ${reviewOptions} platformType, }; } + + async createNoChangesComment( + organizationAndTeamData: OrganizationAndTeamData, + prNumber: number, + repository: { name: string; id: string }, + platformType: string, + language: string, + dryRun?: CodeReviewPipelineContext['dryRun'], + ): Promise { + try { + const noChangesMessage = getTranslationsForLanguageByCategory( + language as LanguageValue, + TranslationsCategory.PullRequestFinishSummaryMarkdown, + ).noChangesDetected; + + const commentBody = this.sanitizeBitbucketMarkdown( + noChangesMessage, + platformType as PlatformType, + ); + + await this.codeManagementService.createIssueComment( + { + organizationAndTeamData, + prNumber, + repository: { + name: repository.name, + id: repository.id, + }, + body: commentBody, + dryRun, + }, + dryRun?.enabled ? PlatformType.INTERNAL : undefined, + ); + + this.logger.log({ + message: `Created no changes comment for PR#${prNumber}`, + context: CommentManagerService.name, + metadata: { prNumber }, + }); + } catch (error) { + this.logger.error({ + message: `Failed to create no changes comment for PR#${prNumber}`, + context: CommentManagerService.name, + error: error.message, + metadata: { + organizationAndTeamData, + prNumber, + repository, + }, + }); + } + } } diff --git a/src/shared/utils/translations/dictionaries/en-US.json b/src/shared/utils/translations/dictionaries/en-US.json index 3f80169c0..7bb0aeef9 100644 --- a/src/shared/utils/translations/dictionaries/en-US.json +++ b/src/shared/utils/translations/dictionaries/en-US.json @@ -5,7 +5,8 @@ }, "pullRequestFinishSummaryMarkdown": { "withComments": "## Code Review Completed! 🔥\n\nThe code review was successfully completed based on your current configurations.\n\n", - "withoutComments": "# Kody Review Complete\n**Great news!** 🎉\nNo issues were found that match your current review configurations.\n\nKeep up the excellent work! 🚀" + "withoutComments": "# Kody Review Complete\n**Great news!** 🎉\nNo issues were found that match your current review configurations.\n\nKeep up the excellent work! 🚀", + "noChangesDetected": "# Kody Review Complete ✅\n**Info:** This PR has already been reviewed with no new changes detected.\n\nIf you've made new changes, ensure they're committed and pushed." }, "pullRequestSummaryMarkdown": { "title": "PR Summary (Comment created by [Kody](https://kodus.io) 🤖)", @@ -102,4 +103,4 @@ "manualTitle": "Manual Review", "manualDesc": "Kody reviews the first push automatically, then only when you request with @kody start-review." } -} +} \ No newline at end of file diff --git a/src/shared/utils/translations/translations.ts b/src/shared/utils/translations/translations.ts index 9d780ee55..89579930d 100644 --- a/src/shared/utils/translations/translations.ts +++ b/src/shared/utils/translations/translations.ts @@ -47,6 +47,7 @@ interface ReviewComment { interface PullRequestFinishSummaryMarkdown { withComments: string; withoutComments: string; + noChangesDetected: string; } interface PullRequestSummaryMarkdown {