refactor: Add LOG_LEVEL=DEBUG environment variable to docker-compose.copilot.yml

This commit adds the LOG_LEVEL=DEBUG environment variable to the docker-compose.copilot.yml file. Setting the log level to DEBUG will enable more detailed logging for the Copilot service. This change is made to improve debugging and troubleshooting capabilities during development and testing.
This commit is contained in:
Simon Larsen
2024-07-08 16:01:51 +01:00
parent 12dab7bdda
commit 448326ee88
5 changed files with 106 additions and 16 deletions

View File

@@ -7,10 +7,12 @@ import ServiceLanguageUtil from "Common/Utils/ServiceLanguage";
export default class CodeRepositoryUtil {
// returns the folder name of the cloned repository
public static async cloneRepository(data: {
repoPath: string;
repoUrl: string;
}): Promise<void> {
}): Promise<string> {
const command: string = `cd ${data.repoPath} && git clone ${data.repoUrl}`;
logger.debug("Executing command: " + command);
@@ -18,6 +20,15 @@ export default class CodeRepositoryUtil {
const stdout: string = await Execute.executeCommand(command);
logger.debug(stdout);
// get the folder name of the repository from the disk.
const getFolderNameCommand: string = `cd ${data.repoPath} && ls`;
const folderName: string = await Execute.executeCommand(getFolderNameCommand);
return folderName;
}
public static async pullChanges(data: { repoPath: string }): Promise<void> {

View File

@@ -12,6 +12,52 @@ export default class LocalFile {
return fileExtention[fileExtention.length - 1]?.toLowerCase() || "";
}
public static async doesDirectoryExist(path: string): Promise<boolean> {
return new Promise(
(resolve: (exists: boolean) => void, reject: PromiseRejectErrorFunction) => {
fs.stat(path, (err: Error | null, stats: fs.Stats) => {
if (err) {
if ((err as any).code === "ENOENT") {
return resolve(false);
}
return reject(err);
}
if (stats.isDirectory()) {
return resolve(true);
}
return resolve(false);
});
},
);
}
public static async deleteAllDataInDirectory(path: string): Promise<void> {
if(await this.doesDirectoryExist(path) === false) {
return;
}
return new Promise(
(resolve: VoidFunction, reject: PromiseRejectErrorFunction) => {
fs.rm(path, { recursive: true }, (err: Error | null) => {
if (err) {
return reject(err);
}
// now crate the directory again
fs.mkdir(path, { recursive: true }, (err: Error | null) => {
if (err) {
return reject(err);
}
resolve();
});
});
},
);
}
public static async makeDirectory(path: string): Promise<void> {
return new Promise(
(resolve: VoidFunction, reject: PromiseRejectErrorFunction) => {

View File

@@ -27,11 +27,19 @@ const init: PromiseVoidFunction = async (): Promise<void> => {
const codeRepositoryResult: CodeRepositoryResult = await InitUtil.init();
logger.info(
`Cloning the repository ${codeRepositoryResult.codeRepository.name} to a temporary directory.`,
);
// now clone this repository to a temporary directory - /repository
await CodeRepositoryUtil.cloneRepository({
codeRepository: codeRepositoryResult.codeRepository,
});
logger.info(
`Repository ${codeRepositoryResult.codeRepository.name} cloned successfully.`,
);
for (const serviceToImrove of codeRepositoryResult.servicesToImprove) {
checkIfCurrentFixCountIsLessThanFixNumberOfCodeEventsInEachRun();

View File

@@ -16,6 +16,7 @@ import { JSONArray, JSONObject } from "Common/Types/JSON";
import API from "Common/Utils/API";
import CodeRepositoryServerUtil from "CommonServer/Utils/CodeRepository/CodeRepository";
import GitHubUtil from "CommonServer/Utils/CodeRepository/GitHub/GitHub";
import LocalFile from "CommonServer/Utils/LocalFile";
import logger from "CommonServer/Utils/Logger";
import CodeRepositoryModel from "Model/Models/CodeRepository";
import ServiceRepository from "Model/Models/ServiceRepository";
@@ -35,10 +36,30 @@ export interface ServiceToImproveResult {
export default class CodeRepositoryUtil {
public static codeRepositoryResult: CodeRepositoryResult | null = null;
public static gitHubUtil: GitHubUtil | null = null;
public static folderNameOfClonedRepository: string | null = null;
public static getLocalRepositoryPath(): string {
if(this.folderNameOfClonedRepository){
return LocalFile.sanitizeFilePath(GetLocalRepositoryPath() + '/' + this.folderNameOfClonedRepository);
}
return GetLocalRepositoryPath();
}
// returns the folder name of the cloned repository.
public static async cloneRepository(data: {
codeRepository: CodeRepositoryModel;
}): Promise<void> {
// make sure this.getLocalRepositoryPath() is empty.
const repoLocalPath = this.getLocalRepositoryPath();
await LocalFile.deleteAllDataInDirectory(repoLocalPath);
await LocalFile.makeDirectory(repoLocalPath);
// check if the data in the directory eixsts, if it does then delete it.
if (!data.codeRepository.repositoryHostedAt) {
throw new BadDataException("Repository Hosted At is required");
}
@@ -64,10 +85,12 @@ export default class CodeRepositoryUtil {
: ""
}/${data.codeRepository.organizationName}/${data.codeRepository.repositoryName}.git`;
await CodeRepositoryServerUtil.cloneRepository({
const folderName = await CodeRepositoryServerUtil.cloneRepository({
repoUrl: repoUrl,
repoPath: GetLocalRepositoryPath(),
repoPath: repoLocalPath,
});
this.folderNameOfClonedRepository = folderName;
}
public static hasOpenPRForFile(data: {
@@ -97,7 +120,7 @@ export default class CodeRepositoryUtil {
directoryPath: string;
}): Promise<Array<string>> {
return await CodeRepositoryServerUtil.listFilesInDirectory({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
directoryPath: data.directoryPath,
});
}
@@ -127,7 +150,7 @@ export default class CodeRepositoryUtil {
public static async pullChanges(): Promise<void> {
await CodeRepositoryServerUtil.pullChanges({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
});
}
@@ -161,7 +184,7 @@ export default class CodeRepositoryUtil {
});
await CodeRepositoryServerUtil.createBranch({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
branchName: branchName,
});
}
@@ -176,7 +199,7 @@ export default class CodeRepositoryUtil {
});
await CodeRepositoryServerUtil.createOrCheckoutBranch({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
branchName: branchName,
});
}
@@ -186,7 +209,7 @@ export default class CodeRepositoryUtil {
content: string;
}): Promise<void> {
await CodeRepositoryServerUtil.writeToFile({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
filePath: data.filePath,
content: data.content,
});
@@ -196,14 +219,14 @@ export default class CodeRepositoryUtil {
directoryPath: string;
}): Promise<void> {
await CodeRepositoryServerUtil.createDirectory({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
directoryPath: data.directoryPath,
});
}
public static async deleteFile(data: { filePath: string }): Promise<void> {
await CodeRepositoryServerUtil.deleteFile({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
filePath: data.filePath,
});
}
@@ -212,14 +235,14 @@ export default class CodeRepositoryUtil {
directoryPath: string;
}): Promise<void> {
await CodeRepositoryServerUtil.deleteDirectory({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
directoryPath: data.directoryPath,
});
}
public static async discardChanges(): Promise<void> {
await CodeRepositoryServerUtil.discardChanges({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
});
}
@@ -227,7 +250,7 @@ export default class CodeRepositoryUtil {
branchName: string;
}): Promise<void> {
await CodeRepositoryServerUtil.checkoutBranch({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
branchName: data.branchName,
});
}
@@ -248,7 +271,7 @@ export default class CodeRepositoryUtil {
filePaths: Array<string>;
}): Promise<void> {
await CodeRepositoryServerUtil.addFilesToGit({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
filePaths: data.filePaths,
});
}
@@ -268,7 +291,7 @@ export default class CodeRepositoryUtil {
}
await CodeRepositoryServerUtil.commitChanges({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
message: data.message,
username: username,
});
@@ -299,7 +322,7 @@ export default class CodeRepositoryUtil {
if (codeRepository.repositoryHostedAt === CodeRepositoryType.GitHub) {
return await this.getGitHubUtil().pushChanges({
repoPath: GetLocalRepositoryPath(),
repoPath: this.getLocalRepositoryPath(),
branchName: branchName,
organizationName: codeRepository.organizationName,
repositoryName: codeRepository.repositoryName,

View File

@@ -19,6 +19,8 @@ services:
extends:
file: ./docker-compose.base.yml
service: copilot
environment:
- LOG_LEVEL=DEBUG
build:
network: host
context: .