Add clear all, restart, stop, remove actions for history

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-17 21:30:04 -04:00
parent 0e6baaaad1
commit f215c03697
4 changed files with 220 additions and 60 deletions

View File

@@ -66,39 +66,65 @@
}, },
"viewsWelcome": [ "viewsWelcome": [
{ {
"view": "components", "view": "components",
"contents": "Loading components..." "contents": "Loading components...",
}, "when": "!githubLocalActions:noComponents && workspaceFolderCount > 0"
},
{ {
"view": "workflows", "view": "components",
"contents": "Loading components...", "contents": "No workspace folder opened",
"when": "!githubLocalActions:noWorkflows" "when": "workspaceFolderCount == 0"
}, },
{ {
"view": "workflows", "view": "components",
"contents": "No workflows found.", "contents": "No components found.",
"when": "githubLocalActions:noWorkflows" "when": "githubLocalActions:noComponents && workspaceFolderCount > 0"
}, },
{ {
"view": "history", "view": "workflows",
"contents": "Loading history...", "contents": "Loading components...",
"when": "!githubLocalActions:noHistory" "when": "!githubLocalActions:noWorkflows && workspaceFolderCount > 0"
}, },
{ {
"view": "history", "view": "workflows",
"contents": "No history found.", "contents": "No workspace folder opened",
"when": "githubLocalActions:noHistory" "when": "workspaceFolderCount == 0"
}, },
{ {
"view": "settings", "view": "workflows",
"contents": "Loading settings...", "contents": "No workflows found.",
"when": "!githubLocalActions:noSettings" "when": "githubLocalActions:noWorkflows && workspaceFolderCount > 0"
}, },
{ {
"view": "settings", "view": "history",
"contents": "No workflows found.", "contents": "Loading history...",
"when": "githubLocalActions:noSettings" "when": "!githubLocalActions:noHistory && workspaceFolderCount > 0"
} },
{
"view": "history",
"contents": "No workspace folder opened",
"when": "workspaceFolderCount == 0"
},
{
"view": "history",
"contents": "No history found.",
"when": "githubLocalActions:noHistory && workspaceFolderCount > 0"
},
{
"view": "settings",
"contents": "Loading settings...",
"when": "!githubLocalActions:noSettings && workspaceFolderCount > 0"
},
{
"view": "settings",
"contents": "No workspace folder opened",
"when": "workspaceFolderCount == 0"
},
{
"view": "settings",
"contents": "No workflows found.",
"when": "githubLocalActions:noSettings && workspaceFolderCount > 0"
}
], ],
"commands": [ "commands": [
{ {
@@ -129,12 +155,14 @@
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.runAllWorkflows", "command": "githubLocalActions.runAllWorkflows",
"title": "Run All Workflows", "title": "Run All Workflows",
"enablement": "!githubLocalActions:noWorkflows && workspaceFolderCount > 0",
"icon": "$(run-all)" "icon": "$(run-all)"
}, },
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.runEvent", "command": "githubLocalActions.runEvent",
"title": "Run Event", "title": "Run Event",
"enablement": "!githubLocalActions:noWorkflows && workspaceFolderCount > 0",
"icon": "$(symbol-event)" "icon": "$(symbol-event)"
}, },
{ {
@@ -161,12 +189,40 @@
"title": "Run Job", "title": "Run Job",
"icon": "$(debug-start)" "icon": "$(debug-start)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.clearAll",
"title": "Clear All",
"enablement": "!githubLocalActions:isRunning && !githubLocalActions:noWorkflows && workspaceFolderCount > 0",
"icon": "$(clear-all)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.refreshHistory", "command": "githubLocalActions.refreshHistory",
"title": "Refresh", "title": "Refresh",
"icon": "$(refresh)" "icon": "$(refresh)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.restart",
"title": "Restart",
"enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/",
"icon": "$(debug-restart)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.stop",
"title": "Stop",
"enablement": "viewItem =~ /^githubLocalActions.history_(Running).*/",
"icon": "$(debug-stop)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.remove",
"title": "Remove",
"enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/",
"icon": "$(close)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
@@ -216,10 +272,26 @@
"command": "githubLocalActions.runJob", "command": "githubLocalActions.runJob",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.clearAll",
"when": "never"
},
{ {
"command": "githubLocalActions.refreshHistory", "command": "githubLocalActions.refreshHistory",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.restart",
"when": "never"
},
{
"command": "githubLocalActions.stop",
"when": "never"
},
{
"command": "githubLocalActions.remove",
"when": "never"
},
{ {
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
"when": "never" "when": "never"
@@ -247,10 +319,15 @@
"group": "navigation@2" "group": "navigation@2"
}, },
{ {
"command": "githubLocalActions.refreshHistory", "command": "githubLocalActions.clearAll",
"when": "view == history", "when": "view == history",
"group": "navigation@0" "group": "navigation@0"
}, },
{
"command": "githubLocalActions.refreshHistory",
"when": "view == history",
"group": "navigation@1"
},
{ {
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
"when": "view == settings", "when": "view == settings",
@@ -287,6 +364,21 @@
"command": "githubLocalActions.runJob", "command": "githubLocalActions.runJob",
"when": "view == workflows && viewItem =~ /^githubLocalActions.job.*/", "when": "view == workflows && viewItem =~ /^githubLocalActions.job.*/",
"group": "inline@0" "group": "inline@0"
},
{
"command": "githubLocalActions.restart",
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/",
"group": "inline@0"
},
{
"command": "githubLocalActions.stop",
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/",
"group": "inline@1"
},
{
"command": "githubLocalActions.remove",
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/",
"group": "inline@2"
} }
] ]
}, },

View File

@@ -1,6 +1,6 @@
import * as child_process from 'child_process'; import * as child_process from 'child_process';
import * as path from "path"; import * as path from "path";
import { commands, CustomExecution, env, EventEmitter, Pseudoterminal, ShellExecution, TaskDefinition, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, window, workspace, WorkspaceFolder } from "vscode"; import { commands, CustomExecution, env, EventEmitter, Pseudoterminal, ShellExecution, TaskDefinition, TaskExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, window, workspace, WorkspaceFolder } from "vscode";
import { ComponentsManager } from "./componentsManager"; import { ComponentsManager } from "./componentsManager";
import { historyTreeDataProvider } from './extension'; import { historyTreeDataProvider } from './extension';
import { SettingsManager } from './settingsManager'; import { SettingsManager } from './settingsManager';
@@ -68,12 +68,22 @@ export interface RawLog {
jobResult?: string, //TODO: Could be an enum? jobResult?: string, //TODO: Could be an enum?
} }
export interface CommandArgs {
workspaceFolder: WorkspaceFolder,
options: string,
name: string,
typeText: string[]
}
export interface History { export interface History {
index: number,
name: string, name: string,
status: HistoryStatus, status: HistoryStatus,
start?: string, start?: string,
end?: string, end?: string,
output?: string output?: string,
taskExecution?: TaskExecution,
commandArgs: CommandArgs
} }
export enum HistoryStatus { export enum HistoryStatus {
@@ -157,7 +167,14 @@ export class Act {
async runWorkflow(workflow: Workflow) { async runWorkflow(workflow: Workflow) {
const workspaceFolder = workspace.getWorkspaceFolder(workflow.uri); const workspaceFolder = workspace.getWorkspaceFolder(workflow.uri);
if (workspaceFolder) { if (workspaceFolder) {
return await this.runCommand(workspaceFolder, `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, workflow.name, [`Workflow: ${workflow.name}`]); return await this.runCommand({
workspaceFolder: workspaceFolder,
options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`,
name: workflow.name,
typeText: [
`Workflow: ${workflow.name}`
]
});
} else { } else {
window.showErrorMessage(`Failed to locate workspace folder for ${workflow.uri.fsPath}`); window.showErrorMessage(`Failed to locate workspace folder for ${workflow.uri.fsPath}`);
} }
@@ -173,8 +190,8 @@ export class Act {
// return await this.runCommand(workspaceFolder, `${Option.Workflows} ${event}`, event, [`Event: ${event}`]); // return await this.runCommand(workspaceFolder, `${Option.Workflows} ${event}`, event, [`Event: ${event}`]);
// } // }
async runCommand(workspaceFolder: WorkspaceFolder, options: string, name: string, typeText: string[]) { async runCommand(commandArgs: CommandArgs) {
const command = `${Act.base} ${Option.Json} ${options}`; const command = `${Act.base} ${Option.Json} ${commandArgs.options}`;
const unreadyComponents = await this.componentsManager.getUnreadyComponents(); const unreadyComponents = await this.componentsManager.getUnreadyComponents();
if (unreadyComponents.length > 0) { if (unreadyComponents.length > 0) {
@@ -186,24 +203,26 @@ export class Act {
return; return;
} }
if (!this.workspaceHistory[workspaceFolder.uri.fsPath]) { if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath]) {
this.workspaceHistory[workspaceFolder.uri.fsPath] = []; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath] = [];
} }
const historyIndex = this.workspaceHistory[workspaceFolder.uri.fsPath].length; const historyIndex = this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath].length;
this.workspaceHistory[workspaceFolder.uri.fsPath].push({ this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath].push({
name: `${name} #${this.workspaceHistory[workspaceFolder.uri.fsPath].length + 1}`, index: historyIndex,
name: `${commandArgs.name} #${this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath].length + 1}`,
status: HistoryStatus.Running, status: HistoryStatus.Running,
start: new Date().toISOString() start: new Date().toISOString(),
commandArgs: commandArgs
}); });
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
await tasks.executeTask({ this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].taskExecution = await tasks.executeTask({
name: name, name: commandArgs.name,
detail: 'Run workflow', detail: 'Run workflow',
definition: { type: 'GitHub Local Actions' }, definition: { type: 'GitHub Local Actions' },
source: 'GitHub Local Actions', source: 'GitHub Local Actions',
scope: workspaceFolder || TaskScope.Workspace, scope: commandArgs.workspaceFolder || TaskScope.Workspace,
isBackground: true, isBackground: true,
presentationOptions: { presentationOptions: {
reveal: TaskRevealKind.Always, reveal: TaskRevealKind.Always,
@@ -221,25 +240,25 @@ export class Act {
const writeEmitter = new EventEmitter<string>(); const writeEmitter = new EventEmitter<string>();
const closeEmitter = new EventEmitter<number>(); const closeEmitter = new EventEmitter<number>();
const exec = child_process.spawn(command, { cwd: workspaceFolder.uri.fsPath, shell: env.shell }); const exec = child_process.spawn(command, { cwd: commandArgs.workspaceFolder.uri.fsPath, shell: env.shell });
const handleIO = (data: any) => { const handleIO = (data: any) => {
const lines: string[] = data.toString().split('\n').filter((line: string) => line != ''); const lines: string[] = data.toString().split('\n').filter((line: string) => line != '');
for (const line of lines) { for (const line of lines) {
const jsonLine = JSON.parse(line); const jsonLine = JSON.parse(line);
if (!this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].start) { if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].start) {
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].start = jsonLine.time; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].start = jsonLine.time;
} }
if (jsonLine.jobResult) { if (jsonLine.jobResult) {
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].end = jsonLine.time; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end = jsonLine.time;
switch (jsonLine.jobResult) { switch (jsonLine.jobResult) {
case 'success': case 'success':
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Success; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Success;
break; break;
case 'failure': case 'failure':
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed;
break; break;
// TODO: Handle cancelled // TODO: Handle cancelled
} }
@@ -252,12 +271,12 @@ export class Act {
exec.stdout.on('data', handleIO); exec.stdout.on('data', handleIO);
exec.stderr.on('data', handleIO); exec.stderr.on('data', handleIO);
exec.on('close', (code) => { exec.on('close', (code) => {
if (!this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].end) { if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end) {
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].end = new Date().toISOString(); this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end = new Date().toISOString();
} }
if (this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) { if (this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) {
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed;
} }
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
@@ -268,9 +287,9 @@ export class Act {
onDidWrite: writeEmitter.event, onDidWrite: writeEmitter.event,
onDidClose: closeEmitter.event, onDidClose: closeEmitter.event,
open: async (initialDimensions: TerminalDimensions | undefined): Promise<void> => { open: async (initialDimensions: TerminalDimensions | undefined): Promise<void> => {
writeEmitter.fire(`Name: ${name}\r\n`); writeEmitter.fire(`Name: ${commandArgs.name}\r\n`);
writeEmitter.fire(`Path: ${workspaceFolder.uri.fsPath}\r\n`); writeEmitter.fire(`Path: ${commandArgs.workspaceFolder.uri.fsPath}\r\n`);
for (const text of typeText) { for (const text of commandArgs.typeText) {
writeEmitter.fire(`${text}\r\n`); writeEmitter.fire(`${text}\r\n`);
} }
writeEmitter.fire(`Environments: OSSBUILD\r\n`); writeEmitter.fire(`Environments: OSSBUILD\r\n`);
@@ -282,8 +301,8 @@ export class Act {
}, },
close: () => { close: () => {
if (this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) { if (this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) {
this.workspaceHistory[workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Cancelled; this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Cancelled;
} }
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
@@ -323,4 +342,26 @@ export class Act {
}); });
} }
} }
async clearAll() {
//TODO: Fix for multi workspace support
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
for (const workspaceFolder of workspaceFolders) {
this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
historyTreeDataProvider.refresh();
}
}
}
async stop(history: History) {
history.taskExecution?.terminate();
historyTreeDataProvider.refresh();
}
async remove(history: History) {
const historyIndex = this.workspaceHistory[history.commandArgs.workspaceFolder.uri.fsPath].findIndex(workspaceHistory => workspaceHistory.index === history.index)
this.workspaceHistory[history.commandArgs.workspaceFolder.uri.fsPath].splice(historyIndex, 1);
historyTreeDataProvider.refresh();
}
} }

View File

@@ -55,8 +55,15 @@ export default class ComponentsTreeDataProvider implements TreeDataProvider<Gith
if (element) { if (element) {
return element.getChildren(); return element.getChildren();
} else { } else {
const items: GithubLocalActionsTreeItem[] = [];
const components = await act.componentsManager.getComponents(); const components = await act.componentsManager.getComponents();
return components.map(component => new ComponentTreeItem(component)); for (const component of components) {
items.push(new ComponentTreeItem(component));
}
await commands.executeCommand('setContext', 'githubLocalActions:noComponents', items.length == 0);
return items;
} }
} }
} }

View File

@@ -1,4 +1,5 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode"; import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode";
import { HistoryStatus } from "../../act";
import { act } from "../../extension"; import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import HistoryTreeItem from "./history"; import HistoryTreeItem from "./history";
@@ -14,8 +15,20 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
}); });
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.clearAll', async () => {
await act.clearAll();
}),
commands.registerCommand('githubLocalActions.refreshHistory', async () => { commands.registerCommand('githubLocalActions.refreshHistory', async () => {
this.refresh(); this.refresh();
}),
commands.registerCommand('githubLocalActions.restart', async (historyTreeItem: HistoryTreeItem) => {
await act.runCommand(historyTreeItem.history.commandArgs);
}),
commands.registerCommand('githubLocalActions.stop', async (historyTreeItem: HistoryTreeItem) => {
await act.stop(historyTreeItem.history);
}),
commands.registerCommand('githubLocalActions.remove', async (historyTreeItem: HistoryTreeItem) => {
await act.remove(historyTreeItem.history);
}) })
); );
} }
@@ -43,15 +56,22 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
const items: GithubLocalActionsTreeItem[] = []; const items: GithubLocalActionsTreeItem[] = [];
const workspaceFolders = workspace.workspaceFolders; const workspaceFolders = workspace.workspaceFolders;
let isRunning: boolean = false;
if (workspaceFolders && workspaceFolders.length > 0) { if (workspaceFolders && workspaceFolders.length > 0) {
const workspaceHistory = act.workspaceHistory[workspaceFolders[0].uri.fsPath]; //TODO: Fix for multi workspace support //TODO: Fix for multi workspace support
const workspaceHistory = act.workspaceHistory[workspaceFolders[0].uri.fsPath];
if (workspaceHistory) { if (workspaceHistory) {
for (const history of workspaceHistory) { for (const history of workspaceHistory) {
items.push(new HistoryTreeItem(history)); items.push(new HistoryTreeItem(history));
if (history.status === HistoryStatus.Running) {
isRunning = true;
}
} }
} }
} }
await commands.executeCommand('setContext', 'githubLocalActions:isRunning', isRunning);
await commands.executeCommand('setContext', 'githubLocalActions:noHistory', items.length == 0); await commands.executeCommand('setContext', 'githubLocalActions:noHistory', items.length == 0);
return items; return items;
} }