Add multi-workspace support
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
21
package.json
21
package.json
@@ -366,12 +366,12 @@
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.runAllWorkflows",
|
||||
"when": "view == workflows",
|
||||
"when": "view == workflows && workspaceFolderCount <= 1",
|
||||
"group": "navigation@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.runEvent",
|
||||
"when": "view == workflows",
|
||||
"when": "view == workflows && workspaceFolderCount <= 1",
|
||||
"group": "navigation@1"
|
||||
},
|
||||
{
|
||||
@@ -381,7 +381,7 @@
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.clearAll",
|
||||
"when": "view == history",
|
||||
"when": "view == history && workspaceFolderCount <= 1",
|
||||
"group": "navigation@0"
|
||||
},
|
||||
{
|
||||
@@ -411,6 +411,16 @@
|
||||
"when": "view == components && viewItem =~ /^githubLocalActions.component_Not Running.*/",
|
||||
"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",
|
||||
"when": "view == workflows && viewItem =~ /^githubLocalActions.workflow.*/",
|
||||
@@ -426,6 +436,11 @@
|
||||
"when": "view == workflows && viewItem =~ /^githubLocalActions.job.*/",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.clearAll",
|
||||
"when": "view == history && viewItem =~ /^githubLocalActions.workspaceFolderHistory.*/ && workspaceFolderCount > 1",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.viewOutput",
|
||||
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/",
|
||||
|
||||
67
src/act.ts
67
src/act.ts
@@ -1,12 +1,12 @@
|
||||
import * as child_process from 'child_process';
|
||||
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 { historyTreeDataProvider } from './extension';
|
||||
import { HistoryManager, HistoryStatus } from './historyManager';
|
||||
import { SettingsManager } from './settingsManager';
|
||||
import { StorageKey, StorageManager } from './storageManager';
|
||||
import { Workflow, WorkflowsManager } from "./workflowsManager";
|
||||
import { Job, Workflow, WorkflowsManager } from "./workflowsManager";
|
||||
|
||||
export enum Event {
|
||||
BranchProtectionRule = 'branch_protection_rule',
|
||||
@@ -127,35 +127,48 @@ export class Act {
|
||||
}
|
||||
}
|
||||
|
||||
async runAllWorkflows() {
|
||||
// TODO: Implement
|
||||
async runAllWorkflows(workspaceFolder: WorkspaceFolder) {
|
||||
return await this.runCommand({
|
||||
workspaceFolder: workspaceFolder,
|
||||
options: ``,
|
||||
name: workspaceFolder.name,
|
||||
typeText: []
|
||||
});
|
||||
}
|
||||
|
||||
async runWorkflow(workflow: Workflow) {
|
||||
const workspaceFolder = workspace.getWorkspaceFolder(workflow.uri);
|
||||
if (workspaceFolder) {
|
||||
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 {
|
||||
window.showErrorMessage(`Failed to locate workspace folder for ${workflow.uri.fsPath}`);
|
||||
}
|
||||
async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) {
|
||||
return await this.runCommand({
|
||||
workspaceFolder: workspaceFolder,
|
||||
options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`,
|
||||
name: workflow.name,
|
||||
typeText: [
|
||||
`Workflow: ${workflow.name}`
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
// async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
|
||||
// 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}`]);
|
||||
// }
|
||||
async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
|
||||
return await this.runCommand({
|
||||
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) {
|
||||
// return await this.runCommand(workspaceFolder, `${Option.Workflows} ${event}`, event, [`Event: ${event}`]);
|
||||
// }
|
||||
async runEvent(workspaceFolder: WorkspaceFolder, event: Event) {
|
||||
return await this.runCommand({
|
||||
workspaceFolder: workspaceFolder,
|
||||
options: event,
|
||||
name: event,
|
||||
typeText: [
|
||||
`Event: ${event}`
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async runCommand(commandArgs: CommandArgs) {
|
||||
const command = `${Act.base} ${Option.Json} ${commandArgs.options}`;
|
||||
@@ -289,7 +302,7 @@ export class Act {
|
||||
writeEmitter.fire(`Environments: OSSBUILD\r\n`);
|
||||
writeEmitter.fire(`Variables: VARIABLE1=ABC, VARIABLE2=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`);
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TaskExecution, window, workspace } from "vscode";
|
||||
import { TaskExecution, window, workspace, WorkspaceFolder } from "vscode";
|
||||
import { CommandArgs } from "./act";
|
||||
import { act, historyTreeDataProvider } from "./extension";
|
||||
import { StorageKey, StorageManager } from "./storageManager";
|
||||
@@ -42,16 +42,10 @@ export class HistoryManager {
|
||||
this.workspaceHistory = workspaceHistory;
|
||||
}
|
||||
|
||||
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();
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
|
||||
}
|
||||
}
|
||||
async clearAll(workspaceFolder: WorkspaceFolder) {
|
||||
this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
|
||||
historyTreeDataProvider.refresh();
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
|
||||
}
|
||||
|
||||
async viewOutput(history: History) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
export namespace DateUtils {
|
||||
import { window, workspace, WorkspaceFolder } from "vscode";
|
||||
|
||||
export namespace Utils {
|
||||
/**
|
||||
* Get date time string.
|
||||
*
|
||||
@@ -37,4 +39,21 @@ export namespace DateUtils {
|
||||
const seconds = totalSeconds % 60;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
|
||||
import { DateUtils } from "../../dateUtils";
|
||||
import { History, HistoryStatus } from "../../historyManager";
|
||||
import { Utils } from "../../utils";
|
||||
import { GithubLocalActionsTreeItem } from "../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;
|
||||
if (history.date) {
|
||||
totalDuration = DateUtils.getTimeDuration(history.date.start, history.date.end);
|
||||
totalDuration = Utils.getTimeDuration(history.date.start, history.date.end);
|
||||
}
|
||||
|
||||
this.description = totalDuration;
|
||||
@@ -34,8 +34,8 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
|
||||
}
|
||||
this.tooltip = `Name: ${history.name}\n` +
|
||||
`Status: ${history.status}\n` +
|
||||
`Started: ${history.date ? DateUtils.getDateString(history.date.start) : 'N/A'}\n` +
|
||||
`Ended: ${history.date ? DateUtils.getDateString(history.date.end) : 'N/A'}\n` +
|
||||
`Started: ${history.date ? Utils.getDateString(history.date.start) : 'N/A'}\n` +
|
||||
`Ended: ${history.date ? Utils.getDateString(history.date.end) : 'N/A'}\n` +
|
||||
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode";
|
||||
import { act } from "../../extension";
|
||||
import { HistoryStatus } from "../../historyManager";
|
||||
import { Utils } from "../../utils";
|
||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||
import HistoryTreeItem from "./history";
|
||||
import WorkspaceFolderHistoryTreeItem from "./workspaceFolderHistory";
|
||||
@@ -16,8 +17,11 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
|
||||
});
|
||||
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('githubLocalActions.clearAll', async () => {
|
||||
await act.historyManager.clearAll();
|
||||
commands.registerCommand('githubLocalActions.clearAll', async (workspaceFolderHistoryTreeItem?: WorkspaceFolderHistoryTreeItem) => {
|
||||
const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderHistoryTreeItem?.workspaceFolder);
|
||||
if (workspaceFolder) {
|
||||
await act.historyManager.clearAll(workspaceFolder);
|
||||
}
|
||||
}),
|
||||
commands.registerCommand('githubLocalActions.refreshHistory', async () => {
|
||||
this.refresh();
|
||||
@@ -65,13 +69,17 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
|
||||
|
||||
const workspaceFolders = workspace.workspaceFolders;
|
||||
if (workspaceFolders) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderHistoryTreeItem(workspaceFolder));
|
||||
if (workspaceFolders.length === 1) {
|
||||
return await new WorkspaceFolderHistoryTreeItem(workspaceFolders[0]).getChildren();
|
||||
} else if (workspaceFolders.length > 1) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderHistoryTreeItem(workspaceFolder));
|
||||
|
||||
const workspaceHistory = act.historyManager.workspaceHistory[workspaceFolders[0].uri.fsPath];
|
||||
if (workspaceHistory.length > 0) {
|
||||
isRunning = act.historyManager.workspaceHistory[workspaceFolders[0].uri.fsPath].find(workspaceHistory => workspaceHistory.status === HistoryStatus.Running) !== undefined;
|
||||
noHistory = false;
|
||||
const workspaceHistory = act.historyManager.workspaceHistory[workspaceFolders[0].uri.fsPath];
|
||||
if (workspaceHistory.length > 0) {
|
||||
isRunning = act.historyManager.workspaceHistory[workspaceFolders[0].uri.fsPath].find(workspaceHistory => workspaceHistory.status === HistoryStatus.Running) !== undefined;
|
||||
noHistory = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,12 +61,16 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
||||
|
||||
const workspaceFolders = workspace.workspaceFolders;
|
||||
if (workspaceFolders) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderSettingsTreeItem(workspaceFolder));
|
||||
if (workspaceFolders.length === 1) {
|
||||
return await new WorkspaceFolderSettingsTreeItem(workspaceFolders[0]).getChildren();
|
||||
} else if (workspaceFolders.length > 1) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderSettingsTreeItem(workspaceFolder));
|
||||
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
if (workflows.length > 0) {
|
||||
noSettings = false;
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
if (workflows.length > 0) {
|
||||
noSettings = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode";
|
||||
import { Event } from "../../act";
|
||||
import { act } from "../../extension";
|
||||
import { Utils } from "../../utils";
|
||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||
import JobTreeItem from "./job";
|
||||
import WorkflowTreeItem from "./workflow";
|
||||
import WorkspaceFolderWorkflowsTreeItem from "./workspaceFolderWorkflows";
|
||||
|
||||
@@ -12,18 +14,23 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
||||
|
||||
constructor(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('githubLocalActions.runAllWorkflows', async () => {
|
||||
await act.runAllWorkflows();
|
||||
commands.registerCommand('githubLocalActions.runAllWorkflows', async (workspaceFolderWorkflowsTreeItem?: WorkspaceFolderWorkflowsTreeItem) => {
|
||||
const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderWorkflowsTreeItem?.workspaceFolder);
|
||||
if (workspaceFolder) {
|
||||
await act.runAllWorkflows(workspaceFolder);
|
||||
}
|
||||
}),
|
||||
commands.registerCommand('githubLocalActions.runEvent', async () => {
|
||||
const event = await window.showQuickPick(Object.values(Event), {
|
||||
title: 'Select the event to run',
|
||||
placeHolder: 'Event'
|
||||
});
|
||||
commands.registerCommand('githubLocalActions.runEvent', async (workspaceFolderWorkflowsTreeItem?: WorkspaceFolderWorkflowsTreeItem) => {
|
||||
const workspaceFolder = await Utils.getWorkspaceFolder(workspaceFolderWorkflowsTreeItem?.workspaceFolder);
|
||||
if (workspaceFolder) {
|
||||
const event = await window.showQuickPick(Object.values(Event), {
|
||||
title: 'Select the event to run',
|
||||
placeHolder: 'Event'
|
||||
});
|
||||
|
||||
if (event) {
|
||||
// TODO: Implement running event
|
||||
// await act.runEvent(event as Event);
|
||||
if (event) {
|
||||
await act.runEvent(workspaceFolder, event as Event);
|
||||
}
|
||||
}
|
||||
}),
|
||||
commands.registerCommand('githubLocalActions.refreshWorkflows', async () => {
|
||||
@@ -34,11 +41,10 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
||||
await window.showTextDocument(document);
|
||||
}),
|
||||
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) => {
|
||||
// TODO: Implement running job
|
||||
// await act.runJob()
|
||||
commands.registerCommand('githubLocalActions.runJob', async (jobTreeItem: JobTreeItem) => {
|
||||
await act.runJob(jobTreeItem.workspaceFolder, jobTreeItem.workflow, jobTreeItem.job);
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -68,15 +74,18 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
||||
|
||||
const workspaceFolders = workspace.workspaceFolders;
|
||||
if (workspaceFolders) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderWorkflowsTreeItem(workspaceFolder));
|
||||
if (workspaceFolders.length === 1) {
|
||||
return await new WorkspaceFolderWorkflowsTreeItem(workspaceFolders[0]).getChildren();
|
||||
} else if (workspaceFolders.length > 1) {
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
items.push(new WorkspaceFolderWorkflowsTreeItem(workspaceFolder));
|
||||
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
if (workflows.length > 0) {
|
||||
noWorkflows = false;
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
if (workflows.length > 0) {
|
||||
noWorkflows = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await commands.executeCommand('setContext', 'githubLocalActions:noWorkflows', noWorkflows);
|
||||
|
||||
Reference in New Issue
Block a user