From 3c324c2ce7509ca10061cf17b264a778eaf24069 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Wed, 18 Oct 2023 12:35:52 +0200 Subject: [PATCH 1/2] add remote repo config --- src/azure-pipelines-vscode-ext/config.js | 1 - .../ext-core/Interop.cs | 2 +- .../ext-core/Program.cs | 5 +--- src/azure-pipelines-vscode-ext/index.js | 25 ++++++++++++++++--- src/azure-pipelines-vscode-ext/package.json | 18 ++++++++++++- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/azure-pipelines-vscode-ext/config.js b/src/azure-pipelines-vscode-ext/config.js index 991026d6bba..1aa32e81316 100644 --- a/src/azure-pipelines-vscode-ext/config.js +++ b/src/azure-pipelines-vscode-ext/config.js @@ -1,6 +1,5 @@ export var basePaths = {}; export var customImports = {}; export async function myimport(url) { - console.log("fake-import: " + url); return customImports[url]; } \ No newline at end of file diff --git a/src/azure-pipelines-vscode-ext/ext-core/Interop.cs b/src/azure-pipelines-vscode-ext/ext-core/Interop.cs index 8055064010b..bb41297c93b 100644 --- a/src/azure-pipelines-vscode-ext/ext-core/Interop.cs +++ b/src/azure-pipelines-vscode-ext/ext-core/Interop.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices.JavaScript; public static partial class Interop { [JSImport("readFile", "extension.js")] - internal static partial Task ReadFile(JSObject handle, string name); + internal static partial Task ReadFile(JSObject handle, string repositoryAndRef, string name); [JSImport("message", "extension.js")] internal static partial Task Message(int type, string message); [JSImport("sleep", "extension.js")] diff --git a/src/azure-pipelines-vscode-ext/ext-core/Program.cs b/src/azure-pipelines-vscode-ext/ext-core/Program.cs index 311639736fe..a40a0862d85 100644 --- a/src/azure-pipelines-vscode-ext/ext-core/Program.cs +++ b/src/azure-pipelines-vscode-ext/ext-core/Program.cs @@ -18,10 +18,7 @@ public MyFileProvider(JSObject handle) { private JSObject handle; public async Task ReadFile(string repositoryAndRef, string path) { - if(!string.IsNullOrEmpty(repositoryAndRef)) { - return await Interop.ReadFile(handle, $"{repositoryAndRef}/{path}"); - } - return await Interop.ReadFile(handle, path); + return await Interop.ReadFile(handle, repositoryAndRef, path); } } diff --git a/src/azure-pipelines-vscode-ext/index.js b/src/azure-pipelines-vscode-ext/index.js index 1a07c3c9064..f4964b02f46 100644 --- a/src/azure-pipelines-vscode-ext/index.js +++ b/src/azure-pipelines-vscode-ext/index.js @@ -35,15 +35,26 @@ function activate(context) { })(); }).create(); runtime.setModuleImports("extension.js", { - readFile: async (handle, filename) => { + readFile: async (handle, repositoryAndRef, filename) => { try { + var uri = ""; + if(repositoryAndRef) { + if(handle.repositories && repositoryAndRef in handle.repositories) { + var base = vscode.Uri.parse(handle.repositories[repositoryAndRef]); + uri = base.with({ path: base.path + "/" + filename }); + } else { + return null; + } + } else { // Get current textEditor content for the entrypoint var doc = handle.textEditor.document; if(handle.filename === filename && doc) { return doc.getText(); + } + uri = handle.base.with({ path: handle.base.path + "/" + filename }); } // Read template references via filesystem api - var content = await vscode.workspace.fs.readFile(handle.base.with({ path: handle.base.path + "/" + filename })); + var content = await vscode.workspace.fs.readFile(uri); var scontent = new TextDecoder().decode(content); return scontent; } catch { @@ -75,6 +86,14 @@ function activate(context) { await vscode.window.showErrorMessage("No active TextEditor"); return; } + var conf = vscode.workspace.getConfiguration("azure-pipelines"); + var repositories = {}; + for(var repo of conf.repositories ?? []) { + var line = repo.split("="); + var name = line.shift(); + repositories[name] = line.join("="); + } + var runtime = await runtimePromise; var base = null; var filename = null; @@ -90,7 +109,7 @@ function activate(context) { var li = current.path.lastIndexOf("/"); base ??= current.with({ path: current.path.substring(0, li)}); filename ??= current.path.substring(li + 1); - var result = await runtime.BINDING.bind_static_method("[ext-core] MyClass:ExpandCurrentPipeline")({ base: base, textEditor: textEditor, filename: filename }, filename); + var result = await runtime.BINDING.bind_static_method("[ext-core] MyClass:ExpandCurrentPipeline")({ base: base, textEditor: textEditor, filename: filename, repositories: repositories }, filename); if(result) { if(validate) { await vscode.window.showInformationMessage("No issues found"); diff --git a/src/azure-pipelines-vscode-ext/package.json b/src/azure-pipelines-vscode-ext/package.json index 65bbfb91c80..5cf892ac376 100644 --- a/src/azure-pipelines-vscode-ext/package.json +++ b/src/azure-pipelines-vscode-ext/package.json @@ -6,7 +6,7 @@ "Testing", "Programming Languages" ], - "version": "0.0.3", + "version": "0.0.4", "publisher": "christopherhx", "repository": "https://github.com/ChristopherHX/runner.server", "engines": { @@ -27,6 +27,22 @@ "command": "extension.expandAzurePipeline", "title": "Expand Azure Pipeline" } + ], + "configuration":[ + { + "title": "Azure Pipelines", + "properties": { + "azure-pipelines.repositories": { + "type":"array", + "items": { + "type":"string" + }, + "default":[], + "scope":"window", + "description":"Syntax [/]@=. can be formed like file:///, vscode-vfs://github// and vscode-vfs://azurerepos///" + } + } + } ] }, "scripts": { From 39b00cdf0575f1a35749582b58e5041a1aea6345 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Thu, 19 Oct 2023 17:29:33 +0200 Subject: [PATCH 2/2] update readme --- .github/workflows/deploy-pages.yml | 5 +++++ src/azure-pipelines-vscode-ext/README.md | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 8fa23478182..c0ee5f1b2d2 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -51,6 +51,11 @@ jobs: mv src/azure-pipelines-vscode-ext/dist webapp/azure-pipelines-vscode-ext/ mv src/azure-pipelines-vscode-ext/package.json webapp/azure-pipelines-vscode-ext/ mv src/azure-pipelines-vscode-ext/*.vsix webapp/azure-pipelines-vscode-ext/ + - name: Upload vsix + uses: actions/upload-artifact@v3 + with: + name: azure-pipelines-vscode-ext-pre-release + path: webapp/azure-pipelines-vscode-ext/azure-pipelines-vscode-ext-pre-release.vsix - name: Setup Pages if: github.event_name == 'push' uses: actions/configure-pages@v3 diff --git a/src/azure-pipelines-vscode-ext/README.md b/src/azure-pipelines-vscode-ext/README.md index bd77fea91d2..ffde12b479d 100644 --- a/src/azure-pipelines-vscode-ext/README.md +++ b/src/azure-pipelines-vscode-ext/README.md @@ -6,8 +6,9 @@ This is a minimal Azure Pipelines Extension ### Remote Template References -**Subject to change** -Checkout your dependent template repository under a folder named like `repo@ref`, `owner/repo@ref` within the same workspace as your pipeline. +The `azure-pipelines.repositories` settings maps the external Repositories to local or remote folders. + +Syntax `[/]@=` per line. `` can be formed like `file:///` (raw file paths are not supported (yet?)), `vscode-vfs://github//` and `vscode-vfs://azurerepos///` ### Validate Azure Pipeline