Add actions to remove and delete setting files
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
15
package.json
15
package.json
@@ -288,6 +288,12 @@
|
|||||||
"title": "Remove",
|
"title": "Remove",
|
||||||
"icon": "$(close)"
|
"icon": "$(close)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"category": "GitHub Local Actions",
|
||||||
|
"command": "githubLocalActions.deleteSettingFile",
|
||||||
|
"title": "Delete",
|
||||||
|
"icon": "$(trash)"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"category": "GitHub Local Actions",
|
"category": "GitHub Local Actions",
|
||||||
"command": "githubLocalActions.editSetting",
|
"command": "githubLocalActions.editSetting",
|
||||||
@@ -414,6 +420,10 @@
|
|||||||
"command": "githubLocalActions.removeSettingFile",
|
"command": "githubLocalActions.removeSettingFile",
|
||||||
"when": "never"
|
"when": "never"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "githubLocalActions.deleteSettingFile",
|
||||||
|
"when": "never"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "githubLocalActions.editSetting",
|
"command": "githubLocalActions.editSetting",
|
||||||
"when": "never"
|
"when": "never"
|
||||||
@@ -585,6 +595,11 @@
|
|||||||
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
|
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
|
||||||
"group": "inline@1"
|
"group": "inline@1"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "githubLocalActions.deleteSettingFile",
|
||||||
|
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
|
||||||
|
"group": "inline@2"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "githubLocalActions.editSetting",
|
"command": "githubLocalActions.editSetting",
|
||||||
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|runner)(?!(File|s)).*/",
|
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|runner)(?!(File|s)).*/",
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ export class Act {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await workspace.fs.createDirectory(this.context.globalStorageUri);
|
await workspace.fs.createDirectory(this.context.globalStorageUri);
|
||||||
} catch (error) { }
|
} catch (error: any) { }
|
||||||
|
|
||||||
// Build command with settings
|
// Build command with settings
|
||||||
const settings = await this.settingsManager.getSettings(workspaceFolder, true);
|
const settings = await this.settingsManager.getSettings(workspaceFolder, true);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export class GitHubManager {
|
|||||||
private async getSession(): Promise<AuthenticationSession | undefined> {
|
private async getSession(): Promise<AuthenticationSession | undefined> {
|
||||||
try {
|
try {
|
||||||
return await authentication.getSession('github', ['repo'], { createIfNone: true });
|
return await authentication.getSession('github', ['repo'], { createIfNone: true });
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
window.showErrorMessage(`Failed to authenticate to GitHub. Error ${error}`);
|
window.showErrorMessage(`Failed to authenticate to GitHub. Error ${error}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class HistoryManager {
|
|||||||
for (const history of existingHistory) {
|
for (const history of existingHistory) {
|
||||||
try {
|
try {
|
||||||
await workspace.fs.delete(Uri.file(history.logPath));
|
await workspace.fs.delete(Uri.file(history.logPath));
|
||||||
} catch (error) { }
|
} catch (error: any) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
|
this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
|
||||||
@@ -60,7 +60,7 @@ export class HistoryManager {
|
|||||||
try {
|
try {
|
||||||
const document = await workspace.openTextDocument(history.logPath);
|
const document = await workspace.openTextDocument(history.logPath);
|
||||||
await window.showTextDocument(document);
|
await window.showTextDocument(document);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
window.showErrorMessage(`${history.name} #${history.count} log file not found`);
|
window.showErrorMessage(`${history.name} #${history.count} log file not found`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,11 +75,13 @@ export class HistoryManager {
|
|||||||
|
|
||||||
async remove(history: History) {
|
async remove(history: History) {
|
||||||
const historyIndex = this.workspaceHistory[history.commandArgs.path].findIndex(workspaceHistory => workspaceHistory.index === history.index);
|
const historyIndex = this.workspaceHistory[history.commandArgs.path].findIndex(workspaceHistory => workspaceHistory.index === history.index);
|
||||||
|
if (historyIndex > -1) {
|
||||||
this.workspaceHistory[history.commandArgs.path].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 {
|
||||||
await workspace.fs.delete(Uri.file(history.logPath));
|
await workspace.fs.delete(Uri.file(history.logPath));
|
||||||
} catch (error) { }
|
} catch (error: any) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { WorkspaceFolder } from "vscode";
|
import { Uri, window, workspace, WorkspaceFolder } from "vscode";
|
||||||
import { act } from "./extension";
|
import { act } from "./extension";
|
||||||
import { GitHubManager } from "./githubManager";
|
import { GitHubManager } from "./githubManager";
|
||||||
import { SecretManager } from "./secretManager";
|
import { SecretManager } from "./secretManager";
|
||||||
@@ -169,6 +169,27 @@ export class SettingsManager {
|
|||||||
await this.storageManager.update(storageKey, existingSettingFiles);
|
await this.storageManager.update(storageKey, existingSettingFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeSettingFile(workspaceFolder: WorkspaceFolder, settingFile: SettingFile, storageKey: StorageKey) {
|
||||||
|
const existingSettingFiles = this.storageManager.get<{ [path: string]: SettingFile[] }>(storageKey) || {};
|
||||||
|
if (existingSettingFiles[workspaceFolder.uri.fsPath]) {
|
||||||
|
const settingFileIndex = existingSettingFiles[workspaceFolder.uri.fsPath].findIndex(settingFile => settingFile.path === settingFile.path);
|
||||||
|
if (settingFileIndex > -1) {
|
||||||
|
existingSettingFiles[workspaceFolder.uri.fsPath].splice(settingFileIndex, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.storageManager.update(storageKey, existingSettingFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteSettingFile(workspaceFolder: WorkspaceFolder, settingFile: SettingFile, storageKey: StorageKey) {
|
||||||
|
try {
|
||||||
|
await workspace.fs.delete(Uri.file(settingFile.path));
|
||||||
|
await this.removeSettingFile(workspaceFolder, settingFile, storageKey);
|
||||||
|
} catch (error: any) {
|
||||||
|
window.showErrorMessage(`Failed to delete file. Error ${error}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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, SettingFile } from "../../settingsManager";
|
||||||
import { StorageKey } from "../../storageManager";
|
import { StorageKey } from "../../storageManager";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
import SettingTreeItem from "./setting";
|
import SettingTreeItem from "./setting";
|
||||||
@@ -10,9 +10,10 @@ export default class InputsTreeItem extends TreeItem implements GithubLocalActio
|
|||||||
static contextValue = 'githubLocalActions.inputs';
|
static contextValue = 'githubLocalActions.inputs';
|
||||||
storageKey = StorageKey.InputFiles;
|
storageKey = StorageKey.InputFiles;
|
||||||
|
|
||||||
constructor(public workspaceFolder: WorkspaceFolder, inputs: Setting[]) {
|
constructor(public workspaceFolder: WorkspaceFolder, inputs: Setting[], inputFiles: SettingFile[]) {
|
||||||
super('Inputs', TreeItemCollapsibleState.Collapsed);
|
super('Inputs', TreeItemCollapsibleState.Collapsed);
|
||||||
this.description = `${inputs.filter(input => input.selected).length}/${inputs.length}`;
|
this.description = `${inputs.filter(input => input.selected).length}/${inputs.length}` +
|
||||||
|
(inputFiles.length > 0 ? ` + ${inputFiles.length} input file(s)` : ``);
|
||||||
this.contextValue = InputsTreeItem.contextValue;
|
this.contextValue = InputsTreeItem.contextValue;
|
||||||
this.iconPath = new ThemeIcon('record-keys');
|
this.iconPath = new ThemeIcon('record-keys');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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, SettingFile } from "../../settingsManager";
|
||||||
import { StorageKey } from "../../storageManager";
|
import { StorageKey } from "../../storageManager";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
import SettingTreeItem from "./setting";
|
import SettingTreeItem from "./setting";
|
||||||
@@ -10,9 +10,10 @@ export default class SecretsTreeItem extends TreeItem implements GithubLocalActi
|
|||||||
static contextValue = 'githubLocalActions.secrets';
|
static contextValue = 'githubLocalActions.secrets';
|
||||||
storageKey = StorageKey.SecretFiles;
|
storageKey = StorageKey.SecretFiles;
|
||||||
|
|
||||||
constructor(public workspaceFolder: WorkspaceFolder, secrets: Setting[]) {
|
constructor(public workspaceFolder: WorkspaceFolder, secrets: Setting[], secretFiles: SettingFile[]) {
|
||||||
super('Secrets', TreeItemCollapsibleState.Collapsed);
|
super('Secrets', TreeItemCollapsibleState.Collapsed);
|
||||||
this.description = `${secrets.filter(secret => secret.selected).length}/${secrets.length}`;
|
this.description = `${secrets.filter(secret => secret.selected).length}/${secrets.length}` +
|
||||||
|
(secretFiles.length > 0 ? ` + ${secretFiles.length} secret file(s)` : ``);
|
||||||
this.contextValue = SecretsTreeItem.contextValue;
|
this.contextValue = SecretsTreeItem.contextValue;
|
||||||
this.iconPath = new ThemeIcon('lock');
|
this.iconPath = new ThemeIcon('lock');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
|||||||
await window.showTextDocument(document);
|
await window.showTextDocument(document);
|
||||||
}),
|
}),
|
||||||
commands.registerCommand('githubLocalActions.removeSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
|
commands.registerCommand('githubLocalActions.removeSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
|
||||||
|
await act.settingsManager.removeSettingFile(settingFileTreeItem.workspaceFolder, settingFileTreeItem.settingFile, settingFileTreeItem.storageKey);
|
||||||
|
this.refresh();
|
||||||
|
}),
|
||||||
|
commands.registerCommand('githubLocalActions.deleteSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
|
||||||
|
await act.settingsManager.deleteSettingFile(settingFileTreeItem.workspaceFolder, settingFileTreeItem.settingFile, settingFileTreeItem.storageKey);
|
||||||
|
this.refresh();
|
||||||
}),
|
}),
|
||||||
commands.registerCommand('githubLocalActions.show', async (settingTreeItem: SettingTreeItem) => {
|
commands.registerCommand('githubLocalActions.show', async (settingTreeItem: SettingTreeItem) => {
|
||||||
const newSetting = settingTreeItem.setting;
|
const newSetting = settingTreeItem.setting;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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, SettingFile } from "../../settingsManager";
|
||||||
import { StorageKey } from "../../storageManager";
|
import { StorageKey } from "../../storageManager";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
import SettingTreeItem from "./setting";
|
import SettingTreeItem from "./setting";
|
||||||
@@ -10,9 +10,10 @@ export default class VariablesTreeItem extends TreeItem implements GithubLocalAc
|
|||||||
static contextValue = 'githubLocalActions.variables';
|
static contextValue = 'githubLocalActions.variables';
|
||||||
storageKey = StorageKey.VariableFiles;
|
storageKey = StorageKey.VariableFiles;
|
||||||
|
|
||||||
constructor(public workspaceFolder: WorkspaceFolder, variables: Setting[]) {
|
constructor(public workspaceFolder: WorkspaceFolder, variables: Setting[], variableFiles: SettingFile[]) {
|
||||||
super('Variables', TreeItemCollapsibleState.Collapsed);
|
super('Variables', TreeItemCollapsibleState.Collapsed);
|
||||||
this.description = `${variables.filter(variable => variable.selected).length}/${variables.length}`;
|
this.description = `${variables.filter(variable => variable.selected).length}/${variables.length}` +
|
||||||
|
(variableFiles.length > 0 ? ` + ${variableFiles.length} variable file(s)` : ``);
|
||||||
this.contextValue = VariablesTreeItem.contextValue;
|
this.contextValue = VariablesTreeItem.contextValue;
|
||||||
this.iconPath = new ThemeIcon('symbol-key');
|
this.iconPath = new ThemeIcon('symbol-key');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ export default class WorkspaceFolderSettingsTreeItem extends TreeItem implements
|
|||||||
|
|
||||||
const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);
|
const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);
|
||||||
items.push(...[
|
items.push(...[
|
||||||
new SecretsTreeItem(this.workspaceFolder, settings.secrets),
|
new SecretsTreeItem(this.workspaceFolder, settings.secrets, settings.secretFiles),
|
||||||
new VariablesTreeItem(this.workspaceFolder, settings.variables),
|
new VariablesTreeItem(this.workspaceFolder, settings.variables, settings.variableFiles),
|
||||||
new InputsTreeItem(this.workspaceFolder, settings.inputs),
|
new InputsTreeItem(this.workspaceFolder, settings.inputs, settings.inputFiles),
|
||||||
new RunnersTreeItem(this.workspaceFolder, settings.runners)
|
new RunnersTreeItem(this.workspaceFolder, settings.runners)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class WorkflowsManager {
|
|||||||
fileContent: fileContent,
|
fileContent: fileContent,
|
||||||
yaml: yaml.parse(fileContent)
|
yaml: yaml.parse(fileContent)
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
workflows.push({
|
workflows.push({
|
||||||
name: (yamlContent ? yamlContent.name : undefined) || path.parse(workflowFileUri.fsPath).name,
|
name: (yamlContent ? yamlContent.name : undefined) || path.parse(workflowFileUri.fsPath).name,
|
||||||
uri: workflowFileUri,
|
uri: workflowFileUri,
|
||||||
|
|||||||
Reference in New Issue
Block a user