Skip to content

Commit 8bee38d

Browse files
committed
fix: fix review comments
1 parent cc9b102 commit 8bee38d

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

src/handlers/summary.handler.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
22
import { generateObject } from 'ai';
33
import { Context } from 'probot';
44
import { toneDetails } from '~common/consts';
5+
import { Severity } from '~common/enums';
56
import { Handler } from '~common/interfaces';
67
import { Config, FileContent, SummaryObject } from '~common/types';
78
import { aiConfig, appConfig } from '~configs';
9+
import { SystemError } from '~errors';
810
import { summaryObjectSchema } from '~schemas';
911
import { AiService, CacheService, GitHubService, QueueService, TemplateService } from '~services';
1012
import { summaryCommentTemplate, summaryPromptTemplate, summarySystemTemplate } from '~templates';
@@ -25,7 +27,7 @@ export class SummaryHandler implements Handler<'pull_request'> {
2527
}
2628

2729
const fileContents = await this.queueService.schedule(() => GitHubService.getPullRequestFilesContent(context));
28-
const summaryObject = await this.generateFileContexts(apiKey, config, fileContents);
30+
const summaryObject = await this.generateSummaryObject(apiKey, config, fileContents);
2931
const summary = this.generateMarkdown(summaryObject.data);
3032
const existingComment = await this.findExistingComment(context);
3133

@@ -75,30 +77,34 @@ export class SummaryHandler implements Handler<'pull_request'> {
7577
.join('\n');
7678
}
7779

78-
private async generateFileContexts(
80+
private async generateSummaryObject(
7981
apiKey: string,
8082
config: Config,
8183
fileContents: FileContent[]
8284
): Promise<SummaryObject> {
83-
const filesContext = fileContents.map((file) => file.path + ': ' + file.content).join('\n');
85+
const filesContext = JSON.stringify(fileContents);
8486

85-
const result = await this.queueService.schedule(() =>
86-
generateObject<SummaryObject>({
87-
topP: aiConfig.topP.summary,
88-
model: this.aiService.getModel(aiConfig.model.summary, apiKey, true),
89-
system: TemplateService.render(summarySystemTemplate, {
90-
tone: toneDetails[config.summary.tone],
91-
language: config.language
92-
}),
93-
prompt: TemplateService.render(summaryPromptTemplate, {
94-
tone: toneDetails[config.summary.tone],
95-
language: config.language,
96-
filesContext
97-
}),
98-
schema: summaryObjectSchema
99-
})
100-
);
87+
try {
88+
const result = await this.queueService.schedule(() =>
89+
generateObject<SummaryObject>({
90+
topP: aiConfig.topP.summary,
91+
model: this.aiService.getModel(aiConfig.model.summary, apiKey, true),
92+
system: TemplateService.render(summarySystemTemplate, {
93+
tone: toneDetails[config.summary.tone],
94+
language: config.language
95+
}),
96+
prompt: TemplateService.render(summaryPromptTemplate, {
97+
tone: toneDetails[config.summary.tone],
98+
language: config.language,
99+
filesContext
100+
}),
101+
schema: summaryObjectSchema
102+
})
103+
);
101104

102-
return result.object;
105+
return result.object;
106+
} catch (error) {
107+
throw new SystemError('Failed to generate summary object', Severity.ERROR, error);
108+
}
103109
}
104110
}

src/handlers/walkthrough.handler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class WalkthroughHandler implements Handler<'pull_request'> {
2727
}
2828

2929
const fileContents = await this.queueService.schedule(() => GitHubService.getPullRequestFilesContent(context));
30-
const walkthroughObject = await this.generateWalkthrough(apiKey, config, fileContents);
30+
const walkthroughObject = await this.generateWalkthroughObject(apiKey, config, fileContents);
3131
const existingComment = await this.findExistingComment(context);
3232
const changes = this.generateMarkdown(walkthroughObject.changes);
3333

@@ -69,11 +69,13 @@ export class WalkthroughHandler implements Handler<'pull_request'> {
6969
return header + rows;
7070
}
7171

72-
private async generateWalkthrough(
72+
private async generateWalkthroughObject(
7373
apiKey: string,
7474
config: Config,
7575
fileContents: FileContent[]
7676
): Promise<WalkthroughObject> {
77+
const filesContext = JSON.stringify(fileContents);
78+
7779
try {
7880
const result = await this.queueService.schedule(() =>
7981
generateObject<WalkthroughObject>({
@@ -84,15 +86,15 @@ export class WalkthroughHandler implements Handler<'pull_request'> {
8486
language: config.language
8587
}),
8688
prompt: TemplateService.render(walkthroughPromptTemplate, {
87-
filesContext: JSON.stringify(fileContents)
89+
filesContext
8890
}),
8991
schema: walkthroughObjectSchema
9092
})
9193
);
9294

9395
return result.object;
9496
} catch (error) {
95-
throw new SystemError('Failed to generate walkthrough', Severity.ERROR, error);
97+
throw new SystemError('Failed to generate walkthrough object', Severity.ERROR, error);
9698
}
9799
}
98100
}

0 commit comments

Comments
 (0)