mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Add cloneRepository method to CodeRepositoryUtil
This commit adds a new method, cloneRepository, to the CodeRepositoryUtil class. The method is responsible for cloning a repository from a given URL to a specified path. It uses the git clone command to perform the cloning operation. This method will be used to clone the repository to a temporary directory in the Copilot/Init.ts file. The method takes an object as a parameter, which includes the repoPath and repoUrl. It executes the git clone command using the Execute.executeCommand() method and logs the output using the logger.debug() method. This new method enhances the functionality of the CodeRepositoryUtil class and improves the codebase.
This commit is contained in:
@@ -6,6 +6,20 @@ import Dictionary from "Common/Types/Dictionary";
|
||||
import ServiceLanguageUtil from "Common/Utils/ServiceLanguage";
|
||||
|
||||
export default class CodeRepositoryUtil {
|
||||
|
||||
public static async cloneRepository(data: {
|
||||
repoPath: string;
|
||||
repoUrl: string;
|
||||
}): Promise<void> {
|
||||
const command: string = `cd ${data.repoPath} && git clone ${data.repoUrl}`;
|
||||
|
||||
logger.debug("Executing command: " + command);
|
||||
|
||||
const stdout: string = await Execute.executeCommand(command);
|
||||
|
||||
logger.debug(stdout);
|
||||
}
|
||||
|
||||
public static async pullChanges(data: { repoPath: string }): Promise<void> {
|
||||
const command: string = `cd ${data.repoPath} && git pull`;
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ RUN npm install
|
||||
|
||||
|
||||
# Create /repository/ directory where the app will store the repository
|
||||
RUN mkdir /repository
|
||||
RUN mkdir -p /repository
|
||||
|
||||
# Set the stack trace limit to 0 to show full stack traces
|
||||
ENV NODE_OPTIONS='--stack-trace-limit=30'
|
||||
|
||||
@@ -24,10 +24,14 @@ import CopilotActionProcessingException from "./Exceptions/CopilotActionProcessi
|
||||
let currentFixCount: number = 1;
|
||||
|
||||
const init: PromiseVoidFunction = async (): Promise<void> => {
|
||||
|
||||
debugger;
|
||||
|
||||
const codeRepositoryResult: CodeRepositoryResult = await InitUtil.init()
|
||||
const codeRepositoryResult: CodeRepositoryResult = await InitUtil.init();
|
||||
|
||||
// now clone this repository to a temporary directory - /repository
|
||||
await CodeRepositoryUtil.cloneRepository({
|
||||
codeRepository: codeRepositoryResult.codeRepository,
|
||||
});
|
||||
|
||||
|
||||
for (const serviceToImrove of codeRepositoryResult.servicesToImprove) {
|
||||
checkIfCurrentFixCountIsLessThanFixNumberOfCodeEventsInEachRun();
|
||||
|
||||
@@ -36,6 +36,40 @@ export default class CodeRepositoryUtil {
|
||||
public static codeRepositoryResult: CodeRepositoryResult | null = null;
|
||||
public static gitHubUtil: GitHubUtil | null = null;
|
||||
|
||||
public static async cloneRepository(data: {
|
||||
codeRepository: CodeRepositoryModel;
|
||||
}): Promise<void> {
|
||||
if (!data.codeRepository.repositoryHostedAt) {
|
||||
throw new BadDataException("Repository Hosted At is required");
|
||||
}
|
||||
|
||||
if (!data.codeRepository.mainBranchName) {
|
||||
throw new BadDataException("Main Branch Name is required");
|
||||
}
|
||||
|
||||
if (!data.codeRepository.organizationName) {
|
||||
throw new BadDataException("Organization Name is required");
|
||||
}
|
||||
|
||||
if (!data.codeRepository.repositoryName) {
|
||||
throw new BadDataException("Repository Name is required");
|
||||
}
|
||||
|
||||
const GithubUsername = GetGitHubUsername();
|
||||
const GithubToken = GetGitHubToken();
|
||||
|
||||
const repoUrl = `https://${GithubUsername}:${GithubToken}@${
|
||||
data.codeRepository.repositoryHostedAt === CodeRepositoryType.GitHub
|
||||
? "github.com"
|
||||
: ""
|
||||
}/${data.codeRepository.organizationName}/${data.codeRepository.repositoryName}.git`;
|
||||
|
||||
await CodeRepositoryServerUtil.cloneRepository({
|
||||
repoUrl: repoUrl,
|
||||
repoPath: GetLocalRepositoryPath(),
|
||||
});
|
||||
}
|
||||
|
||||
public static hasOpenPRForFile(data: {
|
||||
filePath: string;
|
||||
pullRequests: Array<PullRequest>;
|
||||
|
||||
Reference in New Issue
Block a user