Add open workflow action
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export default class ComponentsTreeDataProvider implements TreeDataProvider<Gith
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('githubLocalActions.refreshComponents', async () => {
|
||||
this.refresh();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('githubLocalActions.refreshSettings', async () => {
|
||||
this.refresh();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user