Add support for setting variables, inputs, and runners

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-10-21 17:56:08 -04:00
parent b7dd3b5d0f
commit cde9a5a173
18 changed files with 115 additions and 314 deletions

View File

@@ -1,19 +0,0 @@
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';
environment: Environment;
constructor(public workspaceFolder: WorkspaceFolder, environment: Environment) {
super(environment.name, TreeItemCollapsibleState.None);
this.environment = environment;
this.contextValue = EnvironmentTreeItem.contextValue;
this.iconPath = new ThemeIcon('server');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -1,25 +0,0 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import EnvironmentTreeItem from "./environment";
export default class EnvironmentsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.environments';
constructor(public workspaceFolder: WorkspaceFolder) {
super('Environments', TreeItemCollapsibleState.Collapsed);
this.contextValue = EnvironmentsTreeItem.contextValue;
this.iconPath = new ThemeIcon('server-environment');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const items: GithubLocalActionsTreeItem[] = [];
const environments = await act.settingsManager.getEnvironments(this.workspaceFolder);
for (const environment of environments) {
items.push(new EnvironmentTreeItem(this.workspaceFolder, environment));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString()));
}
}

View File

@@ -1,21 +0,0 @@
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';
input: Input
constructor(public workspaceFolder: WorkspaceFolder, input: Input) {
super(input.key, TreeItemCollapsibleState.None);
this.input = input;
this.description = input.value;
this.contextValue = InputTreeItem.contextValue;
this.iconPath = new ThemeIcon('symbol-parameter');
this.checkboxState = input.selected ? TreeItemCheckboxState.Checked : TreeItemCheckboxState.Unchecked;
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -3,7 +3,7 @@ import { act } from "../../extension";
import { SettingsManager } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputTreeItem from "./input";
import SettingTreeItem from "./setting";
export default class InputsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.inputs';
@@ -19,7 +19,7 @@ export default class InputsTreeItem extends TreeItem implements GithubLocalActio
const inputs = await act.settingsManager.getSetting(this.workspaceFolder, SettingsManager.inputsRegExp, StorageKey.Inputs);
for (const input of inputs) {
items.push(new InputTreeItem(this.workspaceFolder, input));
items.push(SettingTreeItem.getInputTreeItem(this.workspaceFolder, input));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString()));

View File

@@ -1,5 +1,9 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { SettingsManager } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SettingTreeItem from "./setting";
export default class RunnersTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.runners';
@@ -7,10 +11,17 @@ export default class RunnersTreeItem extends TreeItem implements GithubLocalActi
constructor(public workspaceFolder: WorkspaceFolder) {
super('Runners', TreeItemCollapsibleState.Collapsed);
this.contextValue = RunnersTreeItem.contextValue;
this.iconPath = new ThemeIcon('database');
this.iconPath = new ThemeIcon('server-environment');
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
const items: GithubLocalActionsTreeItem[] = [];
const runners = await act.settingsManager.getSetting(this.workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners);
for (const runner of runners) {
items.push(SettingTreeItem.getRunnerTreeItem(this.workspaceFolder, runner));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString()));
}
}

View File

@@ -1,21 +0,0 @@
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';
secret: Secret;
constructor(public workspaceFolder: WorkspaceFolder, secret: Secret) {
super(secret.key, TreeItemCollapsibleState.None);
this.secret = secret;
this.description = secret.value ? '••••••••' : '';
this.contextValue = SecretTreeItem.contextValue;
this.iconPath = new ThemeIcon('key');
this.checkboxState = secret.selected ? TreeItemCheckboxState.Checked : TreeItemCheckboxState.Unchecked;
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -3,7 +3,7 @@ import { act } from "../../extension";
import { SettingsManager } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SecretTreeItem from "./secret";
import SettingTreeItem from "./setting";
export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.secrets';
@@ -19,7 +19,7 @@ export default class SecretsTreeItem extends TreeItem implements GithubLocalActi
const secrets = await act.settingsManager.getSetting(this.workspaceFolder, SettingsManager.secretsRegExp, StorageKey.Secrets);
for (const secret of secrets) {
items.push(new SecretTreeItem(this.workspaceFolder, secret));
items.push(SettingTreeItem.getSecretTreeItem(this.workspaceFolder, secret));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString()));

View File

@@ -0,0 +1,39 @@
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { Setting } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class SettingTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
setting: Setting;
storageKey: StorageKey;
constructor(public workspaceFolder: WorkspaceFolder, setting: Setting, storageKey: StorageKey, treeItem: { description: string, contextValue: string, iconPath: ThemeIcon }) {
super(setting.key, TreeItemCollapsibleState.None);
this.setting = setting;
this.storageKey = storageKey;
this.description = treeItem.description;
this.contextValue = treeItem.contextValue;
this.iconPath = treeItem.iconPath;
this.checkboxState = setting.selected ? TreeItemCheckboxState.Checked : TreeItemCheckboxState.Unchecked;
}
static getSecretTreeItem(workspaceFolder: WorkspaceFolder, secret: Setting): SettingTreeItem {
return new SettingTreeItem(workspaceFolder, secret, StorageKey.Secrets, { description: secret.value ? '••••••••' : '', contextValue: 'githubLocalActions.secret', iconPath: new ThemeIcon('key') });
}
static getVariableTreeItem(workspaceFolder: WorkspaceFolder, variable: Setting): SettingTreeItem {
return new SettingTreeItem(workspaceFolder, variable, StorageKey.Variables, { description: variable.value, contextValue: 'githubLocalActions.variable', iconPath: new ThemeIcon('symbol-variable') });
}
static getInputTreeItem(workspaceFolder: WorkspaceFolder, input: Setting): SettingTreeItem {
return new SettingTreeItem(workspaceFolder, input, StorageKey.Inputs, { description: input.value, contextValue: 'githubLocalActions.input', iconPath: new ThemeIcon('symbol-parameter') });
}
static getRunnerTreeItem(workspaceFolder: WorkspaceFolder, runner: Setting): SettingTreeItem {
return new SettingTreeItem(workspaceFolder, runner, StorageKey.Runners, { description: runner.value, contextValue: 'githubLocalActions.runner', iconPath: new ThemeIcon('server') });
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -1,11 +1,7 @@
import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeCheckboxChangeEvent, TreeDataProvider, TreeItem, TreeItemCheckboxState, window, workspace } from "vscode";
import { act } from "../../extension";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputTreeItem from "./input";
import RunnersTreeItem from "./runners";
import SecretTreeItem from "./secret";
import VariableTreeItem from "./variable";
import SettingTreeItem from "./setting";
import WorkspaceFolderSettingsTreeItem from "./workspaceFolderSettings";
export default class SettingsTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> {
@@ -18,45 +14,18 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
commands.registerCommand('githubLocalActions.refreshSettings', async () => {
this.refresh();
}),
commands.registerCommand('githubLocalActions.editSecret', async (secretTreeItem: SecretTreeItem) => {
commands.registerCommand('githubLocalActions.editSetting', async (settingTreeItem: SettingTreeItem) => {
const newValue = await window.showInputBox({
prompt: `Enter the value for ${secretTreeItem.secret.value}`,
placeHolder: `Secret value`,
value: secretTreeItem.secret.value,
prompt: `Enter the value for ${settingTreeItem.setting.value}`,
placeHolder: `Setting value`,
value: settingTreeItem.setting.value,
password: true
});
if (newValue !== undefined) {
await act.settingsManager.editSetting(secretTreeItem.workspaceFolder, { key: secretTreeItem.secret.key, value: newValue, selected: secretTreeItem.secret.selected }, StorageKey.Secrets);
await act.settingsManager.editSetting(settingTreeItem.workspaceFolder, { key: settingTreeItem.setting.key, value: newValue, selected: settingTreeItem.setting.selected }, settingTreeItem.storageKey);
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.editVariable', async (variableTreeItem: VariableTreeItem) => {
const newValue = await window.showInputBox({
prompt: `Enter the value for ${variableTreeItem.variable.value}`,
placeHolder: `Variable value`,
value: variableTreeItem.variable.value
});
if (newValue !== undefined) {
await act.settingsManager.editSetting(variableTreeItem.workspaceFolder, { key: variableTreeItem.variable.key, value: newValue, selected: variableTreeItem.variable.selected }, StorageKey.Variables);
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.editInput', async (inputTreeItem: InputTreeItem) => {
const newValue = await window.showInputBox({
prompt: `Enter the value for ${inputTreeItem.input.value}`,
placeHolder: `Input value`,
value: inputTreeItem.input.value
});
if (newValue !== undefined) {
await act.settingsManager.editSetting(inputTreeItem.workspaceFolder, { key: inputTreeItem.input.key, value: newValue, selected: inputTreeItem.input.selected }, StorageKey.Inputs);
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.addRunner', async (runnersTreeItem: RunnersTreeItem) => {
//TODO: Implement
})
);
}
@@ -77,15 +46,9 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
return element;
}
async onDidChangeCheckboxState(event: TreeCheckboxChangeEvent<SecretTreeItem | VariableTreeItem | InputTreeItem>) {
async onDidChangeCheckboxState(event: TreeCheckboxChangeEvent<SettingTreeItem>) {
for await (const [treeItem, state] of event.items) {
if (treeItem instanceof SecretTreeItem) {
await act.settingsManager.editSetting(treeItem.workspaceFolder, { key: treeItem.secret.key, value: treeItem.secret.value, selected: state === TreeItemCheckboxState.Checked }, StorageKey.Secrets);
} else if (treeItem instanceof VariableTreeItem) {
await act.settingsManager.editSetting(treeItem.workspaceFolder, { key: treeItem.variable.key, value: treeItem.variable.value, selected: state === TreeItemCheckboxState.Checked }, StorageKey.Variables);
} else {
await act.settingsManager.editSetting(treeItem.workspaceFolder, { key: treeItem.input.key, value: treeItem.input.value, selected: state === TreeItemCheckboxState.Checked }, StorageKey.Inputs);
}
await act.settingsManager.editSetting(treeItem.workspaceFolder, { key: treeItem.setting.key, value: treeItem.setting.value, selected: state === TreeItemCheckboxState.Checked }, treeItem.storageKey);
}
}

View File

@@ -1,21 +0,0 @@
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';
variable: Variable;
constructor(public workspaceFolder: WorkspaceFolder, variable: Variable) {
super(variable.key, TreeItemCollapsibleState.None);
this.variable = variable;
this.description = variable.value;
this.contextValue = VariableTreeItem.contextValue;
this.iconPath = new ThemeIcon('symbol-variable');
this.checkboxState = variable.selected ? TreeItemCheckboxState.Checked : TreeItemCheckboxState.Unchecked;
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -3,7 +3,7 @@ import { act } from "../../extension";
import { SettingsManager } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import VariableTreeItem from "./variable";
import SettingTreeItem from "./setting";
export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.variables';
@@ -19,7 +19,7 @@ export default class VariablesTreeItem extends TreeItem implements GithubLocalAc
const variables = await act.settingsManager.getSetting(this.workspaceFolder, SettingsManager.variablesRegExp, StorageKey.Variables);
for (const variable of variables) {
items.push(new VariableTreeItem(this.workspaceFolder, variable));
items.push(SettingTreeItem.getVariableTreeItem(this.workspaceFolder, variable));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString()));

View File

@@ -1,6 +1,5 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import EnvironmentsTreeItem from "./environments";
import InputsTreeItem from "./inputs";
import RunnersTreeItem from "./runners";
import SecretsTreeItem from "./secrets";
@@ -19,7 +18,6 @@ export default class WorkspaceFolderSettingsTreeItem extends TreeItem implements
const items: GithubLocalActionsTreeItem[] = [];
items.push(...[
new EnvironmentsTreeItem(this.workspaceFolder),
new SecretsTreeItem(this.workspaceFolder),
new VariablesTreeItem(this.workspaceFolder),
new InputsTreeItem(this.workspaceFolder),