diff --git a/CommonServer/Utils/CodeRepository/CodeRepository.ts b/CommonServer/Utils/CodeRepository/CodeRepository.ts index 4c21a1272c..eaa1dd577b 100644 --- a/CommonServer/Utils/CodeRepository/CodeRepository.ts +++ b/CommonServer/Utils/CodeRepository/CodeRepository.ts @@ -2,18 +2,29 @@ import Execute from '../Execute'; import CodeRepositoryFile from './CodeRepositoryFile'; export default class CodeRepositoryUtil { - public static async getGitCommitHashForFile( + public static async getGitCommitHashForFile(data: { + repoPath: string, filePath: string + } ): Promise { + + const { repoPath, filePath } = data; + return await Execute.executeCommand( - `git log -1 --pretty=format:"%H" ${filePath}` + `cd ${repoPath} && git log -1 --pretty=format:"%H" "${filePath}"` ); } - public static async getFilesInDirectory(directoryPath: string): Promise<{ + public static async getFilesInDirectory(data: { + directoryPath: string, + repoPath: string + }): Promise<{ files: Array; subDirectories: Array; }> { + + const { directoryPath, repoPath } = data; + const files: Array = []; const output: string = await Execute.executeCommand( `ls ${directoryPath}` @@ -40,9 +51,10 @@ export default class CodeRepositoryUtil { } const filePath: string = `${directoryPath}/${fileName}`; - const gitCommitHash: string = await this.getGitCommitHashForFile( - filePath - ); + const gitCommitHash: string = await this.getGitCommitHashForFile({ + filePath, + repoPath + }); const fileExtension: string = fileName.split('.').pop() || ''; files.push({ filePath, @@ -58,18 +70,25 @@ export default class CodeRepositoryUtil { }; } - public static async getFilesInDirectoryRecursive( + public static async getFilesInDirectoryRecursive(data: { + repoPath: string, directoryPath: string - ): Promise> { + }): Promise> { const files: Array = []; const { files: filesInDirectory, subDirectories } = - await this.getFilesInDirectory(directoryPath); + await this.getFilesInDirectory({ + directoryPath: data.directoryPath, + repoPath: data.repoPath + }); files.push(...filesInDirectory); for (const subDirectory of subDirectories) { files.push( - ...(await this.getFilesInDirectoryRecursive(subDirectory)) + ...(await this.getFilesInDirectoryRecursive({ + repoPath: data.repoPath, + directoryPath: subDirectory + })) ); } diff --git a/Copilot/.env.example b/Copilot/.env.example index e0ab561977..f02f92d0fc 100644 --- a/Copilot/.env.example +++ b/Copilot/.env.example @@ -1,3 +1,3 @@ ONEUPTIME_URL=https://oneuptime.com ONEUPTIME_REPOSITORY_SECRET_KEY=your-repository-secret-key -LOCAL_REPOSITORY_PATH=/repository +ONEUPTIME_LOCAL_REPOSITORY_PATH=/repository diff --git a/Copilot/Index.ts b/Copilot/Index.ts index 01b8f733a6..bfbd12af13 100644 --- a/Copilot/Index.ts +++ b/Copilot/Index.ts @@ -3,15 +3,26 @@ import { PromiseVoidFunction } from 'Common/Types/FunctionTypes'; import logger from 'CommonServer/Utils/Logger'; import CodeRepository from 'Model/Models/CodeRepository'; import dotenv from 'dotenv'; +import CodeRepositoryFile from 'CommonServer/Utils/CodeRepository/CodeRepositoryFile' +import CodeRepositoryCommonServerUtil from 'CommonServer/Utils/CodeRepository/CodeRepository'; +import { GetLocalRepositoryPath } from './Config'; dotenv.config(); -logger.info('OneUptime Copilot is starting...'); +logger.info('OneUptime Copilot is started...'); const init: PromiseVoidFunction = async (): Promise => { const codeRepository: CodeRepository = await CodeRepositoryUtil.getCodeRepository(); + logger.info(`Code Repository found: ${codeRepository.name}`); + + const allFiles: Array = await CodeRepositoryCommonServerUtil.getFilesInDirectoryRecursive({ + repoPath: GetLocalRepositoryPath(), + directoryPath: GetLocalRepositoryPath() + }); + + logger.info(`All files found: ${allFiles.length}`); }; init()