Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,13 @@ export interface ICommentManagerService {
pullRequestMessagesConfig?: IPullRequestMessages,
dryRun?: CodeReviewPipelineContext['dryRun'],
): Promise<void>;

createNoChangesComment(
organizationAndTeamData: OrganizationAndTeamData,
prNumber: number,
repository: { name: string; id: string },
platformType: string,
language: string,
dryRun?: CodeReviewPipelineContext['dryRun'],
): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,8 +28,10 @@ export class FetchChangedFilesStage extends BasePipelineStage<CodeReviewPipeline

constructor(
@Inject(PULL_REQUEST_MANAGER_SERVICE_TOKEN)
private pullRequestHandlerService: IPullRequestManagerService,
private logger: PinoLoggerService,
private readonly pullRequestHandlerService: IPullRequestManagerService,
@Inject(COMMENT_MANAGER_SERVICE_TOKEN)
private readonly commentManagerService: ICommentManagerService,
private readonly logger: PinoLoggerService,
) {
super();
}
Expand Down Expand Up @@ -64,6 +70,17 @@ export class FetchChangedFilesStage extends BasePipelineStage<CodeReviewPipeline
? AutomationMessage.NO_FILES_AFTER_IGNORE
: AutomationMessage.TOO_MANY_FILES;

if (!files?.length && context.lastExecution) {
await this.commentManagerService.createNoChangesComment(
context.organizationAndTeamData,
context.pullRequest.number,
context.repository,
context.platformType,
context.codeReviewConfig?.languageResultPrompt ?? 'en-US',
context.dryRun,
);
}

this.logger.warn({
message: `Skipping code review for PR#${context.pullRequest.number} - ${msg}`,
context: FetchChangedFilesStage.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class CommentManagerService implements ICommentManagerService {
!isCommitRun &&
updatedPR?.body &&
summaryConfig?.behaviourForExistingDescription ===
BehaviourForExistingDescription.COMPLEMENT
BehaviourForExistingDescription.COMPLEMENT
) {
promptBase += `\n\n**Additional Instructions**:
- Focus on generating new insights and relevant information based on the code changes
Expand Down Expand Up @@ -199,7 +199,7 @@ export class CommentManagerService implements ICommentManagerService {
if (
isCommitRun &&
summaryConfig?.behaviourForNewCommits ===
BehaviourForNewCommits.REPLACE
BehaviourForNewCommits.REPLACE
) {
userPrompt = `
This is the updated pull request summary:
Expand Down Expand Up @@ -348,7 +348,7 @@ export class CommentManagerService implements ICommentManagerService {
if (
updatedPR?.body &&
summaryConfig?.behaviourForExistingDescription ===
BehaviourForExistingDescription.CONCATENATE
BehaviourForExistingDescription.CONCATENATE
) {
// Log for debugging
this.logger.log({
Expand Down Expand Up @@ -1287,7 +1287,7 @@ ${reviewOptions}
(s) =>
s.clusteringInformation?.type === ClusteringType.RELATED &&
s.clusteringInformation?.parentSuggestionId ===
suggestion.id,
suggestion.id,
);

const occurrences = [
Expand Down Expand Up @@ -1318,11 +1318,11 @@ ${reviewOptions}
): string {
return platformType === PlatformType.BITBUCKET
? markdown
.replace(
/(<\/?details>)|(<\/?summary>)|(<!-- kody-codereview -->(\n|\\n)?&#8203;)/g,
'',
)
.trim()
.replace(
/(<\/?details>)|(<\/?summary>)|(<!-- kody-codereview -->(\n|\\n)?&#8203;)/g,
'',
)
.trim()
: markdown;
}

Expand Down Expand Up @@ -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<void> {
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,
},
});
}
}
}
5 changes: 3 additions & 2 deletions src/shared/utils/translations/dictionaries/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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) 🤖)",
Expand Down Expand Up @@ -102,4 +103,4 @@
"manualTitle": "Manual Review",
"manualDesc": "Kody reviews the first push automatically, then only when you request with @kody start-review."
}
}
}
1 change: 1 addition & 0 deletions src/shared/utils/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ReviewComment {
interface PullRequestFinishSummaryMarkdown {
withComments: string;
withoutComments: string;
noChangesDetected: string;
}

interface PullRequestSummaryMarkdown {
Expand Down