Skip to content

Commit f1b4ddb

Browse files
committed
refactor: simplify pullRemote and replace sync fs functions with fs.promises
1 parent 2fe2548 commit f1b4ddb

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

src/proxy/processors/push-action/pullRemote.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ type CloneResult = {
1818
strategy: Action['pullAuthStrategy'];
1919
};
2020

21-
const ensureDirectory = (targetPath: string) => {
22-
if (!fs.existsSync(targetPath)) {
23-
fs.mkdirSync(targetPath, { recursive: true, mode: 0o755 });
24-
}
21+
const ensureDirectory = async (targetPath: string) => {
22+
await fs.promises.mkdir(targetPath, { recursive: true, mode: 0o755 });
2523
};
2624

2725
const decodeBasicAuth = (authHeader?: string): BasicCredentials | null => {
@@ -53,15 +51,7 @@ const buildSSHCloneUrl = (remoteUrl: string): string => {
5351
};
5452

5553
const cleanupTempDir = async (tempDir: string) => {
56-
try {
57-
await fs.promises.rm(tempDir, { recursive: true, force: true });
58-
} catch {
59-
try {
60-
await fs.promises.rmdir(tempDir, { recursive: true });
61-
} catch (_) {
62-
// ignore cleanup errors
63-
}
64-
}
54+
await fs.promises.rm(tempDir, { recursive: true, force: true });
6555
};
6656

6757
const cloneWithHTTPS = async (
@@ -75,12 +65,9 @@ const cloneWithHTTPS = async (
7565
dir: `${action.proxyGitPath}/${action.repoName}`,
7666
singleBranch: true,
7767
depth: 1,
68+
onAuth: credentials ? () => credentials : undefined,
7869
};
7970

80-
if (credentials) {
81-
cloneOptions.onAuth = () => credentials;
82-
}
83-
8471
await git.clone(cloneOptions);
8572
};
8673

@@ -165,16 +152,8 @@ const exec = async (req: any, action: Action): Promise<Action> => {
165152
try {
166153
action.proxyGitPath = `${dir}/${action.id}`;
167154

168-
if (!fs.existsSync(dir)) {
169-
fs.mkdirSync(dir);
170-
}
171-
172-
if (!fs.existsSync(action.proxyGitPath)) {
173-
step.log(`Creating folder ${action.proxyGitPath}`);
174-
fs.mkdirSync(action.proxyGitPath, { recursive: true, mode: 0o755 });
175-
}
176-
177-
ensureDirectory(action.proxyGitPath);
155+
await ensureDirectory(dir);
156+
await ensureDirectory(action.proxyGitPath);
178157

179158
let result: CloneResult;
180159

@@ -207,5 +186,4 @@ const exec = async (req: any, action: Action): Promise<Action> => {
207186
};
208187

209188
exec.displayName = 'pullRemote.exec';
210-
211189
export { exec };

0 commit comments

Comments
 (0)