From 92bf98995d0ce09086df9a8dbe4ed54879c2436f Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Thu, 26 Sep 2024 20:45:59 -0400 Subject: [PATCH] Add open workflow action Signed-off-by: Sanjula Ganepola --- package.json | 17 +++++++++++++++++ src/types.ts | 4 +++- .../components/componentsTreeDataProvider.ts | 2 +- src/views/settings/settingsTreeDataProvider.ts | 2 +- src/views/workflowManager.ts | 14 +++++++------- src/views/workflows/workflow.ts | 2 +- .../workflows/workflowsTreeDataProvider.ts | 8 ++++++-- 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 4fa615c..4fffb8b 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,12 @@ "title": "Refresh", "icon": "$(refresh)" }, + { + "category": "GitHub Local Actions", + "command": "githubLocalActions.openWorkflow", + "title": "Open Workflow", + "icon": "$(go-to-file)" + }, { "category": "GitHub Local Actions", "command": "githubLocalActions.refreshSettings", @@ -89,6 +95,10 @@ "command": "githubLocalActions.refreshWorkflows", "when": "never" }, + { + "command": "githubLocalActions.openWorkflow", + "when": "never" + }, { "command": "githubLocalActions.refreshSettings", "when": "never" @@ -110,6 +120,13 @@ "when": "view == settings", "group": "navigation@0" } + ], + "view/item/context": [ + { + "command": "githubLocalActions.openWorkflow", + "when": "view == workflows && viewItem =~ /^workflow.*/", + "group": "inline@0" + } ] }, "colors": [ diff --git a/src/types.ts b/src/types.ts index 04ecabd..f3de5ba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,5 @@ +import { Uri } from "vscode" + export interface Component { name: string, status: Status, @@ -13,7 +15,7 @@ export enum Status { export interface Workflow { name: string, - path: string, + uri: Uri, content?: any, error?: string } \ No newline at end of file diff --git a/src/views/components/componentsTreeDataProvider.ts b/src/views/components/componentsTreeDataProvider.ts index d030439..2464a3b 100644 --- a/src/views/components/componentsTreeDataProvider.ts +++ b/src/views/components/componentsTreeDataProvider.ts @@ -15,7 +15,7 @@ export default class ComponentsTreeDataProvider implements TreeDataProvider { this.refresh(); - }), + }) ); } diff --git a/src/views/settings/settingsTreeDataProvider.ts b/src/views/settings/settingsTreeDataProvider.ts index cb50606..ce9feb0 100644 --- a/src/views/settings/settingsTreeDataProvider.ts +++ b/src/views/settings/settingsTreeDataProvider.ts @@ -13,7 +13,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider { this.refresh(); - }), + }) ); } diff --git a/src/views/workflowManager.ts b/src/views/workflowManager.ts index 2f459b1..fd1a92c 100644 --- a/src/views/workflowManager.ts +++ b/src/views/workflowManager.ts @@ -10,21 +10,21 @@ export class WorkflowManager { const workspaceFolders = workspace.workspaceFolders; if (workspaceFolders && workspaceFolders.length > 0) { - const workflowFiles = await workspace.findFiles(`.github/workflows/*.{yml,yaml}`); + const workflowFileUris = await workspace.findFiles(`.github/workflows/*.{yml,yaml}`); - for await (const workflowFile of workflowFiles) { + for await (const workflowFileUri of workflowFileUris) { try { - const fileContent = await fs.readFile(workflowFile.fsPath, 'utf8'); + const fileContent = await fs.readFile(workflowFileUri.fsPath, 'utf8'); workflows.push({ - name: path.parse(workflowFile.fsPath).name, - path: workflowFile.fsPath, + name: path.parse(workflowFileUri.fsPath).name, + uri: workflowFileUri, content: yaml.parse(fileContent) }); } catch (error) { workflows.push({ - name: path.parse(workflowFile.fsPath).name, - path: workflowFile.fsPath, + name: path.parse(workflowFileUri.fsPath).name, + uri: workflowFileUri, error: 'Failed to parse workflow file' }); } diff --git a/src/views/workflows/workflow.ts b/src/views/workflows/workflow.ts index 774a94b..cdacd3f 100644 --- a/src/views/workflows/workflow.ts +++ b/src/views/workflows/workflow.ts @@ -12,7 +12,7 @@ export default class WorkflowTreeItem extends TreeItem implements GithubLocalAct this.contextValue = WorkflowTreeItem.contextValue; this.iconPath = new ThemeIcon('layers'); this.tooltip = `Name: ${workflow.name}\n` + - `Path: ${workflow.path}`; + `Path: ${workflow.uri.fsPath}`; if(workflow.error) { this.resourceUri = Uri.parse(`${WorkflowTreeItem.contextValue}:${workflow.name}?error=${workflow.error}`, true); diff --git a/src/views/workflows/workflowsTreeDataProvider.ts b/src/views/workflows/workflowsTreeDataProvider.ts index f03aa8b..6387674 100644 --- a/src/views/workflows/workflowsTreeDataProvider.ts +++ b/src/views/workflows/workflowsTreeDataProvider.ts @@ -1,4 +1,4 @@ -import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem } from "vscode"; +import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { WorkflowManager } from "../workflowManager"; import WorkflowTreeItem from "./workflow"; @@ -12,10 +12,14 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider { this.refresh(); }), + commands.registerCommand('githubLocalActions.openWorkflow', async (workflowTreeItem: WorkflowTreeItem) => { + const document = await workspace.openTextDocument(workflowTreeItem.workflow.uri); + await window.showTextDocument(document); + }) ); }