From 6eef29e4a3d6c42a3c2c4b042d72b817d5314fb5 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 8 Jul 2024 14:05:09 +0100 Subject: [PATCH] refactor: Update Copilot configuration for local development --- .vscode/launch.json | 2 +- .../Utils/CodeRepository/CodeRepository.ts | 26 +++++++++++++++++++ Copilot/Config.ts | 2 +- Copilot/Dockerfile.tpl | 10 +++---- Copilot/Init.ts | 5 +++- Copilot/Utils/CodeRepository.ts | 9 +++++++ 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8d0b35b58d..a01c484128 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -149,7 +149,7 @@ }, { "address": "127.0.0.1", - "localRoot": "${workspaceFolder}/Realtime", + "localRoot": "${workspaceFolder}/Copilot", "name": "Copilot: Debug with Docker", "port": 9985, "remoteRoot": "/usr/src/app", diff --git a/CommonServer/Utils/CodeRepository/CodeRepository.ts b/CommonServer/Utils/CodeRepository/CodeRepository.ts index 91f84f8670..4782bbc23b 100644 --- a/CommonServer/Utils/CodeRepository/CodeRepository.ts +++ b/CommonServer/Utils/CodeRepository/CodeRepository.ts @@ -235,6 +235,32 @@ export default class CodeRepositoryUtil { return hash; } + + public static async listFilesInDirectory(data: { + directoryPath: string; + repoPath: string; + }): Promise> { + if (!data.directoryPath.startsWith("/")) { + data.directoryPath = "/" + data.directoryPath; + } + + if (!data.repoPath.startsWith("/")) { + data.repoPath = "/" + data.repoPath; + } + + const { directoryPath, repoPath } = data; + + let totalPath: string = `${repoPath}/${directoryPath}`; + + totalPath = LocalFile.sanitizeFilePath(totalPath); // clean up the path + + const output: string = await Execute.executeCommand(`ls ${totalPath}`); + + const fileNames: Array = output.split("\n"); + + return fileNames; + } + public static async getFilesInDirectory(data: { directoryPath: string; repoPath: string; diff --git a/Copilot/Config.ts b/Copilot/Config.ts index c724603f3c..7d38d58295 100644 --- a/Copilot/Config.ts +++ b/Copilot/Config.ts @@ -18,7 +18,7 @@ export const GetRepositorySecretKey: GetStringOrNullFunction = (): }; export const GetLocalRepositoryPath: GetStringFunction = (): string => { - return process.env["ONEUPTIME_LOCAL_REPOSITORY_PATH"] || "/repository"; + return "/repository"; }; export const GetGitHubToken: GetStringOrNullFunction = (): string | null => { diff --git a/Copilot/Dockerfile.tpl b/Copilot/Dockerfile.tpl index 0ddd04f676..25ce1e7962 100644 --- a/Copilot/Dockerfile.tpl +++ b/Copilot/Dockerfile.tpl @@ -3,7 +3,7 @@ # # Pull base image nodejs image. -FROM node:21.7.3-alpine3.18 +FROM node:22.3.0 RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global ARG GIT_SHA @@ -18,17 +18,16 @@ RUN if [ -z "$APP_VERSION" ]; then export APP_VERSION=1.0.0; fi # Install bash. -RUN apk add bash && apk add curl - +RUN apt-get install bash -y && apt-get install curl -y # Install python -RUN apk update && apk add --no-cache --virtual .gyp python3 make g++ +RUN apt-get update && apt-get install -y .gyp python3 make g++ #Use bash shell by default SHELL ["/bin/bash", "-c"] -RUN mkdir /usr/src +RUN mkdir -p /usr/src WORKDIR /usr/src/Common COPY ./Common/package*.json /usr/src/Common/ @@ -46,7 +45,6 @@ RUN npm install COPY ./Model /usr/src/Model - WORKDIR /usr/src/CommonServer COPY ./CommonServer/package*.json /usr/src/CommonServer/ # Set version in ./CommonServer/package.json to the APP_VERSION diff --git a/Copilot/Init.ts b/Copilot/Init.ts index bfac6913b5..dc0800d465 100644 --- a/Copilot/Init.ts +++ b/Copilot/Init.ts @@ -24,7 +24,10 @@ import CopilotActionProcessingException from "./Exceptions/CopilotActionProcessi let currentFixCount: number = 1; const init: PromiseVoidFunction = async (): Promise => { - const codeRepositoryResult: CodeRepositoryResult = await InitUtil.init(); + + debugger; + + const codeRepositoryResult: CodeRepositoryResult = await InitUtil.init() for (const serviceToImrove of codeRepositoryResult.servicesToImprove) { checkIfCurrentFixCountIsLessThanFixNumberOfCodeEventsInEachRun(); diff --git a/Copilot/Utils/CodeRepository.ts b/Copilot/Utils/CodeRepository.ts index 800e0b79cc..a9111ea629 100644 --- a/Copilot/Utils/CodeRepository.ts +++ b/Copilot/Utils/CodeRepository.ts @@ -59,6 +59,15 @@ export default class CodeRepositoryUtil { return pullRequests; } + public static async listFilesInDirectory(data: { + directoryPath: string; + }): Promise> { + return await CodeRepositoryServerUtil.listFilesInDirectory({ + repoPath: GetLocalRepositoryPath(), + directoryPath: data.directoryPath, + }); + } + public static getGitHubUtil(): GitHubUtil { if (!this.gitHubUtil) { const gitHubToken: string | null = GetGitHubToken();