Add open workflow action
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
17
package.json
17
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": [
|
||||
|
||||
@@ -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";
|
||||
@@ -16,6 +16,10 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
||||
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