Add multi-workspace support

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-19 21:44:36 -04:00
parent 49e934e297
commit 524a724279
8 changed files with 141 additions and 79 deletions

View File

@@ -366,12 +366,12 @@
}, },
{ {
"command": "githubLocalActions.runAllWorkflows", "command": "githubLocalActions.runAllWorkflows",
"when": "view == workflows", "when": "view == workflows && workspaceFolderCount <= 1",
"group": "navigation@0" "group": "navigation@0"
}, },
{ {
"command": "githubLocalActions.runEvent", "command": "githubLocalActions.runEvent",
"when": "view == workflows", "when": "view == workflows && workspaceFolderCount <= 1",
"group": "navigation@1" "group": "navigation@1"
}, },
{ {
@@ -381,7 +381,7 @@
}, },
{ {
"command": "githubLocalActions.clearAll", "command": "githubLocalActions.clearAll",
"when": "view == history", "when": "view == history && workspaceFolderCount <= 1",
"group": "navigation@0" "group": "navigation@0"
}, },
{ {
@@ -411,6 +411,16 @@
"when": "view == components && viewItem =~ /^githubLocalActions.component_Not Running.*/", "when": "view == components && viewItem =~ /^githubLocalActions.component_Not Running.*/",
"group": "inline@1" "group": "inline@1"
}, },
{
"command": "githubLocalActions.runAllWorkflows",
"when": "view == workflows && viewItem =~ /^githubLocalActions.workspaceFolderWorkflows.*/ && workspaceFolderCount > 1",
"group": "inline@0"
},
{
"command": "githubLocalActions.runEvent",
"when": "view == workflows && viewItem =~ /^githubLocalActions.workspaceFolderWorkflows.*/ && workspaceFolderCount > 1",
"group": "inline@1"
},
{ {
"command": "githubLocalActions.openWorkflow", "command": "githubLocalActions.openWorkflow",
"when": "view == workflows && viewItem =~ /^githubLocalActions.workflow.*/", "when": "view == workflows && viewItem =~ /^githubLocalActions.workflow.*/",
@@ -426,6 +436,11 @@
"when": "view == workflows && viewItem =~ /^githubLocalActions.job.*/", "when": "view == workflows && viewItem =~ /^githubLocalActions.job.*/",
"group": "inline@0" "group": "inline@0"
}, },
{
"command": "githubLocalActions.clearAll",
"when": "view == history && viewItem =~ /^githubLocalActions.workspaceFolderHistory.*/ && workspaceFolderCount > 1",
"group": "inline@0"
},
{ {
"command": "githubLocalActions.viewOutput", "command": "githubLocalActions.viewOutput",
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "when": "view == history && viewItem =~ /^githubLocalActions.history.*/",

View File

@@ -1,12 +1,12 @@
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, ExtensionContext, Pseudoterminal, ShellExecution, TaskDefinition, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, window, workspace, WorkspaceFolder } from "vscode"; import { commands, CustomExecution, env, EventEmitter, ExtensionContext, Pseudoterminal, ShellExecution, TaskDefinition, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, window, WorkspaceFolder } from "vscode";
import { ComponentsManager } from "./componentsManager"; import { ComponentsManager } from "./componentsManager";
import { historyTreeDataProvider } from './extension'; import { historyTreeDataProvider } from './extension';
import { HistoryManager, HistoryStatus } from './historyManager'; import { HistoryManager, HistoryStatus } from './historyManager';
import { SettingsManager } from './settingsManager'; import { SettingsManager } from './settingsManager';
import { StorageKey, StorageManager } from './storageManager'; import { StorageKey, StorageManager } from './storageManager';
import { Workflow, WorkflowsManager } from "./workflowsManager"; import { Job, Workflow, WorkflowsManager } from "./workflowsManager";
export enum Event { export enum Event {
BranchProtectionRule = 'branch_protection_rule', BranchProtectionRule = 'branch_protection_rule',
@@ -127,13 +127,16 @@ export class Act {
} }
} }
async runAllWorkflows() { async runAllWorkflows(workspaceFolder: WorkspaceFolder) {
// TODO: Implement return await this.runCommand({
workspaceFolder: workspaceFolder,
options: ``,
name: workspaceFolder.name,
typeText: []
});
} }
async runWorkflow(workflow: Workflow) { async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) {
const workspaceFolder = workspace.getWorkspaceFolder(workflow.uri);
if (workspaceFolder) {
return await this.runCommand({ return await this.runCommand({
workspaceFolder: workspaceFolder, workspaceFolder: workspaceFolder,
options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`,
@@ -142,20 +145,30 @@ export class Act {
`Workflow: ${workflow.name}` `Workflow: ${workflow.name}`
] ]
}); });
} else {
window.showErrorMessage(`Failed to locate workspace folder for ${workflow.uri.fsPath}`);
}
} }
// TODO: Implement async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
// async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) { return await this.runCommand({
// return await this.runCommand(workspaceFolder, `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}" ${Option.Job} "${job.id}"`, `${workflow.name}/${job.name}`, [`Workflow: ${workflow.name}`, `Job: ${job.name}`]); workspaceFolder: workspaceFolder,
// } options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}" ${Option.Job} "${job.id}"`,
name: `${workflow.name}/${job.name}`,
typeText: [
`Workflow: ${workflow.name}`,
`Job: ${job.name}`
]
});
}
// TODO: Implement async runEvent(workspaceFolder: WorkspaceFolder, event: Event) {
// async runEvent(workspaceFolder: WorkspaceFolder, event: Event) { return await this.runCommand({
// return await this.runCommand(workspaceFolder, `${Option.Workflows} ${event}`, event, [`Event: ${event}`]); workspaceFolder: workspaceFolder,
// } options: event,
name: event,
typeText: [
`Event: ${event}`
]
});
}
async runCommand(commandArgs: CommandArgs) { async runCommand(commandArgs: CommandArgs) {
const command = `${Act.base} ${Option.Json} ${commandArgs.options}`; const command = `${Act.base} ${Option.Json} ${commandArgs.options}`;
@@ -289,7 +302,7 @@ export class Act {
writeEmitter.fire(`Environments: OSSBUILD\r\n`); writeEmitter.fire(`Environments: OSSBUILD\r\n`);
writeEmitter.fire(`Variables: VARIABLE1=ABC, VARIABLE2=DEF\r\n`); writeEmitter.fire(`Variables: VARIABLE1=ABC, VARIABLE2=DEF\r\n`);
writeEmitter.fire(`Secrets: SECRET1=ABC, SECRET2=DEF\r\n`); writeEmitter.fire(`Secrets: SECRET1=ABC, SECRET2=DEF\r\n`);
writeEmitter.fire(`Command: ${command}\r\n`); writeEmitter.fire(`Command: ${command.replace(` ${Option.Json}`, ``)}\r\n`);
writeEmitter.fire(`\r\n`); writeEmitter.fire(`\r\n`);
}, },

View File

@@ -1,4 +1,4 @@
import { TaskExecution, window, workspace } from "vscode"; import { TaskExecution, window, workspace, WorkspaceFolder } from "vscode";
import { CommandArgs } from "./act"; import { CommandArgs } from "./act";
import { act, historyTreeDataProvider } from "./extension"; import { act, historyTreeDataProvider } from "./extension";
import { StorageKey, StorageManager } from "./storageManager"; import { StorageKey, StorageManager } from "./storageManager";
@@ -42,17 +42,11 @@ export class HistoryManager {
this.workspaceHistory = workspaceHistory; this.workspaceHistory = workspaceHistory;
} }
async clearAll() { async clearAll(workspaceFolder: WorkspaceFolder) {
//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] = []; this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
} }
}
}
async viewOutput(history: History) { async viewOutput(history: History) {
await workspace.openTextDocument({ content: history.output }).then(async document => { await workspace.openTextDocument({ content: history.output }).then(async document => {

View File

@@ -1,4 +1,6 @@
export namespace DateUtils { import { window, workspace, WorkspaceFolder } from "vscode";
export namespace Utils {
/** /**
* Get date time string. * Get date time string.
* *
@@ -37,4 +39,21 @@ export namespace DateUtils {
const seconds = totalSeconds % 60; const seconds = totalSeconds % 60;
return `${minutes}m ${seconds}s`; return `${minutes}m ${seconds}s`;
} }
/**
* Get the provided workspace folder or the first one if there are multiple.
*/
export async function getWorkspaceFolder(workspaceFolder?: WorkspaceFolder) {
if (workspaceFolder) {
return workspaceFolder;
} else {
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
return workspaceFolders[0];
} else {
await window.showErrorMessage('Failed to find a workspace folder');
return;
}
}
}
} }

View File

@@ -1,6 +1,6 @@
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { DateUtils } from "../../dateUtils";
import { History, HistoryStatus } from "../../historyManager"; import { History, HistoryStatus } from "../../historyManager";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem { export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
@@ -13,7 +13,7 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
let totalDuration: string | undefined; let totalDuration: string | undefined;
if (history.date) { if (history.date) {
totalDuration = DateUtils.getTimeDuration(history.date.start, history.date.end); totalDuration = Utils.getTimeDuration(history.date.start, history.date.end);
} }
this.description = totalDuration; this.description = totalDuration;
@@ -34,8 +34,8 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
} }
this.tooltip = `Name: ${history.name}\n` + this.tooltip = `Name: ${history.name}\n` +
`Status: ${history.status}\n` + `Status: ${history.status}\n` +
`Started: ${history.date ? DateUtils.getDateString(history.date.start) : 'N/A'}\n` + `Started: ${history.date ? Utils.getDateString(history.date.start) : 'N/A'}\n` +
`Ended: ${history.date ? DateUtils.getDateString(history.date.end) : 'N/A'}\n` + `Ended: ${history.date ? Utils.getDateString(history.date.end) : 'N/A'}\n` +
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``); (totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
} }

View File

@@ -1,6 +1,7 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode"; import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode";
import { act } from "../../extension"; import { act } from "../../extension";
import { HistoryStatus } from "../../historyManager"; import { HistoryStatus } from "../../historyManager";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import HistoryTreeItem from "./history"; import HistoryTreeItem from "./history";
import WorkspaceFolderHistoryTreeItem from "./workspaceFolderHistory"; import WorkspaceFolderHistoryTreeItem from "./workspaceFolderHistory";
@@ -16,8 +17,11 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
}); });
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.clearAll', async () => { commands.registerCommand('githubLocalActions.clearAll', async (workspaceFolderHistoryTreeItem?: WorkspaceFolderHistoryTreeItem) => {
await act.historyManager.clearAll(); const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderHistoryTreeItem?.workspaceFolder);
if (workspaceFolder) {
await act.historyManager.clearAll(workspaceFolder);
}
}), }),
commands.registerCommand('githubLocalActions.refreshHistory', async () => { commands.registerCommand('githubLocalActions.refreshHistory', async () => {
this.refresh(); this.refresh();
@@ -65,6 +69,9 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
const workspaceFolders = workspace.workspaceFolders; const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) { if (workspaceFolders) {
if (workspaceFolders.length === 1) {
return await new WorkspaceFolderHistoryTreeItem(workspaceFolders[0]).getChildren();
} else if (workspaceFolders.length > 1) {
for (const workspaceFolder of workspaceFolders) { for (const workspaceFolder of workspaceFolders) {
items.push(new WorkspaceFolderHistoryTreeItem(workspaceFolder)); items.push(new WorkspaceFolderHistoryTreeItem(workspaceFolder));
@@ -75,6 +82,7 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
} }
} }
} }
}
await commands.executeCommand('setContext', 'githubLocalActions:isRunning', isRunning); await commands.executeCommand('setContext', 'githubLocalActions:isRunning', isRunning);
await commands.executeCommand('setContext', 'githubLocalActions:noHistory', noHistory); await commands.executeCommand('setContext', 'githubLocalActions:noHistory', noHistory);

View File

@@ -61,6 +61,9 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
const workspaceFolders = workspace.workspaceFolders; const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) { if (workspaceFolders) {
if (workspaceFolders.length === 1) {
return await new WorkspaceFolderSettingsTreeItem(workspaceFolders[0]).getChildren();
} else if (workspaceFolders.length > 1) {
for (const workspaceFolder of workspaceFolders) { for (const workspaceFolder of workspaceFolders) {
items.push(new WorkspaceFolderSettingsTreeItem(workspaceFolder)); items.push(new WorkspaceFolderSettingsTreeItem(workspaceFolder));
@@ -70,6 +73,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
} }
} }
} }
}
await commands.executeCommand('setContext', 'githubLocalActions:noSettings', noSettings); await commands.executeCommand('setContext', 'githubLocalActions:noSettings', noSettings);
return items; return items;

View File

@@ -1,7 +1,9 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode"; import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode";
import { Event } from "../../act"; import { Event } from "../../act";
import { act } from "../../extension"; import { act } from "../../extension";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import JobTreeItem from "./job";
import WorkflowTreeItem from "./workflow"; import WorkflowTreeItem from "./workflow";
import WorkspaceFolderWorkflowsTreeItem from "./workspaceFolderWorkflows"; import WorkspaceFolderWorkflowsTreeItem from "./workspaceFolderWorkflows";
@@ -12,18 +14,23 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
constructor(context: ExtensionContext) { constructor(context: ExtensionContext) {
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.runAllWorkflows', async () => { commands.registerCommand('githubLocalActions.runAllWorkflows', async (workspaceFolderWorkflowsTreeItem?: WorkspaceFolderWorkflowsTreeItem) => {
await act.runAllWorkflows(); const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderWorkflowsTreeItem?.workspaceFolder);
if (workspaceFolder) {
await act.runAllWorkflows(workspaceFolder);
}
}), }),
commands.registerCommand('githubLocalActions.runEvent', async () => { commands.registerCommand('githubLocalActions.runEvent', async (workspaceFolderWorkflowsTreeItem?: WorkspaceFolderWorkflowsTreeItem) => {
const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderWorkflowsTreeItem?.workspaceFolder);
if (workspaceFolder) {
const event = await window.showQuickPick(Object.values(Event), { const event = await window.showQuickPick(Object.values(Event), {
title: 'Select the event to run', title: 'Select the event to run',
placeHolder: 'Event' placeHolder: 'Event'
}); });
if (event) { if (event) {
// TODO: Implement running event await act.runEvent(workspaceFolder, event as Event);
// await act.runEvent(event as Event); }
} }
}), }),
commands.registerCommand('githubLocalActions.refreshWorkflows', async () => { commands.registerCommand('githubLocalActions.refreshWorkflows', async () => {
@@ -34,11 +41,10 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
await window.showTextDocument(document); await window.showTextDocument(document);
}), }),
commands.registerCommand('githubLocalActions.runWorkflow', async (workflowTreeItem: WorkflowTreeItem) => { commands.registerCommand('githubLocalActions.runWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
await act.runWorkflow(workflowTreeItem.workflow); await act.runWorkflow(workflowTreeItem.workspaceFolder, workflowTreeItem.workflow);
}), }),
commands.registerCommand('githubLocalActions.runJob', async (workflowTreeItem: WorkflowTreeItem) => { commands.registerCommand('githubLocalActions.runJob', async (jobTreeItem: JobTreeItem) => {
// TODO: Implement running job await act.runJob(jobTreeItem.workspaceFolder, jobTreeItem.workflow, jobTreeItem.job);
// await act.runJob()
}) })
); );
} }
@@ -68,6 +74,9 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
const workspaceFolders = workspace.workspaceFolders; const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) { if (workspaceFolders) {
if (workspaceFolders.length === 1) {
return await new WorkspaceFolderWorkflowsTreeItem(workspaceFolders[0]).getChildren();
} else if (workspaceFolders.length > 1) {
for (const workspaceFolder of workspaceFolders) { for (const workspaceFolder of workspaceFolders) {
items.push(new WorkspaceFolderWorkflowsTreeItem(workspaceFolder)); items.push(new WorkspaceFolderWorkflowsTreeItem(workspaceFolder));
@@ -76,7 +85,7 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
noWorkflows = false; noWorkflows = false;
} }
} }
}
} }
await commands.executeCommand('setContext', 'githubLocalActions:noWorkflows', noWorkflows); await commands.executeCommand('setContext', 'githubLocalActions:noWorkflows', noWorkflows);