Add actions to add and open secret, variable, and input files

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-11-21 21:48:27 -05:00
parent 67ac9f72e7
commit 049b6bdc8f
12 changed files with 325 additions and 44 deletions

View File

@@ -240,6 +240,12 @@
"title": "Refresh", "title": "Refresh",
"icon": "$(refresh)" "icon": "$(refresh)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.addSecretFiles",
"title": "Add Secret Files",
"icon": "$(add)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.show", "command": "githubLocalActions.show",
@@ -252,12 +258,36 @@
"title": "Hide", "title": "Hide",
"icon": "$(eye-closed)" "icon": "$(eye-closed)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.addVariableFiles",
"title": "Add Variable Files",
"icon": "$(add)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.importFromGithub", "command": "githubLocalActions.importFromGithub",
"title": "Import from GitHub", "title": "Import from GitHub",
"icon": "$(github)" "icon": "$(github)"
}, },
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.addInputFiles",
"title": "Add Input Files",
"icon": "$(add)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.openSettingFile",
"title": "Open",
"icon": "$(go-to-file)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.removeSettingFile",
"title": "Remove",
"icon": "$(close)"
},
{ {
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.editSetting", "command": "githubLocalActions.editSetting",
@@ -352,6 +382,10 @@
"command": "githubLocalActions.refreshSettings", "command": "githubLocalActions.refreshSettings",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.addSecretFiles",
"when": "never"
},
{ {
"command": "githubLocalActions.show", "command": "githubLocalActions.show",
"when": "never" "when": "never"
@@ -360,10 +394,26 @@
"command": "githubLocalActions.hide", "command": "githubLocalActions.hide",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.addVariableFiles",
"when": "never"
},
{ {
"command": "githubLocalActions.importFromGithub", "command": "githubLocalActions.importFromGithub",
"when": "never" "when": "never"
}, },
{
"command": "githubLocalActions.addInputFiles",
"when": "never"
},
{
"command": "githubLocalActions.openSettingFile",
"when": "never"
},
{
"command": "githubLocalActions.removeSettingFile",
"when": "never"
},
{ {
"command": "githubLocalActions.editSetting", "command": "githubLocalActions.editSetting",
"when": "never" "when": "never"
@@ -495,6 +545,11 @@
"when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "when": "view == history && viewItem =~ /^githubLocalActions.history.*/",
"group": "inline@3" "group": "inline@3"
}, },
{
"command": "githubLocalActions.addSecretFiles",
"when": "view == settings && viewItem =~ /^githubLocalActions.secrets.*/",
"group": "inline@0"
},
{ {
"command": "githubLocalActions.show", "command": "githubLocalActions.show",
"when": "view == settings && viewItem =~ /^githubLocalActions.secret(?!s)_hide.*/", "when": "view == settings && viewItem =~ /^githubLocalActions.secret(?!s)_hide.*/",
@@ -506,13 +561,33 @@
"group": "inline@0" "group": "inline@0"
}, },
{ {
"command": "githubLocalActions.importFromGithub", "command": "githubLocalActions.addVariableFiles",
"when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/", "when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/",
"group": "inline@0" "group": "inline@0"
}, },
{
"command": "githubLocalActions.importFromGithub",
"when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/",
"group": "inline@1"
},
{
"command": "githubLocalActions.addInputFiles",
"when": "view == settings && viewItem =~ /^githubLocalActions.inputs.*/",
"group": "inline@0"
},
{
"command": "githubLocalActions.openSettingFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
"group": "inline@0"
},
{
"command": "githubLocalActions.removeSettingFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
"group": "inline@1"
},
{ {
"command": "githubLocalActions.editSetting", "command": "githubLocalActions.editSetting",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|runner)(?!s).*/", "when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|runner)(?!(File|s)).*/",
"group": "inline@1" "group": "inline@1"
} }
] ]

View File

@@ -55,7 +55,7 @@ export enum Option {
} }
export interface CommandArgs { export interface CommandArgs {
fsPath: string, path: string,
options: string, options: string,
name: string, name: string,
extraHeader: { key: string, value: string }[] extraHeader: { key: string, value: string }[]
@@ -168,7 +168,7 @@ export class Act {
const historyIndex = taskDefinition.historyIndex; const historyIndex = taskDefinition.historyIndex;
// Add new entry to workspace history // Add new entry to workspace history
this.historyManager.workspaceHistory[commandArgs.fsPath].push({ this.historyManager.workspaceHistory[commandArgs.path].push({
index: historyIndex, index: historyIndex,
count: taskDefinition.count, count: taskDefinition.count,
name: `${commandArgs.name}`, name: `${commandArgs.name}`,
@@ -191,18 +191,18 @@ export class Act {
const historyIndex = taskDefinition.historyIndex; const historyIndex = taskDefinition.historyIndex;
// Set end status // Set end status
if (this.historyManager.workspaceHistory[commandArgs.fsPath][historyIndex].status === HistoryStatus.Running) { if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status === HistoryStatus.Running) {
if (e.exitCode === 0) { if (e.exitCode === 0) {
this.historyManager.workspaceHistory[commandArgs.fsPath][historyIndex].status = HistoryStatus.Success; this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status = HistoryStatus.Success;
} else if (!e.exitCode) { } else if (!e.exitCode) {
this.historyManager.workspaceHistory[commandArgs.fsPath][historyIndex].status = HistoryStatus.Cancelled; this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status = HistoryStatus.Cancelled;
} else { } else {
this.historyManager.workspaceHistory[commandArgs.fsPath][historyIndex].status = HistoryStatus.Failed; this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status = HistoryStatus.Failed;
} }
} }
// Set end time // Set end time
this.historyManager.workspaceHistory[commandArgs.fsPath][historyIndex].date.end = new Date().toString(); this.historyManager.workspaceHistory[commandArgs.path][historyIndex].date.end = new Date().toString();
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
@@ -212,7 +212,7 @@ export class Act {
async runAllWorkflows(workspaceFolder: WorkspaceFolder) { async runAllWorkflows(workspaceFolder: WorkspaceFolder) {
return await this.runCommand({ return await this.runCommand({
fsPath: workspaceFolder.uri.fsPath, path: workspaceFolder.uri.fsPath,
options: ``, options: ``,
name: workspaceFolder.name, name: workspaceFolder.name,
extraHeader: [] extraHeader: []
@@ -221,7 +221,7 @@ export class Act {
async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) { async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) {
return await this.runCommand({ return await this.runCommand({
fsPath: workspaceFolder.uri.fsPath, path: workspaceFolder.uri.fsPath,
options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`,
name: workflow.name, name: workflow.name,
extraHeader: [ extraHeader: [
@@ -232,7 +232,7 @@ export class Act {
async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) { async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
return await this.runCommand({ return await this.runCommand({
fsPath: workspaceFolder.uri.fsPath, path: workspaceFolder.uri.fsPath,
options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}" ${Option.Job} "${job.id}"`, options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}" ${Option.Job} "${job.id}"`,
name: `${workflow.name}/${job.name}`, name: `${workflow.name}/${job.name}`,
extraHeader: [ extraHeader: [
@@ -244,7 +244,7 @@ export class Act {
async runEvent(workspaceFolder: WorkspaceFolder, event: Event) { async runEvent(workspaceFolder: WorkspaceFolder, event: Event) {
return await this.runCommand({ return await this.runCommand({
fsPath: workspaceFolder.uri.fsPath, path: workspaceFolder.uri.fsPath,
options: event, options: event,
name: event, name: event,
extraHeader: [ extraHeader: [
@@ -266,21 +266,21 @@ export class Act {
// } // }
// Map to workspace folder // Map to workspace folder
const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(commandArgs.fsPath)); const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(commandArgs.path));
if (!workspaceFolder) { if (!workspaceFolder) {
window.showErrorMessage(`Failed to locate workspace folder for ${commandArgs.fsPath}`); window.showErrorMessage(`Failed to locate workspace folder for ${commandArgs.path}`);
return; return;
} }
// Initialize history for workspace // Initialize history for workspace
if (!this.historyManager.workspaceHistory[commandArgs.fsPath]) { if (!this.historyManager.workspaceHistory[commandArgs.path]) {
this.historyManager.workspaceHistory[commandArgs.fsPath] = []; this.historyManager.workspaceHistory[commandArgs.path] = [];
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
} }
// Process task count suffix // Process task count suffix
const historyIndex = this.historyManager.workspaceHistory[commandArgs.fsPath].length; const historyIndex = this.historyManager.workspaceHistory[commandArgs.path].length;
const matchingTasks = this.historyManager.workspaceHistory[commandArgs.fsPath] const matchingTasks = this.historyManager.workspaceHistory[commandArgs.path]
.filter(history => history.name === commandArgs.name) .filter(history => history.name === commandArgs.name)
.sort((a, b) => b.count - a.count); .sort((a, b) => b.count - a.count);
const count = matchingTasks && matchingTasks.length > 0 ? matchingTasks[0].count + 1 : 1; const count = matchingTasks && matchingTasks.length > 0 ? matchingTasks[0].count + 1 : 1;
@@ -341,7 +341,7 @@ export class Act {
execution: new ShellExecution( execution: new ShellExecution(
command, command,
{ {
cwd: commandArgs.fsPath, cwd: commandArgs.path,
env: settings.secrets env: settings.secrets
.filter(secret => secret.value) .filter(secret => secret.value)
.reduce((previousValue, currentValue) => { .reduce((previousValue, currentValue) => {

View File

@@ -74,8 +74,8 @@ export class HistoryManager {
} }
async remove(history: History) { async remove(history: History) {
const historyIndex = this.workspaceHistory[history.commandArgs.fsPath].findIndex(workspaceHistory => workspaceHistory.index === history.index); const historyIndex = this.workspaceHistory[history.commandArgs.path].findIndex(workspaceHistory => workspaceHistory.index === history.index);
this.workspaceHistory[history.commandArgs.fsPath].splice(historyIndex, 1); this.workspaceHistory[history.commandArgs.path].splice(historyIndex, 1);
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
try { try {

View File

@@ -4,6 +4,17 @@ import { GitHubManager } from "./githubManager";
import { SecretManager } from "./secretManager"; import { SecretManager } from "./secretManager";
import { StorageKey, StorageManager } from "./storageManager"; import { StorageKey, StorageManager } from "./storageManager";
export interface Settings {
secrets: Setting[];
secretFiles: SettingFile[];
variables: Setting[];
variableFiles: SettingFile[];
inputs: Setting[];
inputFiles: SettingFile[];
runners: Setting[];
environments: Setting[];
}
export interface Setting { export interface Setting {
key: string, key: string,
value: string, value: string,
@@ -12,6 +23,12 @@ export interface Setting {
visible: Visibility visible: Visibility
} }
export interface SettingFile {
name: string,
path: string,
selected: boolean
}
export enum Visibility { export enum Visibility {
show = 'show', show = 'show',
hide = 'hide' hide = 'hide'
@@ -32,17 +49,23 @@ export class SettingsManager {
this.githubManager = new GitHubManager(); this.githubManager = new GitHubManager();
} }
async getSettings(workspaceFolder: WorkspaceFolder, isUserSelected: boolean) { async getSettings(workspaceFolder: WorkspaceFolder, isUserSelected: boolean): Promise<Settings> {
const secrets = (await this.getSetting(workspaceFolder, SettingsManager.secretsRegExp, StorageKey.Secrets, true, Visibility.hide)).filter(secret => !isUserSelected || secret.selected); const secrets = (await this.getSetting(workspaceFolder, SettingsManager.secretsRegExp, StorageKey.Secrets, true, Visibility.hide)).filter(secret => !isUserSelected || secret.selected);
const secretFiles = await this.getSettingFiles(workspaceFolder, StorageKey.SecretFiles);
const variables = (await this.getSetting(workspaceFolder, SettingsManager.variablesRegExp, StorageKey.Variables, false, Visibility.show)).filter(variable => !isUserSelected || variable.selected); const variables = (await this.getSetting(workspaceFolder, SettingsManager.variablesRegExp, StorageKey.Variables, false, Visibility.show)).filter(variable => !isUserSelected || variable.selected);
const variableFiles = await this.getSettingFiles(workspaceFolder, StorageKey.VariableFiles);
const inputs = (await this.getSetting(workspaceFolder, SettingsManager.inputsRegExp, StorageKey.Inputs, false, Visibility.show)).filter(input => !isUserSelected || (input.selected && input.value)); const inputs = (await this.getSetting(workspaceFolder, SettingsManager.inputsRegExp, StorageKey.Inputs, false, Visibility.show)).filter(input => !isUserSelected || (input.selected && input.value));
const inputFiles = await this.getSettingFiles(workspaceFolder, StorageKey.InputFiles);
const runners = (await this.getSetting(workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners, false, Visibility.show)).filter(runner => !isUserSelected || (runner.selected && runner.value)); const runners = (await this.getSetting(workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners, false, Visibility.show)).filter(runner => !isUserSelected || (runner.selected && runner.value));
const environments = await this.getEnvironments(workspaceFolder); const environments = await this.getEnvironments(workspaceFolder);
return { return {
secrets: secrets, secrets: secrets,
secretFiles: secretFiles,
variables: variables, variables: variables,
variableFiles: variableFiles,
inputs: inputs, inputs: inputs,
inputFiles: inputFiles,
runners: runners, runners: runners,
environments: environments environments: environments
}; };
@@ -94,6 +117,11 @@ export class SettingsManager {
return settings; return settings;
} }
async getSettingFiles(workspaceFolder: WorkspaceFolder, storageKey: StorageKey): Promise<SettingFile[]> {
const existingSettingFiles = this.storageManager.get<{ [path: string]: SettingFile[] }>(storageKey) || {};
return existingSettingFiles[workspaceFolder.uri.fsPath] || [];
}
async getEnvironments(workspaceFolder: WorkspaceFolder): Promise<Setting[]> { async getEnvironments(workspaceFolder: WorkspaceFolder): Promise<Setting[]> {
const environments: Setting[] = []; const environments: Setting[] = [];
@@ -125,6 +153,22 @@ export class SettingsManager {
return environments; return environments;
} }
async editSettingFile(workspaceFolder: WorkspaceFolder, newSettingFile: SettingFile, storageKey: StorageKey) {
const existingSettingFiles = this.storageManager.get<{ [path: string]: SettingFile[] }>(storageKey) || {};
if (existingSettingFiles[workspaceFolder.uri.fsPath]) {
const index = existingSettingFiles[workspaceFolder.uri.fsPath].findIndex(settingFile => settingFile.path === newSettingFile.path);
if (index > -1) {
existingSettingFiles[workspaceFolder.uri.fsPath][index] = newSettingFile;
} else {
existingSettingFiles[workspaceFolder.uri.fsPath].push(newSettingFile);
}
} else {
existingSettingFiles[workspaceFolder.uri.fsPath] = [newSettingFile];
}
await this.storageManager.update(storageKey, existingSettingFiles);
}
async editSetting(workspaceFolder: WorkspaceFolder, newSetting: Setting, storageKey: StorageKey) { async editSetting(workspaceFolder: WorkspaceFolder, newSetting: Setting, storageKey: StorageKey) {
const value = newSetting.value; const value = newSetting.value;
if (storageKey === StorageKey.Secrets) { if (storageKey === StorageKey.Secrets) {

View File

@@ -3,8 +3,11 @@ import { ExtensionContext } from "vscode";
export enum StorageKey { export enum StorageKey {
WorkspaceHistory = 'workspaceHistory', WorkspaceHistory = 'workspaceHistory',
Secrets = 'secrets', Secrets = 'secrets',
SecretFiles = 'secretFiles',
Variables = 'variables', Variables = 'variables',
VariableFiles = 'variableFiles',
Inputs = 'inputs', Inputs = 'inputs',
InputFiles = 'inputFiles',
Runners = 'runners' Runners = 'runners'
} }

View File

@@ -40,7 +40,7 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
} }
this.tooltip = `Name: ${history.name} #${history.count}\n` + this.tooltip = `Name: ${history.name} #${history.count}\n` +
`${history.commandArgs.extraHeader.map(header => `${header.key}: ${header.value}`).join('\n')}\n` + `${history.commandArgs.extraHeader.map(header => `${header.key}: ${header.value}`).join('\n')}\n` +
`Path: ${history.commandArgs.fsPath}\n` + `Path: ${history.commandArgs.path}\n` +
`Log File: ${path.parse(history.logPath).base}\n` + `Log File: ${path.parse(history.logPath).base}\n` +
`Status: ${history.status}\n` + `Status: ${history.status}\n` +
`Started: ${Utils.getDateString(history.date.start)}\n` + `Started: ${Utils.getDateString(history.date.start)}\n` +

View File

@@ -1,11 +1,14 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension"; import { act } from "../../extension";
import { Setting } from "../../settingsManager"; import { Setting } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SettingTreeItem from "./setting"; import SettingTreeItem from "./setting";
import SettingFileTreeItem from "./settingFile";
export default class InputsTreeItem extends TreeItem implements GithubLocalActionsTreeItem { export default class InputsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.inputs'; static contextValue = 'githubLocalActions.inputs';
storageKey = StorageKey.InputFiles;
constructor(public workspaceFolder: WorkspaceFolder, inputs: Setting[]) { constructor(public workspaceFolder: WorkspaceFolder, inputs: Setting[]) {
super('Inputs', TreeItemCollapsibleState.Collapsed); super('Inputs', TreeItemCollapsibleState.Collapsed);
@@ -18,10 +21,19 @@ export default class InputsTreeItem extends TreeItem implements GithubLocalActio
const items: GithubLocalActionsTreeItem[] = []; const items: GithubLocalActionsTreeItem[] = [];
const settings = await act.settingsManager.getSettings(this.workspaceFolder, false); const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);
for (const input of settings.inputs) {
items.push(SettingTreeItem.getInputTreeItem(this.workspaceFolder, input));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())); const inputTreeItems: GithubLocalActionsTreeItem[] = [];
for (const input of settings.inputs) {
inputTreeItems.push(SettingTreeItem.getInputTreeItem(this.workspaceFolder, input));
}
items.push(...inputTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
const inputFileTreeItems: GithubLocalActionsTreeItem[] = [];
for (const inputFile of settings.inputFiles) {
inputFileTreeItems.push(SettingFileTreeItem.getInputTreeItem(this.workspaceFolder, inputFile));
}
items.push(...inputFileTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
return items;
} }
} }

View File

@@ -1,11 +1,14 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension"; import { act } from "../../extension";
import { Setting } from "../../settingsManager"; import { Setting } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SettingTreeItem from "./setting"; import SettingTreeItem from "./setting";
import SettingFileTreeItem from "./settingFile";
export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem { export default class SecretsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.secrets'; static contextValue = 'githubLocalActions.secrets';
storageKey = StorageKey.SecretFiles;
constructor(public workspaceFolder: WorkspaceFolder, secrets: Setting[]) { constructor(public workspaceFolder: WorkspaceFolder, secrets: Setting[]) {
super('Secrets', TreeItemCollapsibleState.Collapsed); super('Secrets', TreeItemCollapsibleState.Collapsed);
@@ -18,10 +21,19 @@ export default class SecretsTreeItem extends TreeItem implements GithubLocalActi
const items: GithubLocalActionsTreeItem[] = []; const items: GithubLocalActionsTreeItem[] = [];
const settings = await act.settingsManager.getSettings(this.workspaceFolder, false); const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);
for (const secret of settings.secrets) {
items.push(SettingTreeItem.getSecretTreeItem(this.workspaceFolder, secret));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())); const secretTreeItems: GithubLocalActionsTreeItem[] = [];
for (const secret of settings.secrets) {
secretTreeItems.push(SettingTreeItem.getSecretTreeItem(this.workspaceFolder, secret));
}
items.push(...secretTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
const secretFileTreeItems: GithubLocalActionsTreeItem[] = [];
for (const secretFile of settings.secretFiles) {
secretFileTreeItems.push(SettingFileTreeItem.getSecretTreeItem(this.workspaceFolder, secretFile));
}
items.push(...secretFileTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
return items;
} }
} }

View File

@@ -36,7 +36,8 @@ export default class SettingTreeItem extends TreeItem implements GithubLocalActi
static getVariableTreeItem(workspaceFolder: WorkspaceFolder, variable: Setting): SettingTreeItem { static getVariableTreeItem(workspaceFolder: WorkspaceFolder, variable: Setting): SettingTreeItem {
return new SettingTreeItem( return new SettingTreeItem(
workspaceFolder, workspaceFolder,
variable, StorageKey.Variables, variable,
StorageKey.Variables,
{ {
contextValue: 'githubLocalActions.variable', contextValue: 'githubLocalActions.variable',
iconPath: new ThemeIcon('symbol-variable') iconPath: new ThemeIcon('symbol-variable')
@@ -47,7 +48,8 @@ export default class SettingTreeItem extends TreeItem implements GithubLocalActi
static getInputTreeItem(workspaceFolder: WorkspaceFolder, input: Setting): SettingTreeItem { static getInputTreeItem(workspaceFolder: WorkspaceFolder, input: Setting): SettingTreeItem {
return new SettingTreeItem( return new SettingTreeItem(
workspaceFolder, workspaceFolder,
input, StorageKey.Inputs, input,
StorageKey.Inputs,
{ {
contextValue: 'githubLocalActions.input', contextValue: 'githubLocalActions.input',
iconPath: new ThemeIcon('symbol-parameter') iconPath: new ThemeIcon('symbol-parameter')
@@ -58,7 +60,8 @@ export default class SettingTreeItem extends TreeItem implements GithubLocalActi
static getRunnerTreeItem(workspaceFolder: WorkspaceFolder, runner: Setting): SettingTreeItem { static getRunnerTreeItem(workspaceFolder: WorkspaceFolder, runner: Setting): SettingTreeItem {
return new SettingTreeItem( return new SettingTreeItem(
workspaceFolder, workspaceFolder,
runner, StorageKey.Runners, runner,
StorageKey.Runners,
{ {
contextValue: 'githubLocalActions.runner', contextValue: 'githubLocalActions.runner',
iconPath: new ThemeIcon('vm-connect') iconPath: new ThemeIcon('vm-connect')

View File

@@ -0,0 +1,59 @@
import { ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { SettingFile } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class SettingFileTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
settingFile: SettingFile;
storageKey: StorageKey;
constructor(public workspaceFolder: WorkspaceFolder, settingFile: SettingFile, storageKey: StorageKey, treeItem: { contextValue: string, iconPath: ThemeIcon }) {
super(settingFile.name, TreeItemCollapsibleState.None);
this.settingFile = settingFile;
this.storageKey = storageKey;
this.description = settingFile.path;
this.contextValue = treeItem.contextValue;
this.iconPath = treeItem.iconPath;
this.checkboxState = settingFile.selected ? TreeItemCheckboxState.Checked : TreeItemCheckboxState.Unchecked;
}
static getSecretTreeItem(workspaceFolder: WorkspaceFolder, secretFile: SettingFile): SettingFileTreeItem {
return new SettingFileTreeItem(
workspaceFolder,
secretFile,
StorageKey.SecretFiles,
{
contextValue: 'githubLocalActions.secretFile',
iconPath: new ThemeIcon('gist-secret')
}
);
}
static getVariableTreeItem(workspaceFolder: WorkspaceFolder, variableFile: SettingFile): SettingFileTreeItem {
return new SettingFileTreeItem(
workspaceFolder,
variableFile,
StorageKey.VariableFiles,
{
contextValue: 'githubLocalActions.variableFile',
iconPath: new ThemeIcon('file')
}
);
}
static getInputTreeItem(workspaceFolder: WorkspaceFolder, inputFile: SettingFile): SettingFileTreeItem {
return new SettingFileTreeItem(
workspaceFolder,
inputFile,
StorageKey.InputFiles,
{
contextValue: 'githubLocalActions.inputFile',
iconPath: new ThemeIcon('file')
}
);
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -1,9 +1,14 @@
import * as path from "path";
import { CancellationToken, commands, EventEmitter, ExtensionContext, QuickPickItem, QuickPickItemKind, ThemeIcon, TreeCheckboxChangeEvent, TreeDataProvider, TreeItem, TreeItemCheckboxState, window, workspace } from "vscode"; import { CancellationToken, commands, EventEmitter, ExtensionContext, QuickPickItem, QuickPickItemKind, ThemeIcon, TreeCheckboxChangeEvent, TreeDataProvider, TreeItem, TreeItemCheckboxState, window, workspace } from "vscode";
import { act } from "../../extension"; import { act } from "../../extension";
import { Visibility } from "../../settingsManager"; import { SettingFile, Visibility } from "../../settingsManager";
import { StorageKey } from "../../storageManager"; import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputsTreeItem from "./inputs";
import SecretsTreeItem from "./secrets";
import SettingTreeItem from "./setting"; import SettingTreeItem from "./setting";
import SettingFileTreeItem from "./settingFile";
import VariablesTreeItem from "./variables";
import WorkspaceFolderSettingsTreeItem from "./workspaceFolderSettings"; import WorkspaceFolderSettingsTreeItem from "./workspaceFolderSettings";
export default class SettingsTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> { export default class SettingsTreeDataProvider implements TreeDataProvider<GithubLocalActionsTreeItem> {
@@ -15,6 +20,56 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
context.subscriptions.push( context.subscriptions.push(
commands.registerCommand('githubLocalActions.refreshSettings', async () => { commands.registerCommand('githubLocalActions.refreshSettings', async () => {
this.refresh(); this.refresh();
}),
commands.registerCommand('githubLocalActions.addSettingFiles', async (treeItem: SecretsTreeItem | VariablesTreeItem | InputsTreeItem, title: string) => {
const settingFilesUris = await window.showOpenDialog({
title: title,
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: true,
defaultUri: treeItem.workspaceFolder.uri
});
if (settingFilesUris) {
const settingFilesPaths = (await act.settingsManager.getSettingFiles(treeItem.workspaceFolder, treeItem.storageKey)).map(settingFile => settingFile.path);
const existingSettingFileNames: string[] = [];
for await (const uri of settingFilesUris) {
const settingFileName = path.parse(uri.fsPath).name;
if (settingFilesPaths.includes(uri.fsPath)) {
existingSettingFileNames.push(settingFileName);
} else {
const newSettingFile: SettingFile = {
name: path.parse(uri.fsPath).name,
path: uri.fsPath,
selected: false
};
await act.settingsManager.editSettingFile(treeItem.workspaceFolder, newSettingFile, treeItem.storageKey);
}
}
if (existingSettingFileNames.length > 0) {
window.showErrorMessage(`The following file(s) have already been added: ${existingSettingFileNames.join(', ')}`);
}
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.addSecretFiles', async (secretsTreeItem: SecretsTreeItem) => {
await commands.executeCommand('githubLocalActions.addSettingFiles', secretsTreeItem, 'Add Secret File');
}),
commands.registerCommand('githubLocalActions.addVariableFiles', async (variablesTreeItem: VariablesTreeItem) => {
await commands.executeCommand('githubLocalActions.addSettingFiles', variablesTreeItem, 'Add Variable File');
}),
commands.registerCommand('githubLocalActions.addInputFiles', async (inputsTreeItem: InputsTreeItem) => {
await commands.executeCommand('githubLocalActions.addSettingFiles', inputsTreeItem, 'Add Input File');
}),
commands.registerCommand('githubLocalActions.openSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
const document = await workspace.openTextDocument(settingFileTreeItem.settingFile.path);
await window.showTextDocument(document);
}),
commands.registerCommand('githubLocalActions.removeSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
}), }),
commands.registerCommand('githubLocalActions.show', async (settingTreeItem: SettingTreeItem) => { commands.registerCommand('githubLocalActions.show', async (settingTreeItem: SettingTreeItem) => {
const newSetting = settingTreeItem.setting; const newSetting = settingTreeItem.setting;
@@ -167,11 +222,17 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
return element; return element;
} }
async onDidChangeCheckboxState(event: TreeCheckboxChangeEvent<SettingTreeItem>) { async onDidChangeCheckboxState(event: TreeCheckboxChangeEvent<SettingTreeItem | SettingFileTreeItem>) {
for await (const [treeItem, state] of event.items) { for await (const [treeItem, state] of event.items) {
const newSetting = treeItem.setting; if (treeItem instanceof SettingTreeItem) {
newSetting.selected = (state === TreeItemCheckboxState.Checked); const newSetting = treeItem.setting;
await act.settingsManager.editSetting(treeItem.workspaceFolder, newSetting, treeItem.storageKey); newSetting.selected = (state === TreeItemCheckboxState.Checked);
await act.settingsManager.editSetting(treeItem.workspaceFolder, newSetting, treeItem.storageKey);
} else {
const newSettingFile = treeItem.settingFile;
newSettingFile.selected = (state === TreeItemCheckboxState.Checked);
await act.settingsManager.editSettingFile(treeItem.workspaceFolder, newSettingFile, treeItem.storageKey);
}
} }
this.refresh(); this.refresh();
} }

View File

@@ -1,11 +1,14 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension"; import { act } from "../../extension";
import { Setting } from "../../settingsManager"; import { Setting } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SettingTreeItem from "./setting"; import SettingTreeItem from "./setting";
import SettingFileTreeItem from "./settingFile";
export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem { export default class VariablesTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.variables'; static contextValue = 'githubLocalActions.variables';
storageKey = StorageKey.VariableFiles;
constructor(public workspaceFolder: WorkspaceFolder, variables: Setting[]) { constructor(public workspaceFolder: WorkspaceFolder, variables: Setting[]) {
super('Variables', TreeItemCollapsibleState.Collapsed); super('Variables', TreeItemCollapsibleState.Collapsed);
@@ -18,10 +21,19 @@ export default class VariablesTreeItem extends TreeItem implements GithubLocalAc
const items: GithubLocalActionsTreeItem[] = []; const items: GithubLocalActionsTreeItem[] = [];
const settings = await act.settingsManager.getSettings(this.workspaceFolder, false); const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);
for (const variable of settings.variables) {
items.push(SettingTreeItem.getVariableTreeItem(this.workspaceFolder, variable));
}
return items.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())); const variableTreeItems: GithubLocalActionsTreeItem[] = [];
for (const variable of settings.variables) {
variableTreeItems.push(SettingTreeItem.getVariableTreeItem(this.workspaceFolder, variable));
}
items.push(...variableTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
const variableFileTreeItems: GithubLocalActionsTreeItem[] = [];
for (const variableFile of settings.variableFiles) {
variableFileTreeItems.push(SettingFileTreeItem.getVariableTreeItem(this.workspaceFolder, variableFile));
}
items.push(...variableFileTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));
return items;
} }
} }