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

@@ -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
}

View File

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

View File

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

View File

@@ -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'
});
}

View File

@@ -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);

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