Add open workflow action

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-09-26 20:45:59 -04:00
parent 57809e46ff
commit 92bf98995d
7 changed files with 36 additions and 13 deletions

View File

@@ -72,6 +72,12 @@
"title": "Refresh", "title": "Refresh",
"icon": "$(refresh)" "icon": "$(refresh)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.openWorkflow",
"title": "Open Workflow",
"icon": "$(go-to-file)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
@@ -89,6 +95,10 @@
"command": "githubLocalActions.refreshWorkflows", "command": "githubLocalActions.refreshWorkflows",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.openWorkflow",
"when": "never"
},
{ {
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
"when": "never" "when": "never"
@@ -110,6 +120,13 @@
"when": "view == settings", "when": "view == settings",
"group": "navigation@0" "group": "navigation@0"
} }
],
"view/item/context": [
{
"command": "githubLocalActions.openWorkflow",
"when": "view == workflows && viewItem =~ /^workflow.*/",
"group": "inline@0"
}
] ]
}, },
"colors": [ "colors": [

View File

@@ -1,3 +1,5 @@
import { Uri } from "vscode"
export interface Component { export interface Component {
name: string, name: string,
status: Status, status: Status,
@@ -13,7 +15,7 @@ export enum Status {
export interface Workflow { export interface Workflow {
name: string, name: string,
path: string, uri: Uri,
content?: any, content?: any,
error?: string error?: string
} }

View File

@@ -15,7 +15,7 @@ export default class ComponentsTreeDataProvider implements TreeDataProvider<Gith
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.refreshComponents', async () => { commands.registerCommand('githubLocalActions.refreshComponents', async () => {
this.refresh(); this.refresh();
}), })
); );
} }

View File

@@ -13,7 +13,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.refreshSettings', async () => { commands.registerCommand('githubLocalActions.refreshSettings', async () => {
this.refresh(); this.refresh();
}), })
); );
} }

View File

@@ -10,21 +10,21 @@ export class WorkflowManager {
const workspaceFolders = workspace.workspaceFolders; const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) { 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 { try {
const fileContent = await fs.readFile(workflowFile.fsPath, 'utf8'); const fileContent = await fs.readFile(workflowFileUri.fsPath, 'utf8');
workflows.push({ workflows.push({
name: path.parse(workflowFile.fsPath).name, name: path.parse(workflowFileUri.fsPath).name,
path: workflowFile.fsPath, uri: workflowFileUri,
content: yaml.parse(fileContent) content: yaml.parse(fileContent)
}); });
} catch (error) { } catch (error) {
workflows.push({ workflows.push({
name: path.parse(workflowFile.fsPath).name, name: path.parse(workflowFileUri.fsPath).name,
path: workflowFile.fsPath, uri: workflowFileUri,
error: 'Failed to parse workflow file' error: 'Failed to parse workflow file'
}); });
} }

View File

@@ -12,7 +12,7 @@ export default class WorkflowTreeItem extends TreeItem implements GithubLocalAct
this.contextValue = WorkflowTreeItem.contextValue; this.contextValue = WorkflowTreeItem.contextValue;
this.iconPath = new ThemeIcon('layers'); this.iconPath = new ThemeIcon('layers');
this.tooltip = `Name: ${workflow.name}\n` + this.tooltip = `Name: ${workflow.name}\n` +
`Path: ${workflow.path}`; `Path: ${workflow.uri.fsPath}`;
if(workflow.error) { if(workflow.error) {
this.resourceUri = Uri.parse(`${WorkflowTreeItem.contextValue}:${workflow.name}?error=${workflow.error}`, true); this.resourceUri = Uri.parse(`${WorkflowTreeItem.contextValue}:${workflow.name}?error=${workflow.error}`, true);

View File

@@ -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 { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import { WorkflowManager } from "../workflowManager"; import { WorkflowManager } from "../workflowManager";
import WorkflowTreeItem from "./workflow"; import WorkflowTreeItem from "./workflow";
@@ -12,10 +12,14 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
constructor(context: ExtensionContext) { constructor(context: ExtensionContext) {
this.workflowManager = new WorkflowManager(); this.workflowManager = new WorkflowManager();
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.refreshWorkflows', async () => { commands.registerCommand('githubLocalActions.refreshWorkflows', async () => {
this.refresh(); this.refresh();
}), }),
commands.registerCommand('githubLocalActions.openWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
const document = await workspace.openTextDocument(workflowTreeItem.workflow.uri);
await window.showTextDocument(document);
})
); );
} }