Refactor to use workspace folders

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-19 20:20:48 -04:00
parent f4a73316f4
commit 49e934e297
26 changed files with 515 additions and 206 deletions

View File

@@ -1,6 +1,8 @@
import { MarkdownString, TreeItem } from "vscode";
import { MarkdownString, TreeItem, WorkspaceFolder } from "vscode";
export interface GithubLocalActionsTreeItem extends TreeItem {
workspaceFolder?: WorkspaceFolder;
getChildren: () => GithubLocalActionsTreeItem[] | Promise<GithubLocalActionsTreeItem[]>;
getToolTip?: () => Promise<MarkdownString | string | undefined>;

View File

@@ -1,13 +1,13 @@
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { History, HistoryStatus } from "../../act";
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { DateUtils } from "../../dateUtils";
import { History, HistoryStatus } from "../../historyManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.history';
history: History;
constructor(history: History) {
constructor(public workspaceFolder: WorkspaceFolder, history: History) {
super(history.name, TreeItemCollapsibleState.None);
this.history = history;

View File

@@ -1,8 +1,9 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, extensions, TreeDataProvider, TreeItem, workspace } from "vscode";
import { HistoryStatus } from "../../act";
import { act } from "../../extension";
import { HistoryStatus } from "../../historyManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import HistoryTreeItem from "./history";
import WorkspaceFolderHistoryTreeItem from "./workspaceFolderHistory";
export default class HistoryTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> {
private _onDidChangeTreeData = new EventEmitter<GithubLocalActionsTreeItem | undefined | null | void>();
@@ -16,22 +17,24 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
context.subscriptions.push(
commands.registerCommand('githubLocalActions.clearAll', async () => {
await act.clearAll();
await act.historyManager.clearAll();
}),
commands.registerCommand('githubLocalActions.refreshHistory', async () => {
this.refresh();
}),
commands.registerCommand('githubLocalActions.viewOutput', async (historyTreeItem: HistoryTreeItem) => {
await act.viewOutput(historyTreeItem.history);
await act.historyManager.viewOutput(historyTreeItem.history);
}),
commands.registerCommand('githubLocalActions.restart', async (historyTreeItem: HistoryTreeItem) => {
await act.runCommand(historyTreeItem.history.commandArgs);
await act.historyManager.restart(historyTreeItem.history);
}),
commands.registerCommand('githubLocalActions.stop', async (historyTreeItem: HistoryTreeItem) => {
await act.stop(historyTreeItem.history);
await act.historyManager.stop(historyTreeItem.history);
this.refresh();
}),
commands.registerCommand('githubLocalActions.remove', async (historyTreeItem: HistoryTreeItem) => {
await act.remove(historyTreeItem.history);
await act.historyManager.remove(historyTreeItem.history);
this.refresh();
})
);
}
@@ -57,25 +60,24 @@ export default class HistoryTreeDataProvider implements TreeDataProvider<GithubL
return element.getChildren();
} else {
const items: GithubLocalActionsTreeItem[] = [];
let isRunning: boolean = false;
let noHistory: boolean = true;
const workspaceFolders = workspace.workspaceFolders;
let isRunning: boolean = false;
if (workspaceFolders && workspaceFolders.length > 0) {
//TODO: Fix for multi workspace support
const workspaceHistory = act.workspaceHistory[workspaceFolders[0].uri.fsPath];
if (workspaceHistory) {
for (const history of workspaceHistory) {
items.push(new HistoryTreeItem(history));
if (workspaceFolders) {
for (const workspaceFolder of workspaceFolders) {
items.push(new WorkspaceFolderHistoryTreeItem(workspaceFolder));
if (history.status === HistoryStatus.Running) {
isRunning = true;
}
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;
}
}
}
await commands.executeCommand('setContext', 'githubLocalActions:isRunning', isRunning);
await commands.executeCommand('setContext', 'githubLocalActions:noHistory', items.length == 0);
await commands.executeCommand('setContext', 'githubLocalActions:noHistory', noHistory);
return items;
}
}

View File

@@ -0,0 +1,26 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import HistoryTreeItem from "./history";
export default class WorkspaceFolderHistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.workspaceFolderHistory';
constructor(public workspaceFolder: WorkspaceFolder) {
super(workspaceFolder.name, TreeItemCollapsibleState.Collapsed);
this.contextValue = WorkspaceFolderHistoryTreeItem.contextValue;
this.iconPath = new ThemeIcon('folder');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const items: GithubLocalActionsTreeItem[] = [];
const workspaceHistory = act.historyManager.workspaceHistory[this.workspaceFolder.uri.fsPath];
if (workspaceHistory) {
for (const history of workspaceHistory.slice().reverse()) {
items.push(new HistoryTreeItem(this.workspaceFolder, history));
}
}
return items;
}
}

View File

@@ -0,0 +1,18 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { ContainerEngine } from "../../settingsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class ContainerEngineTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.containerEngine';
constructor(public workspaceFolder: WorkspaceFolder, containerEngine: ContainerEngine) {
super(containerEngine.key, TreeItemCollapsibleState.None);
this.description = containerEngine.value;
this.contextValue = ContainerEngineTreeItem.contextValue;
this.iconPath = new ThemeIcon('code');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -1,16 +1,25 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import ContainerEngineTreeItem from "./containerEngine";
export default class ContainerEnginesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.containerEngines';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Container Engines', TreeItemCollapsibleState.Collapsed);
this.contextValue = ContainerEnginesTreeItem.contextValue;
this.iconPath = new ThemeIcon('server-process');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
const items: GithubLocalActionsTreeItem[] = [];
const containerEngines = act.settingsManager.getSettings(this.workspaceFolder).containerEngines;
for (const containerEngine of containerEngines) {
items.push(new ContainerEngineTreeItem(this.workspaceFolder, containerEngine));
}
return items;
}
}

View File

@@ -1,11 +1,11 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Environment } from "../../settingsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class EnvironmentTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.environment';
constructor(environment: Environment) {
constructor(public workspaceFolder: WorkspaceFolder, environment: Environment) {
super(environment.name, TreeItemCollapsibleState.None);
this.contextValue = EnvironmentTreeItem.contextValue;
this.iconPath = new ThemeIcon('server');

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import EnvironmentTreeItem from "./environment";
@@ -6,15 +6,15 @@ import EnvironmentTreeItem from "./environment";
export default class EnvironmentsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.environments';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Environments', TreeItemCollapsibleState.Collapsed);
this.contextValue = EnvironmentsTreeItem.contextValue;
this.iconPath = new ThemeIcon('server-environment');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const workflows = await act.workflowsManager.getWorkflows();
const workflows = await act.workflowsManager.getWorkflows(this.workspaceFolder);
const environments = [...new Set(workflows.map(workflow => act.settingsManager.getEnvironments(workflow)).flat())];
return environments.map(environment => new EnvironmentTreeItem(environment));
return environments.map(environment => new EnvironmentTreeItem(this.workspaceFolder, environment));
}
}

View File

@@ -1,11 +1,11 @@
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Input } from "../../settingsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class InputTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.input';
constructor(input: Input) {
constructor(public workspaceFolder: WorkspaceFolder, input: Input) {
super(input.key, TreeItemCollapsibleState.None);
this.description = input.value;
this.contextValue = InputTreeItem.contextValue;

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputTreeItem from "./input";
@@ -6,15 +6,15 @@ import InputTreeItem from "./input";
export default class InputsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.inputs';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Inputs', TreeItemCollapsibleState.Collapsed);
this.contextValue = InputsTreeItem.contextValue;
this.iconPath = new ThemeIcon('record-keys');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const workflows = await act.workflowsManager.getWorkflows();
const workflows = await act.workflowsManager.getWorkflows(this.workspaceFolder);
const inputs = [...new Set(workflows.map(workflow => act.settingsManager.getInputs(workflow)).flat())];
return inputs.map(input => new InputTreeItem(input));
return inputs.map(input => new InputTreeItem(this.workspaceFolder, input));
}
}

View File

@@ -1,10 +1,10 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class RunnersTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.runners';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Runners', TreeItemCollapsibleState.Collapsed);
this.contextValue = RunnersTreeItem.contextValue;
this.iconPath = new ThemeIcon('database');

View File

@@ -1,15 +1,13 @@
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Secret } from "../../settingsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class SecretTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.secret';
constructor(secret: Secret) {
constructor(public workspaceFolder: WorkspaceFolder, secret: Secret) {
super(secret.key, TreeItemCollapsibleState.None);
if (secret.value) {
this.description = '••••••••'
}
this.description = secret.value ? '••••••••' : '';
this.contextValue = SecretTreeItem.contextValue;
this.iconPath = new ThemeIcon('key');
this.checkboxState = TreeItemCheckboxState.Unchecked;

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SecretTreeItem from "./secret";
@@ -6,15 +6,15 @@ import SecretTreeItem from "./secret";
export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.secrets';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Secrets', TreeItemCollapsibleState.Collapsed);
this.contextValue = SecretsTreeItem.contextValue;
this.iconPath = new ThemeIcon('lock');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const workflows = await act.workflowsManager.getWorkflows();
const workflows = await act.workflowsManager.getWorkflows(this.workspaceFolder);
const secrets = [...new Set(workflows.map(workflow => act.settingsManager.getSecrets(workflow)).flat())];
return secrets.map(secret => new SecretTreeItem(secret));
return secrets.map(secret => new SecretTreeItem(this.workspaceFolder, secret));
}
}

View File

@@ -1,12 +1,12 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem } from "vscode";
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, workspace } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import ContainerEnginesTreeItem from "./containerEngines";
import EnvironmentsTreeItem from "./environments";
import InputsTreeItem from "./inputs";
import ContainerEngineTreeItem from "./containerEngine";
import InputTreeItem from "./input";
import RunnersTreeItem from "./runners";
import SecretsTreeItem from "./secrets";
import VariablesTreeItem from "./variables";
import SecretTreeItem from "./secret";
import VariableTreeItem from "./variable";
import WorkspaceFolderSettingsTreeItem from "./workspaceFolderSettings";
export default class SettingsTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> {
private _onDidChangeTreeData = new EventEmitter<GithubLocalActionsTreeItem | undefined | null | void>();
@@ -17,6 +17,21 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
context.subscriptions.push(
commands.registerCommand('githubLocalActions.refreshSettings', async () => {
this.refresh();
}),
commands.registerCommand('githubLocalActions.editSecret', async (secretTreeItem: SecretTreeItem) => {
//TODO: Implement
}),
commands.registerCommand('githubLocalActions.editVariable', async (variableTreeItem: VariableTreeItem) => {
//TODO: Implement
}),
commands.registerCommand('githubLocalActions.editInput', async (inputTreeItem: InputTreeItem) => {
//TODO: Implement
}),
commands.registerCommand('githubLocalActions.addRunner', async (runnersTreeItem: RunnersTreeItem) => {
//TODO: Implement
}),
commands.registerCommand('githubLocalActions.editContainerEngine', async (containerEngineTreeItem: ContainerEngineTreeItem) => {
//TODO: Implement
})
);
}
@@ -42,20 +57,21 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
return element.getChildren();
} else {
const items: GithubLocalActionsTreeItem[] = [];
let noSettings: boolean = true;
const workflows = await act.workflowsManager.getWorkflows();
if (workflows.length > 0) {
items.push(...[
new EnvironmentsTreeItem(),
new SecretsTreeItem(),
new VariablesTreeItem(),
new InputsTreeItem(),
new RunnersTreeItem(),
new ContainerEnginesTreeItem()
]);
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) {
for (const workspaceFolder of workspaceFolders) {
items.push(new WorkspaceFolderSettingsTreeItem(workspaceFolder));
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
if (workflows.length > 0) {
noSettings = false;
}
}
}
await commands.executeCommand('setContext', 'githubLocalActions:noSettings', items.length == 0);
await commands.executeCommand('setContext', 'githubLocalActions:noSettings', noSettings);
return items;
}
}

View File

@@ -1,11 +1,11 @@
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Variable } from "../../settingsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class VariableTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.variable';
constructor(variable: Variable) {
constructor(public workspaceFolder: WorkspaceFolder, variable: Variable) {
super(variable.key, TreeItemCollapsibleState.None);
this.description = variable.value;
this.contextValue = VariableTreeItem.contextValue;

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import VariableTreeItem from "./variable";
@@ -6,15 +6,15 @@ import VariableTreeItem from "./variable";
export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.variables';
constructor() {
constructor(public workspaceFolder: WorkspaceFolder) {
super('Variables', TreeItemCollapsibleState.Collapsed);
this.contextValue = VariablesTreeItem.contextValue;
this.iconPath = new ThemeIcon('symbol-key');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const workflows = await act.workflowsManager.getWorkflows();
const workflows = await act.workflowsManager.getWorkflows(this.workspaceFolder);
const variables = [...new Set(workflows.map(workflow => act.settingsManager.getVariables(workflow)).flat())];
return variables.map(variable => new VariableTreeItem(variable));
return variables.map(variable => new VariableTreeItem(this.workspaceFolder, variable));
}
}

View File

@@ -0,0 +1,33 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import ContainerEnginesTreeItem from "./containerEngines";
import EnvironmentsTreeItem from "./environments";
import InputsTreeItem from "./inputs";
import RunnersTreeItem from "./runners";
import SecretsTreeItem from "./secrets";
import VariablesTreeItem from "./variables";
export default class WorkspaceFolderSettingsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.workspaceFolderSettings';
constructor(public workspaceFolder: WorkspaceFolder) {
super(workspaceFolder.name, TreeItemCollapsibleState.Collapsed);
this.contextValue = WorkspaceFolderSettingsTreeItem.contextValue;
this.iconPath = new ThemeIcon('folder');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const items: GithubLocalActionsTreeItem[] = [];
items.push(...[
new EnvironmentsTreeItem(this.workspaceFolder),
new SecretsTreeItem(this.workspaceFolder),
new VariablesTreeItem(this.workspaceFolder),
new InputsTreeItem(this.workspaceFolder),
new RunnersTreeItem(this.workspaceFolder),
new ContainerEnginesTreeItem(this.workspaceFolder)
]);
return items;
}
}

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Job, Workflow } from "../../workflowsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
@@ -7,7 +7,7 @@ export default class JobTreeItem extends TreeItem implements GithubLocalActionsT
job: Job;
workflow: Workflow;
constructor(workflow: Workflow, job: Job) {
constructor(public workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
super(job.name, TreeItemCollapsibleState.None);
this.workflow = workflow;
this.job = job;

View File

@@ -1,4 +1,4 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, WorkspaceFolder } from "vscode";
import { Workflow } from "../../workflowsManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import JobTreeItem from "./job";
@@ -7,7 +7,7 @@ export default class WorkflowTreeItem extends TreeItem implements GithubLocalAct
static contextValue = 'githubLocalActions.workflow';
workflow: Workflow;
constructor(workflow: Workflow) {
constructor(public workspaceFolder: WorkspaceFolder, workflow: Workflow) {
super(workflow.name, workflow.error ? TreeItemCollapsibleState.None : TreeItemCollapsibleState.Collapsed);
this.workflow = workflow;
this.contextValue = WorkflowTreeItem.contextValue;
@@ -27,7 +27,7 @@ export default class WorkflowTreeItem extends TreeItem implements GithubLocalAct
const jobs = this.workflow.yaml.jobs;
if (jobs) {
for (const [key, value] of Object.entries<any>(jobs)) {
items.push(new JobTreeItem(this.workflow, { name: value.name ? value.name : key, id: key }));
items.push(new JobTreeItem(this.workspaceFolder, this.workflow, { name: value.name ? value.name : key, id: key }));
}
}

View File

@@ -3,6 +3,7 @@ import { Event } from "../../act";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import WorkflowTreeItem from "./workflow";
import WorkspaceFolderWorkflowsTreeItem from "./workspaceFolderWorkflows";
export default class WorkflowsTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> {
private _onDidChangeTreeData = new EventEmitter<GithubLocalActionsTreeItem | undefined | null | void>();
@@ -63,13 +64,22 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
return element.getChildren();
} else {
const items: GithubLocalActionsTreeItem[] = [];
let noWorkflows: boolean = true;
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders) {
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();
for (const workflow of workflows) {
items.push(new WorkflowTreeItem(workflow));
}
await commands.executeCommand('setContext', 'githubLocalActions:noWorkflows', items.length == 0);
await commands.executeCommand('setContext', 'githubLocalActions:noWorkflows', noWorkflows);
return items;
}
}

View File

@@ -0,0 +1,25 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import WorkflowTreeItem from "./workflow";
export default class WorkspaceFolderWorkflowsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.workspaceFolderWorkflows';
constructor(public workspaceFolder: WorkspaceFolder) {
super(workspaceFolder.name, TreeItemCollapsibleState.Collapsed);
this.contextValue = WorkspaceFolderWorkflowsTreeItem.contextValue;
this.iconPath = new ThemeIcon('folder');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const items: GithubLocalActionsTreeItem[] = [];
const workflows = await act.workflowsManager.getWorkflows(this.workspaceFolder);
for (const workflow of workflows) {
items.push(new WorkflowTreeItem(this.workspaceFolder, workflow));
}
return items;
}
}