Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/functions/confluence.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import axios, { type AxiosInstance } from 'axios';
import { getSecretEnvVar } from 'src/config/secretConfig';
import { llms } from '#agent/agentContextLocalStorage';
import { agentStorageDir } from '#app/appDirs';
import { getSecretEnvVar } from '#config/secretConfig';
import { func, funcClass } from '#functionSchema/functionDecorators';
import { logger } from '#o11y/logger';
import { functionConfig } from '#user/userContext';
Expand Down
2 changes: 1 addition & 1 deletion src/functions/jira.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import axios, { type AxiosInstance } from 'axios';
import { getSecretEnvVar } from 'src/config/secretConfig';
import { llms } from '#agent/agentContextLocalStorage';
import { agentStorageDir } from '#app/appDirs';
import { getSecretEnvVar } from '#config/secretConfig';
import { func, funcClass } from '#functionSchema/functionDecorators';
import { getJiraIssueType } from '#functions/jiraIssueType';
import { logger } from '#o11y/logger';
Expand Down
19 changes: 17 additions & 2 deletions src/functions/scm/gitlabCodeReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class GitLabCodeReview {
}

@span()
async reviewMergeRequest(gitlabProjectId: string | number, mergeRequestIId: number): Promise<void> {
async createMergeRequestReviewTasks(gitlabProjectId: string | number, mergeRequestIId: number): Promise<CodeReviewTask[]> {
const mergeRequest: ExpandedMergeRequestSchema = await this.api().MergeRequests.show(gitlabProjectId, mergeRequestIId);
const diffs: MergeRequestDiffSchema[] = await this.getDiffs(gitlabProjectId, mergeRequestIId);
const codeReviewService = appContext().codeReviewService;
Expand All @@ -91,7 +91,9 @@ export class GitLabCodeReview {
// Load the hashes of the diffs we've already reviewed
const reviewCache: CodeReviewFingerprintCache = await codeReviewService.getMergeRequestReviewCache(gitlabProjectId, mergeRequestIId);

logger.info(`Reviewing MR "${mergeRequest.title}" in project "${projectPath}" (${mergeRequest.web_url}) with ${codeReviewConfigs.length} configs`);
logger.info(
`Checking for review tasks for MR "${mergeRequest.title}" in project "${projectPath}" (${mergeRequest.web_url}) with ${codeReviewConfigs.length} configs`,
);

const codeReviewTasks: CodeReviewTask[] = [];

Expand All @@ -114,6 +116,19 @@ export class GitLabCodeReview {
}
}
logger.info(`Found ${codeReviewTasks.length} review tasks needing LLM analysis.`);
return codeReviewTasks;
}

@span()
async processMergeRequestCodeReviewTasks(gitlabProjectId: string | number, mergeRequestIId: number, codeReviewTasks: CodeReviewTask[]): Promise<void> {
const mergeRequest: ExpandedMergeRequestSchema = await this.api().MergeRequests.show(gitlabProjectId, mergeRequestIId);
const codeReviewService = appContext().codeReviewService;
const project = await this.gitlabSCM().getProject(gitlabProjectId);
const projectPath = project.fullPath;
// Load the hashes of the diffs we've already reviewed
const reviewCache: CodeReviewFingerprintCache = await codeReviewService.getMergeRequestReviewCache(gitlabProjectId, mergeRequestIId);

logger.info(`Reviewing MR "${mergeRequest.title}" in project "${projectPath}" (${mergeRequest.web_url}) with ${codeReviewTasks.length} review tasks`);
if (!codeReviewTasks.length) return;

// Perform LLM Reviews
Expand Down
2 changes: 1 addition & 1 deletion src/modules/slack/slackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSecretEnvVar } from 'src/config/secretConfig';
import { getSecretEnvVar } from '#config/secretConfig';
import { logger } from '#o11y/logger';

export interface SlackConfig {
Expand Down
7 changes: 3 additions & 4 deletions src/routes/codeTask/createCodeTaskRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendBadRequest, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import type { CreateCodeTaskData } from '#shared/codeTask/codeTask.model';
import { currentUser } from '#user/userContext';
Expand All @@ -27,9 +28,7 @@ export async function createCodeTaskRoute(fastify: AppFastifyInstance): Promise<

if (!effectiveRepositoryPath && repositoryName && (repositorySource === 'github' || repositorySource === 'gitlab')) {
effectiveRepositoryPath = repositoryName;
fastify.log.info(
`Code task creation: repositoryFullPath was not provided for source '${repositorySource}', derived from repositoryName '${repositoryName}'.`,
);
logger.info(`Code task creation: repositoryFullPath was not provided for source '${repositorySource}', derived from repositoryName '${repositoryName}'.`);
}

if (!effectiveRepositoryPath) {
Expand All @@ -54,7 +53,7 @@ export async function createCodeTaskRoute(fastify: AppFastifyInstance): Promise<
const newCodeTask = await codeTaskService.createCodeTask(userId, createData);
return reply.sendJSON(newCodeTask);
} catch (error: any) {
fastify.log.error(error, `Error creating Code task for user ${userId}`);
logger.error(error, `Error creating Code task for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to create Code task');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/createPresetRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -15,7 +16,7 @@ export async function createPresetRoute(fastify: AppFastifyInstance): Promise<vo
const newPreset = await codeTaskService.saveCodeTaskPreset(userId, name, config);
return reply.sendJSON(newPreset);
} catch (error: any) {
fastify.log.error(error, `Error creating Code task preset for user ${userId}`);
logger.error(error, `Error creating Code task preset for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to create Code task preset');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/deleteCodeTaskRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -18,7 +19,7 @@ export async function deleteCodeTaskRoute(fastify: AppFastifyInstance): Promise<
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task with ID ${codeTaskId} not found for deletion`);
}
fastify.log.error(error, `Error deleting Code task ${codeTaskId} for user ${userId}`);
logger.error(error, `Error deleting Code task ${codeTaskId} for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to delete Code task');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/deletePresetRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -19,7 +20,7 @@ export async function deletePresetRoute(fastify: AppFastifyInstance): Promise<vo
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task preset with ID ${presetId} not found for deletion`);
}
fastify.log.error(error, `Error deleting Code task preset ${presetId} for user ${userId}`);
logger.error(error, `Error deleting Code task preset ${presetId} for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to delete Code task preset');
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/routes/codeTask/executeDesignRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendErrorResponse, sendNotFound, sendServerError } from '#fastify/responses';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -15,7 +16,7 @@ export async function executeDesignRoute(fastify: AppFastifyInstance): Promise<v
await codeTaskService.executeDesign(userId, codeTaskId);
return reply.sendJSON({ message: 'Design execution accepted and processing started.' });
} catch (error: any) {
fastify.log.error(error, `Error triggering design execution for codeTask ${codeTaskId}, user ${userId}`);
logger.error(error, `Error triggering design execution for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task with ID ${codeTaskId} not found`);
}
Expand Down
7 changes: 4 additions & 3 deletions src/routes/codeTask/generateDesignRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendErrorResponse, sendNotFound, sendServerError } from '#fastify/responses';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -20,7 +21,7 @@ export async function generateDesignRoute(fastify: AppFastifyInstance): Promise<
// The service method or API definition should be reconciled.
const { instructions } = request.body; // As per CODE_TASK_API.generateDesign schema
if (instructions) {
fastify.log.warn(
logger.warn(
`Received 'instructions' for generateDesign API, but the current service method 'generateDetailedDesign' expects 'variations'. Instructions will be ignored. Service or API definition may need an update. Instructions: ${instructions}`,
);
}
Expand All @@ -31,7 +32,7 @@ export async function generateDesignRoute(fastify: AppFastifyInstance): Promise<
await codeTaskService.generateDetailedDesign(userId, codeTaskId);
return reply.sendJSON({ message: 'Design generation accepted and processing started.' });
} catch (error: any) {
fastify.log.error(error, `Error triggering design generation for codeTask ${codeTaskId}, user ${userId}`);
logger.error(error, `Error triggering design generation for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task with ID ${codeTaskId} not found`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/getCodeTaskByIdRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -17,7 +18,7 @@ export async function getCodeTaskByIdRoute(fastify: AppFastifyInstance): Promise

return reply.sendJSON(codeTask);
} catch (error: any) {
fastify.log.error(error, `Error getting Code task ${codeTaskId} for user ${userId}`);
logger.error(error, `Error getting Code task ${codeTaskId} for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to retrieve Code task');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/getFileContentRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -17,7 +18,7 @@ export async function getFileContentRoute(fastify: AppFastifyInstance): Promise<
const content = await codeTaskService.getFileContent(userId, codeTaskId, filePath);
return reply.sendJSON({ content });
} catch (error: any) {
fastify.log.error(error, `Error getting file content for codeTask ${codeTaskId} (path: ${filePath}), user ${userId}`);
logger.error(error, `Error getting file content for codeTask ${codeTaskId} (path: ${filePath}), user ${userId}`);
if (error.message?.includes('not found') || error.name === 'ENOENT' /* For fs errors */) {
return sendNotFound(reply, `File or CodeTask not found: ${filePath}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/getFileSystemTreeRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -22,7 +23,7 @@ export async function getFileSystemTreeRoute(fastify: AppFastifyInstance): Promi
}
return reply.sendJSON(tree);
} catch (error: any) {
fastify.log.error(error, `Error getting file system tree for codeTask ${codeTaskId} (path: ${path || '/'}), user ${userId}`);
logger.error(error, `Error getting file system tree for codeTask ${codeTaskId} (path: ${path || '/'}), user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task or path not found: ${error.message}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/getRepoBranchesRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendBadRequest, sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -17,7 +18,7 @@ export async function getRepoBranchesRoute(fastify: AppFastifyInstance): Promise
const branches = await codeTaskService.getBranchList(userId, codeTaskId, providerType, projectId);
return reply.sendJSON(branches);
} catch (error: any) {
fastify.log.error(error, `Error getting branches for codeTask ${codeTaskId}, repo ${projectId} (provider: ${providerType}), user ${userId}`);
logger.error(error, `Error getting branches for codeTask ${codeTaskId}, repo ${projectId} (provider: ${providerType}), user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task or repository not found: ${error.message}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/listCodeTasksRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -14,7 +15,7 @@ export async function listCodeTasksRoute(fastify: AppFastifyInstance): Promise<v
const codeTasks = await codeTaskService.listCodeTasks(userId);
return reply.sendJSON(codeTasks);
} catch (error: any) {
fastify.log.error(error, `Error listing Code tasks for user ${userId}`);
logger.error(error, `Error listing Code tasks for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to list Code tasks');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/listPresetsRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -14,7 +15,7 @@ export async function listPresetsRoute(fastify: AppFastifyInstance): Promise<voi
const presets = await codeTaskService.listCodeTaskPresets(userId);
return reply.sendJSON(presets);
} catch (error: any) {
fastify.log.error(error, `Error listing Code task presets for user ${userId}`);
logger.error(error, `Error listing Code task presets for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to list Code task presets');
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/routes/codeTask/resetSelectionRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendErrorResponse, sendNotFound, sendServerError } from '#fastify/responses';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -15,7 +16,7 @@ export async function resetSelectionRoute(fastify: AppFastifyInstance): Promise<
await codeTaskService.resetFileSelection(userId, codeTaskId);
return reply.sendJSON({ message: 'File selection reset accepted.' });
} catch (error: any) {
fastify.log.error(error, `Error resetting file selection for codeTask ${codeTaskId}, user ${userId}`);
logger.error(error, `Error resetting file selection for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) {
return sendNotFound(reply, error.message);
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/codeTask/updateCodeRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendErrorResponse, sendNotFound, sendServerError } from '#fastify/responses';
import { sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import { currentUser } from '#user/userContext';
import { registerApiRoute } from '../routeUtils';
Expand All @@ -17,7 +18,7 @@ export async function updateCodeRoute(fastify: AppFastifyInstance): Promise<void
await codeTaskService.updateCodeWithComments(userId, codeTaskId, data);
return reply.sendJSON({});
} catch (error: any) {
fastify.log.error(error, `Error triggering code update for codeTask ${codeTaskId}, user ${userId}`);
logger.error(error, `Error triggering code update for codeTask ${codeTaskId}, user ${userId}`);
if (error.message?.includes('not found')) return sendNotFound(reply, `Code task with ID ${codeTaskId} not found`);
return sendServerError(reply, error.message || 'Failed to trigger code update');
}
Expand Down
3 changes: 2 additions & 1 deletion src/routes/codeTask/updateCodeTaskRoute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppFastifyInstance } from '#app/applicationTypes';
import { CodeTaskServiceImpl } from '#codeTask/codeTaskServiceImpl';
import { sendBadRequest, sendNotFound, sendServerError } from '#fastify/responses';
import { logger } from '#o11y/logger';
import { CODE_TASK_API } from '#shared/codeTask/codeTask.api';
import type { UpdateCodeTaskData } from '#shared/codeTask/codeTask.model';
import { currentUser } from '#user/userContext';
Expand All @@ -26,7 +27,7 @@ export async function updateCodeTaskRoute(fastify: AppFastifyInstance): Promise<
if (error.message?.includes('not found')) {
return sendNotFound(reply, `Code task with ID ${codeTaskId} not found for update`);
}
fastify.log.error(error, `Error updating Code task ${codeTaskId} for user ${userId}`);
logger.error(error, `Error updating Code task ${codeTaskId} for user ${userId}`);
return sendServerError(reply, error.message || 'Failed to update Code task');
}
});
Expand Down
Loading
Loading