Add support for setting variables, inputs, and runners
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ Run your GitHub Actions locally with the power of the [GitHub Local Actions](htt
|
||||
|
||||
* Run Workflows:
|
||||
* View Workflow Run History:
|
||||
* Manage Environments, Secrets, and Variables:
|
||||
* Manage Secrets, Variables, and Inputs:
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
55
package.json
55
package.json
@@ -238,27 +238,9 @@
|
||||
},
|
||||
{
|
||||
"category": "GitHub Local Actions",
|
||||
"command": "githubLocalActions.editSecret",
|
||||
"title": "Edit Secret",
|
||||
"command": "githubLocalActions.editSetting",
|
||||
"title": "Edit",
|
||||
"icon": "$(edit)"
|
||||
},
|
||||
{
|
||||
"category": "GitHub Local Actions",
|
||||
"command": "githubLocalActions.editVariable",
|
||||
"title": "Edit Variable",
|
||||
"icon": "$(edit)"
|
||||
},
|
||||
{
|
||||
"category": "GitHub Local Actions",
|
||||
"command": "githubLocalActions.editInput",
|
||||
"title": "Edit Input",
|
||||
"icon": "$(edit)"
|
||||
},
|
||||
{
|
||||
"category": "GitHub Local Actions",
|
||||
"command": "githubLocalActions.addRunner",
|
||||
"title": "Add Runner",
|
||||
"icon": "$(add)"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
@@ -332,19 +314,7 @@
|
||||
"when": "never"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editSecret",
|
||||
"when": "never"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editVariable",
|
||||
"when": "never"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editInput",
|
||||
"when": "never"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.addRunner",
|
||||
"command": "githubLocalActions.editSetting",
|
||||
"when": "never"
|
||||
}
|
||||
],
|
||||
@@ -452,23 +422,8 @@
|
||||
"group": "inline@3"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editSecret",
|
||||
"when": "view == settings && viewItem =~ /^githubLocalActions.secret(?!s).*/",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editVariable",
|
||||
"when": "view == settings && viewItem =~ /^githubLocalActions.variable(?!s).*/",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.editInput",
|
||||
"when": "view == settings && viewItem =~ /^githubLocalActions.input(?!s).*/",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "githubLocalActions.addRunner",
|
||||
"when": "view == settings && viewItem =~ /^githubLocalActions.runners.*/",
|
||||
"command": "githubLocalActions.editSetting",
|
||||
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|runner)(?!s).*/",
|
||||
"group": "inline@0"
|
||||
}
|
||||
]
|
||||
|
||||
52
src/act.ts
52
src/act.ts
@@ -47,11 +47,11 @@ export enum Event {
|
||||
export enum Option {
|
||||
ActionCachePath = '--action-cache-path',
|
||||
ActionOfflineMode = '--action-offline-mode',
|
||||
Actor = '--a',
|
||||
Actor = '-a',
|
||||
ArtifactServerAddr = '--artifact-server-addr',
|
||||
ArtifactServerPath = '--artifact-server-path',
|
||||
ArtifactServerPort = '--artifact-server-port',
|
||||
Bind = '--b',
|
||||
Bind = '-b',
|
||||
BugReport = '--bug-report',
|
||||
CacheServerAddr = '--cache-server-addr',
|
||||
CacheServerPath = '--cache-server-path',
|
||||
@@ -63,20 +63,20 @@ export enum Option {
|
||||
ContainerOptions = '--container-options',
|
||||
DefaultBranch = '--defaultbranch',
|
||||
DetectEvent = '--detect-event',
|
||||
Directory = '--C',
|
||||
DryRun = '--n',
|
||||
Directory = '-C',
|
||||
DryRun = '-n',
|
||||
Env = '--env',
|
||||
EnvFile = '--env-file',
|
||||
EventPath = '--e',
|
||||
EventPath = '-e',
|
||||
GitHubInstance = '--github-instance',
|
||||
Graph = '--g',
|
||||
Help = '--h',
|
||||
Graph = '-g',
|
||||
Help = '-h',
|
||||
Input = '--input',
|
||||
InputFile = '--input-file',
|
||||
InsecureSecrets = '--insecure-secrets',
|
||||
Job = '--j',
|
||||
Job = '-j',
|
||||
Json = '--json',
|
||||
List = '--l',
|
||||
List = '-l',
|
||||
LocalRepository = '--local-repository',
|
||||
LogPrefixJobId = '--log-prefix-job-id',
|
||||
ManPage = '--man-page',
|
||||
@@ -85,15 +85,15 @@ export enum Option {
|
||||
NoCacheServer = '--no-cache-server',
|
||||
NoRecurse = '--no-recurse',
|
||||
NoSkipCheckout = '--no-skip-checkout',
|
||||
Platform = '--P',
|
||||
Platform = '-P',
|
||||
Privileged = '--privileged',
|
||||
Pull = '--p',
|
||||
Quiet = '--q',
|
||||
Pull = '-p',
|
||||
Quiet = '-q',
|
||||
Rebuild = '--rebuild',
|
||||
RemoteName = '--remote-name',
|
||||
ReplaceGHEActionTokenWithGitHubCom = '--replace-ghe-action-token-with-github-com',
|
||||
ReplaceGHEActionWithGitHubCom = '--replace-ghe-action-with-github-com',
|
||||
Reuse = '--r',
|
||||
Reuse = '-r',
|
||||
Rm = '--rm',
|
||||
Secret = '--secret',
|
||||
SecretFile = '--secret-file',
|
||||
@@ -102,10 +102,10 @@ export enum Option {
|
||||
Userns = '--userns',
|
||||
Var = '--var',
|
||||
VarFile = '--var-file',
|
||||
Verbose = '--v',
|
||||
Verbose = '-v',
|
||||
Version = '--version',
|
||||
Watch = '--w',
|
||||
Workflows = '--W'
|
||||
Watch = '-w',
|
||||
Workflows = '-W'
|
||||
}
|
||||
|
||||
export interface CommandArgs {
|
||||
@@ -258,19 +258,20 @@ export class Act {
|
||||
runOptions: {},
|
||||
group: TaskGroup.Build,
|
||||
execution: new CustomExecution(async (resolvedDefinition: TaskDefinition): Promise<Pseudoterminal> => {
|
||||
const environments = await this.settingsManager.getEnvironments(commandArgs.workspaceFolder);
|
||||
const secrets = (await this.settingsManager.getSetting(commandArgs.workspaceFolder, SettingsManager.secretsRegExp, StorageKey.Secrets)).filter(secret => secret.selected && secret.value);
|
||||
const variables = (await this.settingsManager.getSetting(commandArgs.workspaceFolder, SettingsManager.variablesRegExp, StorageKey.Variables)).filter(variable => variable.selected && variable.value);
|
||||
const inputs = (await this.settingsManager.getSetting(commandArgs.workspaceFolder, SettingsManager.inputsRegExp, StorageKey.Inputs)).filter(input => input.selected && input.value);
|
||||
|
||||
const runners = (await this.settingsManager.getSetting(commandArgs.workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners)).filter(runner => runner.selected && runner.value);
|
||||
|
||||
|
||||
// TODO: Fix secrets, variables, and inputs in below command
|
||||
// How to pass in secrets
|
||||
// Is there any point to show environments in the header? Is it needed in the tree view?
|
||||
const variablesOption = variables.length > 0 ? `${Option.Var} ${variables.map(variable => `${variable.key}=${variable.value}`).join(` ${Option.Var} `)}` : ``;
|
||||
const inputsOption = inputs.length > 0 ? `${Option.Input} ${inputs.map(input => `${input.key}=${input.value}`).join(` ${Option.Input} `)}` : ``;
|
||||
const runnersOption = runners.length > 0 ? `${Option.Platform} ${runners.map(runner => `${runner.key}=${runner.value}`).join(` ${Option.Platform} `)}` : ``;
|
||||
|
||||
|
||||
const command = `${Act.base} ${Option.Json} ${commandArgs.options}`;
|
||||
const command = `${Act.base} ${Option.Json} ${variablesOption} ${inputsOption} ${runnersOption} ${commandArgs.options}`;
|
||||
|
||||
|
||||
|
||||
@@ -375,9 +376,8 @@ export class Act {
|
||||
open: async (initialDimensions: TerminalDimensions | undefined): Promise<void> => {
|
||||
let headerText: string = '';
|
||||
const addMultipleEntries = (key: string, values: string[]): { key: string, value: string }[] => {
|
||||
if (values.length === 0) return [];
|
||||
return values.map((value, index) => ({
|
||||
key: index === 0 ? key : '', // Show the key only for the first entry
|
||||
key: index === 0 ? key : '',
|
||||
value
|
||||
}));
|
||||
};
|
||||
@@ -386,10 +386,10 @@ export class Act {
|
||||
{ key: 'Name', value: commandArgs.name },
|
||||
{ key: 'Path', value: commandArgs.workspaceFolder.uri.fsPath },
|
||||
...commandArgs.extraHeader,
|
||||
...addMultipleEntries('Environments', environments.map(env => env.name)),
|
||||
...addMultipleEntries('Variables', variables.map(variable => `${variable.key}=${variable.value}`)),
|
||||
...addMultipleEntries('Secrets', secrets.map(secret => `${secret.key}=••••••••`)),
|
||||
...addMultipleEntries('Inputs', inputs.map(input => `${input.key}=${input.value}`)),
|
||||
...(variables.length > 0 ? addMultipleEntries('Variables', variables.map(variable => `${variable.key}=${variable.value}`)) : []),
|
||||
...(secrets.length > 0 ? addMultipleEntries('Secrets', secrets.map(secret => `${secret.key}`)) : []),
|
||||
...(inputs.length > 0 ? addMultipleEntries('Inputs', inputs.map(input => `${input.key}=${input.value}`)) : []),
|
||||
...(runners.length > 0 ? addMultipleEntries('Runners', runners.map(runner => `${runner.key}=${runner.value}`)) : []),
|
||||
{ key: 'Command', value: command.replace(` ${Option.Json}`, ``) }
|
||||
];
|
||||
|
||||
|
||||
@@ -5,10 +5,8 @@ import ComponentsTreeDataProvider from './views/components/componentsTreeDataPro
|
||||
import { DecorationProvider } from './views/decorationProvider';
|
||||
import { GithubLocalActionsTreeItem } from './views/githubLocalActionsTreeItem';
|
||||
import HistoryTreeDataProvider from './views/history/historyTreeDataProvider';
|
||||
import InputTreeItem from './views/settings/input';
|
||||
import SecretTreeItem from './views/settings/secret';
|
||||
import SettingTreeItem from './views/settings/setting';
|
||||
import SettingsTreeDataProvider from './views/settings/settingsTreeDataProvider';
|
||||
import VariableTreeItem from './views/settings/variable';
|
||||
import WorkflowsTreeDataProvider from './views/workflows/workflowsTreeDataProvider';
|
||||
|
||||
export let act: Act;
|
||||
@@ -33,7 +31,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
settingsTreeDataProvider = new SettingsTreeDataProvider(context);
|
||||
const settingsTreeView = window.createTreeView(SettingsTreeDataProvider.VIEW_ID, { treeDataProvider: settingsTreeDataProvider });
|
||||
settingsTreeView.onDidChangeCheckboxState(async (event: TreeCheckboxChangeEvent<GithubLocalActionsTreeItem>) => {
|
||||
await settingsTreeDataProvider.onDidChangeCheckboxState(event as TreeCheckboxChangeEvent<SecretTreeItem | VariableTreeItem | InputTreeItem>);
|
||||
await settingsTreeDataProvider.onDidChangeCheckboxState(event as TreeCheckboxChangeEvent<SettingTreeItem>);
|
||||
});
|
||||
|
||||
// Create file watcher
|
||||
|
||||
@@ -2,29 +2,7 @@ import { WorkspaceFolder } from "vscode";
|
||||
import { act } from "./extension";
|
||||
import { StorageKey, StorageManager } from "./storageManager";
|
||||
|
||||
export interface Environment {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Secret {
|
||||
key: string,
|
||||
value: string,
|
||||
selected: boolean
|
||||
}
|
||||
|
||||
export interface Variable {
|
||||
key: string,
|
||||
value: string,
|
||||
selected: boolean
|
||||
}
|
||||
|
||||
export interface Input {
|
||||
key: string,
|
||||
value: string,
|
||||
selected: boolean
|
||||
}
|
||||
|
||||
export interface Runner {
|
||||
export interface Setting {
|
||||
key: string,
|
||||
value: string,
|
||||
selected: boolean
|
||||
@@ -35,43 +13,14 @@ export class SettingsManager {
|
||||
static secretsRegExp: RegExp = /\${{\s*secrets\.(.*?)\s*}}/g;
|
||||
static variablesRegExp: RegExp = /\${{\s*vars\.(.*?)(?:\s*==\s*(.*?))?\s*}}/g;
|
||||
static inputsRegExp: RegExp = /\${{\s*(?:inputs|github\.event\.inputs)\.(.*?)(?:\s*==\s*(.*?))?\s*}}/g;
|
||||
static runnersRegExp: RegExp = /runs-on:\s*(.+)/g;
|
||||
|
||||
constructor(storageManager: StorageManager) {
|
||||
this.storageManager = storageManager;
|
||||
}
|
||||
|
||||
async getEnvironments(workspaceFolder: WorkspaceFolder): Promise<Environment[]> {
|
||||
const environments: Environment[] = [];
|
||||
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
for (const workflow of workflows) {
|
||||
if (!workflow.yaml) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const jobs = workflow.yaml?.jobs;
|
||||
if (jobs) {
|
||||
for (const details of Object.values<any>(jobs)) {
|
||||
if (details.environment) {
|
||||
const existingEnvironment = environments.find(environment => environment.name === details.environment);
|
||||
if (!existingEnvironment) {
|
||||
environments.push({
|
||||
name: details.environment
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return environments;
|
||||
}
|
||||
|
||||
|
||||
async getSetting<T extends Secret | Variable | Input>(workspaceFolder: WorkspaceFolder, regExp: RegExp, storageKey: StorageKey): Promise<T[]> {
|
||||
const existingSettings = this.storageManager.get<{ [path: string]: T[] }>(storageKey) || {};
|
||||
|
||||
const settings: T[] = [];
|
||||
async getSetting(workspaceFolder: WorkspaceFolder, regExp: RegExp, storageKey: StorageKey): Promise<Setting[]> {
|
||||
const settings: Setting[] = [];
|
||||
|
||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||
for (const workflow of workflows) {
|
||||
@@ -79,7 +28,7 @@ export class SettingsManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
const workflowSettings = this.findInWorkflow<T>(workflow.fileContent, regExp);
|
||||
const workflowSettings = this.findInWorkflow(workflow.fileContent, regExp);
|
||||
for (const workflowSetting of workflowSettings) {
|
||||
const existingSetting = settings.find(setting => setting.key === workflowSetting.key);
|
||||
if (!existingSetting) {
|
||||
@@ -88,6 +37,7 @@ export class SettingsManager {
|
||||
}
|
||||
}
|
||||
|
||||
const existingSettings = this.storageManager.get<{ [path: string]: Setting[] }>(storageKey) || {};
|
||||
if (existingSettings[workspaceFolder.uri.fsPath]) {
|
||||
for (const [index, setting] of settings.entries()) {
|
||||
const existingSetting = existingSettings[workspaceFolder.uri.fsPath].find(existingSetting => existingSetting.key === setting.key);
|
||||
@@ -96,7 +46,7 @@ export class SettingsManager {
|
||||
key: setting.key,
|
||||
value: existingSetting.value,
|
||||
selected: existingSetting.selected
|
||||
} as T;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,8 +56,9 @@ export class SettingsManager {
|
||||
return settings;
|
||||
}
|
||||
|
||||
async editSetting<T extends Secret | Variable | Input>(workspaceFolder: WorkspaceFolder, newSetting: T, storageKey: StorageKey) {
|
||||
const existingSettings = this.storageManager.get<{ [path: string]: T[] }>(storageKey) || {};
|
||||
async editSetting(workspaceFolder: WorkspaceFolder, newSetting: Setting, storageKey: StorageKey) {
|
||||
const existingSettings = this.storageManager.get<{ [path: string]: Setting[] }>(storageKey) || {};
|
||||
|
||||
if (existingSettings[workspaceFolder.uri.fsPath]) {
|
||||
const index = existingSettings[workspaceFolder.uri.fsPath].findIndex(setting => setting.key === newSetting.key);
|
||||
if (index > -1) {
|
||||
@@ -122,22 +73,14 @@ export class SettingsManager {
|
||||
await this.storageManager.update(storageKey, existingSettings);
|
||||
}
|
||||
|
||||
private findInWorkflow<T extends Secret | Variable | Input>(content: string, regExp: RegExp) {
|
||||
const results: (T)[] = [];
|
||||
private findInWorkflow(content: string, regExp: RegExp) {
|
||||
const results: Setting[] = [];
|
||||
|
||||
const matches = content.matchAll(regExp);
|
||||
for (const match of matches) {
|
||||
results.push({ key: match[1], value: '', selected: false } as T);
|
||||
results.push({ key: match[1], value: '', selected: false });
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
getRunners(workspaceFolder: WorkspaceFolder): Runner[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
addRunner(workspaceFolder: WorkspaceFolder, runner: Runner) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ export enum StorageKey {
|
||||
WorkspaceHistory = 'workspaceHistory',
|
||||
Secrets = 'secrets',
|
||||
Variables = 'variables',
|
||||
Inputs = 'inputs'
|
||||
Inputs = 'inputs',
|
||||
Runners = 'runners'
|
||||
}
|
||||
|
||||
export class StorageManager {
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
|
||||
39
src/views/settings/setting.ts
Normal file
39
src/views/settings/setting.ts
Normal 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 [];
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -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()));
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user