Skip to content

Commit

Permalink
Ensure dir exists before cloning a repo to it
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Dec 9, 2024
1 parent 48a34a8 commit 25bdada
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/functions/scm/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fs from 'node:fs';
import util from 'util';
import { getFileSystem } from '#agent/agentContextLocalStorage';
import { funcClass } from '#functionSchema/functionDecorators';
import { FileSystemService } from '#functions/storage/fileSystemService';
import { logger } from '#o11y/logger';
Expand All @@ -15,6 +17,7 @@ export class Git implements VersionControlSystem {
constructor(private fileSystem: FileSystemService) {}

async clone(repoURL: string, commitOrBranch = ''): Promise<void> {
await fs.promises.mkdir(getFileSystem().getWorkingDirectory(), { recursive: true });
const { exitCode, stdout, stderr } = await execCommand(`git clone ${repoURL} ${commitOrBranch}`);
if (exitCode > 0) throw new Error(`${stdout}\n${stderr}`);
}
Expand Down
4 changes: 3 additions & 1 deletion src/functions/scm/gitlab.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync } from 'fs';
import fs from 'node:fs';
import { join } from 'path';
import {
CommitDiffSchema,
Expand Down Expand Up @@ -192,8 +193,9 @@ export class GitLab implements SourceControlManagement {
// checkExecResult(result, `Failed to pull ${path}`);
} else {
logger.info(`Cloning project: ${projectPathWithNamespace} to ${path}`);
await fs.promises.mkdir(path, { recursive: true });
const command = `git clone https://oauth2:${this.config().token}@${this.config().host}/${projectPathWithNamespace}.git ${path}`;
const result = await execCommand(command);
const result = await execCommand(command, { mask: this.config().token });

Check failure on line 198 in src/functions/scm/gitlab.ts

View workflow job for this annotation

GitHub Actions / backend

Object literal may only specify known properties, and 'mask' does not exist in type 'ExecCmdOptions'.

if (result.stderr?.includes('remote HEAD refers to nonexistent ref')) {
const gitProject = await this.getProject(projectPathWithNamespace);
Expand Down

0 comments on commit 25bdada

Please sign in to comment.