Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add remote repo config #241

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/azure-pipelines-vscode-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `[<owner>/]<repo>@<ref>=<uri>` per line. `<uri>` can be formed like `file:///<folder>` (raw file paths are not supported (yet?)), `vscode-vfs://github/<owner>/<repository>` and `vscode-vfs://azurerepos/<owner>/<project>/<repository>`

### Validate Azure Pipeline

Expand Down
1 change: 0 additions & 1 deletion src/azure-pipelines-vscode-ext/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export var basePaths = {};
export var customImports = {};
export async function myimport(url) {
console.log("fake-import: " + url);
return customImports[url];
}
2 changes: 1 addition & 1 deletion src/azure-pipelines-vscode-ext/ext-core/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Runtime.InteropServices.JavaScript;
public static partial class Interop {
[JSImport("readFile", "extension.js")]
internal static partial Task<string> ReadFile(JSObject handle, string name);
internal static partial Task<string> ReadFile(JSObject handle, string repositoryAndRef, string name);
[JSImport("message", "extension.js")]
internal static partial Task Message(int type, string message);
[JSImport("sleep", "extension.js")]
Expand Down
5 changes: 1 addition & 4 deletions src/azure-pipelines-vscode-ext/ext-core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public MyFileProvider(JSObject handle) {
private JSObject handle;
public async Task<string> 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);
}
}

Expand Down
25 changes: 22 additions & 3 deletions src/azure-pipelines-vscode-ext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
18 changes: 17 additions & 1 deletion src/azure-pipelines-vscode-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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 [<owner>/]<repo>@<ref>=<uri>. <uri> can be formed like file:///<folder>, vscode-vfs://github/<owner>/<repository> and vscode-vfs://azurerepos/<owner>/<project>/<repository>"
}
}
}
]
},
"scripts": {
Expand Down
Loading