From 5f3cfa3f0d0c97c0b89230054a0c30382e2e3386 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 15 Jul 2024 08:36:23 -0600 Subject: [PATCH] feat: Update Docker configuration for Copilot debugging This commit updates the Docker configuration in the `.vscode/launch.json` file to improve the debugging experience for Copilot. It modifies the `Debug: Copilot Locally` configuration by changing the `localRoot` to `${workspaceFolder}/TestServer` and updating the `name` to `Copilot: Debug with Docker`. Additionally, it sets the `port` to `9985`, `remoteRoot` to `/usr/src/app`, and enables `restart` and `autoAttachChildProcesses` for better debugging capabilities. These changes enhance the development workflow and make it easier to debug Copilot locally with Docker. --- .vscode/launch.json | 32 +++++++------------------ Copilot/Index.ts | 1 + Copilot/Service/CopilotActions/Index.ts | 6 ++++- Copilot/Utils/CodeRepository.ts | 28 ++++++++++++++++------ Copilot/Utils/Init.ts | 5 ++++ 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a01c484128..0a6020ea8f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,18 +20,18 @@ ], "configurations": [ { - "name": "Debug: Copilot Locally", - "request": "launch", - "localRoot": "${workspaceFolder}/Copilot", - "runtimeArgs": [ - "run-script", - "start" - ], - "runtimeExecutable": "npm", + "address": "127.0.0.1", + "localRoot": "${workspaceFolder}/TestServer", + "name": "Copilot: Debug with Docker", + "port": 9985, + "remoteRoot": "/usr/src/app", + "request": "attach", "skipFiles": [ "/**" ], - "type": "node" + "type": "node", + "restart": true, + "autoAttachChildProcesses": true }, { "name": "Debug Infrastructure Agent", @@ -147,20 +147,6 @@ "restart": true, "autoAttachChildProcesses": true }, - { - "address": "127.0.0.1", - "localRoot": "${workspaceFolder}/Copilot", - "name": "Copilot: Debug with Docker", - "port": 9985, - "remoteRoot": "/usr/src/app", - "request": "attach", - "skipFiles": [ - "/**" - ], - "type": "node", - "restart": true, - "autoAttachChildProcesses": true - }, { "address": "127.0.0.1", "localRoot": "${workspaceFolder}/Workers", diff --git a/Copilot/Index.ts b/Copilot/Index.ts index 9e144fb278..6da59cfad8 100644 --- a/Copilot/Index.ts +++ b/Copilot/Index.ts @@ -14,6 +14,7 @@ Init() }) .catch(async (error: Error | HTTPErrorResponse) => { try { + logger.error(error); await CodeRepositoryUtil.discardChanges(); // change back to main branch. diff --git a/Copilot/Service/CopilotActions/Index.ts b/Copilot/Service/CopilotActions/Index.ts index d75534007c..cec4413a52 100644 --- a/Copilot/Service/CopilotActions/Index.ts +++ b/Copilot/Service/CopilotActions/Index.ts @@ -135,7 +135,11 @@ export default class CopilotActionService { // add files to stage - logger.info("Adding files to stage"); + logger.info("Adding files to stage: "); + + for (const filePath of filePaths) { + logger.info(`- ${filePath}`); + } await CodeRepositoryUtil.addFilesToGit({ filePaths: filePaths, diff --git a/Copilot/Utils/CodeRepository.ts b/Copilot/Utils/CodeRepository.ts index bd4cd763b1..a52aafcb8f 100644 --- a/Copilot/Utils/CodeRepository.ts +++ b/Copilot/Utils/CodeRepository.ts @@ -49,6 +49,10 @@ export default class CodeRepositoryUtil { public static gitHubUtil: GitHubUtil | null = null; public static folderNameOfClonedRepository: string | null = null; + public static isRepoCloned(): boolean { + return Boolean(this.folderNameOfClonedRepository); + } + public static async getOpenSetupPullRequest(): Promise { const openPullRequests: Array = await CopilotPullRequestService.getOpenPullRequestsFromDatabase(); @@ -475,21 +479,29 @@ export default class CodeRepositoryUtil { } public static async discardChanges(): Promise { - await CodeRepositoryServerUtil.discardChanges({ - repoPath: this.getLocalRepositoryPath(), - }); + if (this.isRepoCloned()) { + await CodeRepositoryServerUtil.discardChanges({ + repoPath: this.getLocalRepositoryPath(), + }); + } } public static async checkoutBranch(data: { branchName: string; }): Promise { - await CodeRepositoryServerUtil.checkoutBranch({ - repoPath: this.getLocalRepositoryPath(), - branchName: data.branchName, - }); + if (this.isRepoCloned()) { + await CodeRepositoryServerUtil.checkoutBranch({ + repoPath: this.getLocalRepositoryPath(), + branchName: data.branchName, + }); + } } public static async checkoutMainBranch(): Promise { + if (!this.isRepoCloned()) { + return; + } + const codeRepository: CopilotCodeRepository = await this.getCodeRepository(); @@ -685,6 +697,8 @@ export default class CodeRepositoryUtil { return this.codeRepositoryResult; } + logger.info("Fetching Code Repository..."); + const repositorySecretKey: string | null = GetRepositorySecretKey(); if (!repositorySecretKey) { diff --git a/Copilot/Utils/Init.ts b/Copilot/Utils/Init.ts index 700eabb209..64e1a90950 100644 --- a/Copilot/Utils/Init.ts +++ b/Copilot/Utils/Init.ts @@ -13,6 +13,7 @@ import API from "Common/Utils/API"; import HTTPErrorResponse from "Common/Types/API/HTTPErrorResponse"; import HTTPResponse from "Common/Types/API/HTTPResponse"; import { JSONObject } from "Common/Types/JSON"; +import logger from "CommonServer/Utils/Logger"; export default class InitUtil { public static async init(): Promise { @@ -40,6 +41,10 @@ export default class InitUtil { // Check if the repository type is GitHub and the GitHub token is provided if (codeRepositoryResult.serviceRepositories.length === 0) { + logger.error( + "No services found in the repository. Please add services to the repository in OneUptime Dashboard.", + ); + throw new BadDataException( "No services found in the repository. Please add services to the repository in OneUptime Dashboard.", );