From 559956e2ebf1f7c48f0da89254252c1aa08d0c54 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:56:07 +0200 Subject: [PATCH 1/8] Create the full upload basepath If a nested basepath `'a/b/c'` is given and does not exist yet, all directories in the basepath will be created, similar to using `mkdir -p` --- src/gitpuller.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gitpuller.ts b/src/gitpuller.ts index 4f7c042..96434ab 100644 --- a/src/gitpuller.ts +++ b/src/gitpuller.ts @@ -23,7 +23,14 @@ export abstract class GitPuller { * @returns the path of the created directory. */ async clone(url: string, branch: string, basePath: string): Promise { - await this.createTree([basePath]); + const basePathComponents = basePath.split('/'); + const basePathPrefixes = []; + for (let i = 0; i < basePathComponents.length; i++) { + basePathPrefixes.push(basePathComponents.slice(0, i+1).join('/')); + } + + // For a basePath 'a/b/c', create ['a', 'a/b', 'a/b/c'] + await this.createTree(basePathPrefixes); const fileList = await this.getFileList(url, branch); From 80f5c7ae4aa242277aac0d7fd7869f5dc3b7f28b Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:01:27 +0200 Subject: [PATCH 2/8] Add a `uploadpath` query param to upload the repo to --- src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d08f508..4369067 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,10 +61,12 @@ const gitPullerExtension: JupyterFrontEndPlugin = { let puller: GitPuller | null = null; - const basePath = PathExt.basename(repo); const branch = urlParams.get('branch') || 'main'; const provider = urlParams.get('provider') || 'github'; const filePath = urlParams.get('urlpath'); + const uploadPath = urlParams.get('uploadpath') | '/'; + + const basePath = PathExt.join(uploadPath, PathExt.basename(repo)); const repoUrl = new URL(repo); if (provider === 'github') { @@ -95,10 +97,10 @@ const gitPullerExtension: JupyterFrontEndPlugin = { return; } - puller.clone(repoUrl.href, branch, basePath).then(async basePath => { + puller.clone(repoUrl.href, branch, basePath).then(async repoPath => { if (filePath) { app.commands.execute('filebrowser:open-path', { - path: PathExt.join(basePath, filePath) + path: PathExt.join(repoPath, filePath) }); } }); From ede30d69490ca1249e45e3b4c03cce4f71e55bda Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:03:58 +0200 Subject: [PATCH 3/8] Document the new `uploadpath` query parameter --- docs/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 440500a..902f8aa 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,7 +25,8 @@ Currently the allowed parameters are: - `repo`: (**required**) the github repository to fetch. - `branch`: the branch of the repository to fetch (default to _main_). - `urlpath`: the path to a notebook file to open (relative to the root of the repository). -- `provider`: The provider of the API. Currently it supports _Github_ and _Gitlab_ API. +- `provider`: the provider of the API. Currently it supports _Github_ and _Gitlab_ API. +- `uploadpath`: the path to the directory in which the repository directory is created. ## Limitations From ada3214d35fc65b773f238a470956af5ab82695f Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:11:10 +0200 Subject: [PATCH 4/8] Fix code formatting --- src/gitpuller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitpuller.ts b/src/gitpuller.ts index 96434ab..e1f4b1a 100644 --- a/src/gitpuller.ts +++ b/src/gitpuller.ts @@ -26,7 +26,7 @@ export abstract class GitPuller { const basePathComponents = basePath.split('/'); const basePathPrefixes = []; for (let i = 0; i < basePathComponents.length; i++) { - basePathPrefixes.push(basePathComponents.slice(0, i+1).join('/')); + basePathPrefixes.push(basePathComponents.slice(0, i + 1).join('/')); } // For a basePath 'a/b/c', create ['a', 'a/b', 'a/b/c'] From 0f6ec1a9855ffe72627623afa862edfec135f3a5 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:14:46 +0200 Subject: [PATCH 5/8] Fix uploadpath default --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4369067..922d0b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,7 @@ const gitPullerExtension: JupyterFrontEndPlugin = { const branch = urlParams.get('branch') || 'main'; const provider = urlParams.get('provider') || 'github'; const filePath = urlParams.get('urlpath'); - const uploadPath = urlParams.get('uploadpath') | '/'; + const uploadPath = urlParams.get('uploadpath') || '/'; const basePath = PathExt.join(uploadPath, PathExt.basename(repo)); From a807cd6f447693fe4156c9c0b8d65f0ad972db1e Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:16:24 +0200 Subject: [PATCH 6/8] Remove extraneous async --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 922d0b1..ded0559 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,7 @@ const gitPullerExtension: JupyterFrontEndPlugin = { return; } - puller.clone(repoUrl.href, branch, basePath).then(async repoPath => { + puller.clone(repoUrl.href, branch, basePath).then(repoPath => { if (filePath) { app.commands.execute('filebrowser:open-path', { path: PathExt.join(repoPath, filePath) From 921c52c3be7568833e59ef084af45f4d0d29b1cb Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:20:23 +0200 Subject: [PATCH 7/8] Add missing awaits --- src/gitpuller.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gitpuller.ts b/src/gitpuller.ts index e1f4b1a..61cfe16 100644 --- a/src/gitpuller.ts +++ b/src/gitpuller.ts @@ -103,10 +103,9 @@ export abstract class GitPuller { path: PathExt.dirname(directory) }; // Create directory if it does not exist. - await this._contents.get(directory, { content: false }).catch(() => { - this._contents.newUntitled(options).then(async newDirectory => { - await this._contents.rename(newDirectory.path, directory); - }); + await this._contents.get(directory, { content: false }).catch(async () => { + const newDirectory = await this._contents.newUntitled(options); + await this._contents.rename(newDirectory.path, directory); }); } } From 3963bd15f26808648374e78c14d43ee5eaa16d2d Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:29:03 +0000 Subject: [PATCH 8/8] Fix prettier --- src/gitpuller.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gitpuller.ts b/src/gitpuller.ts index 61cfe16..dfc38e9 100644 --- a/src/gitpuller.ts +++ b/src/gitpuller.ts @@ -103,10 +103,12 @@ export abstract class GitPuller { path: PathExt.dirname(directory) }; // Create directory if it does not exist. - await this._contents.get(directory, { content: false }).catch(async () => { - const newDirectory = await this._contents.newUntitled(options); - await this._contents.rename(newDirectory.path, directory); - }); + await this._contents + .get(directory, { content: false }) + .catch(async () => { + const newDirectory = await this._contents.newUntitled(options); + await this._contents.rename(newDirectory.path, directory); + }); } }