Skip to content

Commit a7ceea8

Browse files
committed
fix repo url to use ssh when cloning
1 parent 9a7df57 commit a7ceea8

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

.changeset/breezy-students-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ryanatkn/fuz_gitops': patch
3+
---
4+
5+
fix repo url to use ssh when cloning

src/lib/gitops_task_helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ const download_repos = async (
9898
log: Logger | undefined,
9999
): Promise<Resolved_Local_Repo[]> => {
100100
const resolved: Resolved_Local_Repo[] = [];
101-
for (const {repo_config, repo_url} of unresolved_local_repos) {
102-
log?.info(`Cloning repo ${repo_url} to ${repos_dir}`);
103-
await spawn_cli('git', ['clone', repo_url], log, {cwd: repos_dir}); // eslint-disable-line no-await-in-loop
101+
for (const {repo_config, repo_git_ssh_url} of unresolved_local_repos) {
102+
log?.info(`Cloning repo ${repo_git_ssh_url} to ${repos_dir}`);
103+
await spawn_cli('git', ['clone', repo_git_ssh_url], log, {cwd: repos_dir}); // eslint-disable-line no-await-in-loop
104104
const local_repo = await resolve_local_repo(repo_config, repos_dir); // eslint-disable-line no-await-in-loop
105105
if (local_repo.type === 'unresolved_local_repo') {
106-
throw new Task_Error(`Failed to clone repo ${repo_url} to ${repos_dir}`);
106+
throw new Task_Error(`Failed to clone repo ${repo_git_ssh_url} to ${repos_dir}`);
107107
}
108108
await spawn_cli('npm', ['install'], log, {cwd: local_repo.repo_dir}); // eslint-disable-line no-await-in-loop
109109
resolved.push(local_repo);

src/lib/local_repo.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Resolved_Local_Repo {
1515
repo_name: string;
1616
repo_dir: string;
1717
repo_url: string;
18+
repo_git_ssh_url: string;
1819
repo_config: Gitops_Repo_Config;
1920
pkg: Package_Meta;
2021
// TODO what else? filesystem info?
@@ -24,6 +25,7 @@ export interface Unresolved_Local_Repo {
2425
type: 'unresolved_local_repo';
2526
repo_name: string;
2627
repo_url: string;
28+
repo_git_ssh_url: string;
2729
repo_config: Gitops_Repo_Config;
2830
}
2931

@@ -35,9 +37,11 @@ export const resolve_local_repo = async (
3537
const repo_name = strip_end(repo_url, '/').split('/').at(-1);
3638
if (!repo_name) throw Error('Invalid `repo_config.repo_url` ' + repo_url);
3739

40+
const repo_git_ssh_url = to_repo_git_ssh_url(repo_url);
41+
3842
const repo_dir = repo_config.repo_dir ?? join(repos_dir, repo_name);
3943
if (!existsSync(repo_dir)) {
40-
return {type: 'unresolved_local_repo', repo_name, repo_url, repo_config};
44+
return {type: 'unresolved_local_repo', repo_name, repo_url, repo_git_ssh_url, repo_config};
4145
}
4246

4347
const parsed_sveltekit_config = await init_sveltekit_config(repo_dir);
@@ -51,7 +55,13 @@ export const resolve_local_repo = async (
5155
repo_name,
5256
repo_dir,
5357
repo_url,
58+
repo_git_ssh_url,
5459
repo_config,
5560
pkg: parse_package_meta(package_json, src_json),
5661
};
5762
};
63+
64+
const to_repo_git_ssh_url = (repo_url: string): string => {
65+
const url = new URL(repo_url);
66+
return `git@${url.hostname}:${url.pathname.substring(1)}`;
67+
};

0 commit comments

Comments
 (0)