Skip to content

Commit

Permalink
Merge pull request #65 from SanjulaGanepola/feature/payload-file
Browse files Browse the repository at this point in the history
Add payload support
  • Loading branch information
SanjulaGanepola authored Nov 23, 2024
2 parents c4acae4 + e332993 commit 0e3c278
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 16 deletions.
50 changes: 40 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@
"title": "Locate Variable Files",
"icon": "$(search)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.importFromGithub",
"title": "Import from GitHub",
"icon": "$(github)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.createInputFile",
Expand All @@ -290,9 +296,15 @@
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.importFromGithub",
"title": "Import from GitHub",
"icon": "$(github)"
"command": "githubLocalActions.createPayloadFile",
"title": "Create Payload File",
"icon": "$(add)"
},
{
"category": "GitHub Local Actions",
"command": "githubLocalActions.locatePayloadFiles",
"title": "Locate Payload Files",
"icon": "$(search)"
},
{
"category": "GitHub Local Actions",
Expand Down Expand Up @@ -430,6 +442,10 @@
"command": "githubLocalActions.locateVariableFiles",
"when": "never"
},
{
"command": "githubLocalActions.importFromGithub",
"when": "never"
},
{
"command": "githubLocalActions.createInputFile",
"when": "never"
Expand All @@ -439,7 +455,11 @@
"when": "never"
},
{
"command": "githubLocalActions.importFromGithub",
"command": "githubLocalActions.createPayloadFile",
"when": "never"
},
{
"command": "githubLocalActions.locatePayloadFiles",
"when": "never"
},
{
Expand Down Expand Up @@ -615,6 +635,11 @@
"when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/",
"group": "inline@1"
},
{
"command": "githubLocalActions.importFromGithub",
"when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/",
"group": "inline@2"
},
{
"command": "githubLocalActions.createInputFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.inputs.*/",
Expand All @@ -626,23 +651,28 @@
"group": "inline@1"
},
{
"command": "githubLocalActions.importFromGithub",
"when": "view == settings && viewItem =~ /^githubLocalActions.variables.*/",
"group": "inline@2"
"command": "githubLocalActions.createPayloadFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.payloads.*/",
"group": "inline@0"
},
{
"command": "githubLocalActions.locatePayloadFiles",
"when": "view == settings && viewItem =~ /^githubLocalActions.payloads.*/",
"group": "inline@1"
},
{
"command": "githubLocalActions.openSettingFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|payload)File.*/",
"group": "inline@0"
},
{
"command": "githubLocalActions.removeSettingFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|payload)File.*/",
"group": "inline@1"
},
{
"command": "githubLocalActions.deleteSettingFile",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input)File.*/",
"when": "view == settings && viewItem =~ /^githubLocalActions.(secret|variable|input|payload)File.*/",
"group": "inline@2"
},
{
Expand Down
10 changes: 6 additions & 4 deletions src/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ export enum Event {
}

export enum Option {
Workflows = '-W',
Job = '-j',
Platform = '-P',
Workflows = '--workflows',
Job = '--job',
Platform = '--platform',
Secret = '--secret',
SecretFile = '--secret-file',
Variable = '--var',
VariableFile = '--var-file',
Input = '--input',
InputFile = '--input-file'
InputFile = '--input-file',
PayloadFile = '--eventpath'
}

export interface CommandArgs {
Expand Down Expand Up @@ -315,6 +316,7 @@ export class Act {
(settings.inputs.length > 0 ? ` ${Option.Input} ${settings.inputs.map(input => `${input.key}=${input.value}`).join(` ${Option.Input} `)}` : ``) +
(settings.inputFiles.length > 0 ? ` ${Option.InputFile} "${settings.inputFiles[0].path}"` : ` ${Option.InputFile} ""`) +
(settings.runners.length > 0 ? ` ${Option.Platform} ${settings.runners.map(runner => `${runner.key}=${runner.value}`).join(` ${Option.Platform} `)}` : ``) +
(settings.payloadFiles.length > 0 ? ` ${Option.PayloadFile} "${settings.payloadFiles[0].path}"` : ` ${Option.PayloadFile} ""`) +
` 2>&1 | tee "${logPath}"`;

// Execute task
Expand Down
6 changes: 5 additions & 1 deletion src/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Settings {
inputs: Setting[];
inputFiles: SettingFile[];
runners: Setting[];
payloadFiles: SettingFile[];
environments: Setting[];
}

Expand All @@ -38,7 +39,8 @@ export enum Visibility {
export enum SettingFileName {
secretFile = '.secrets',
variableFile = '.env',
inputFile = '.input'
inputFile = '.input',
payloadFile = 'payload.json'
}

export class SettingsManager {
Expand All @@ -64,6 +66,7 @@ export class SettingsManager {
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)).filter(inputFile => !isUserSelected || inputFile.selected);
const runners = (await this.getSetting(workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners, false, Visibility.show)).filter(runner => !isUserSelected || (runner.selected && runner.value));
const payloadFiles = (await this.getSettingFiles(workspaceFolder, StorageKey.PayloadFiles)).filter(payloadFile => !isUserSelected || payloadFile.selected);
const environments = await this.getEnvironments(workspaceFolder);

return {
Expand All @@ -74,6 +77,7 @@ export class SettingsManager {
inputs: inputs,
inputFiles: inputFiles,
runners: runners,
payloadFiles: payloadFiles,
environments: environments
};
}
Expand Down
1 change: 1 addition & 0 deletions src/storageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum StorageKey {
VariableFiles = 'variableFiles',
Inputs = 'inputs',
InputFiles = 'inputFiles',
PayloadFiles = 'PayloadFiles',
Runners = 'runners'
}

Expand Down
33 changes: 33 additions & 0 deletions src/views/settings/payloads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { act } from "../../extension";
import { SettingFile } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import SettingFileTreeItem from "./settingFile";

export default class PayloadsTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.payloads';
storageKey = StorageKey.PayloadFiles;

constructor(public workspaceFolder: WorkspaceFolder, payloadFiles: SettingFile[]) {
super('Payloads', TreeItemCollapsibleState.Collapsed);
const selectedPayloadFiles = payloadFiles.filter(payloadFile => payloadFile.selected);
this.description = selectedPayloadFiles.length > 0 ? `${selectedPayloadFiles[0].name}` : ``;
this.contextValue = PayloadsTreeItem.contextValue;
this.iconPath = new ThemeIcon('json');
}

async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
const items: GithubLocalActionsTreeItem[] = [];

const settings = await act.settingsManager.getSettings(this.workspaceFolder, false);

const payloadFileTreeItems: GithubLocalActionsTreeItem[] = [];
for (const payloadFile of settings.payloadFiles) {
payloadFileTreeItems.push(SettingFileTreeItem.getPayloadTreeItem(this.workspaceFolder, payloadFile));
}
items.push(...payloadFileTreeItems.sort((a, b) => a.label!.toString().localeCompare(b.label!.toString())));

return items;
}
}
12 changes: 12 additions & 0 deletions src/views/settings/settingFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export default class SettingFileTreeItem extends TreeItem implements GithubLocal
);
}

static getPayloadTreeItem(workspaceFolder: WorkspaceFolder, payloadFile: SettingFile): SettingFileTreeItem {
return new SettingFileTreeItem(
workspaceFolder,
payloadFile,
StorageKey.PayloadFiles,
{
contextValue: 'githubLocalActions.payloadFile',
iconPath: new ThemeIcon('file')
}
);
}

async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
Expand Down
27 changes: 27 additions & 0 deletions src/views/settings/settingsTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SettingFileName, Visibility } from "../../settingsManager";
import { StorageKey } from "../../storageManager";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputsTreeItem from "./inputs";
import PayloadsTreeItem from "./payloads";
import SecretsTreeItem from "./secrets";
import SettingTreeItem from "./setting";
import SettingFileTreeItem from "./settingFile";
Expand Down Expand Up @@ -98,6 +99,32 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.createPayloadFile', async (payloadsTreeItem: PayloadsTreeItem) => {
const payloadFileName = await window.showInputBox({
prompt: `Enter the name for the payload file`,
placeHolder: `Payload File Name`,
value: SettingFileName.payloadFile
});

if (payloadFileName) {
await act.settingsManager.createSettingFile(payloadsTreeItem.workspaceFolder, payloadsTreeItem.storageKey, payloadFileName);
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.locatePayloadFiles', async (payloadsTreeItem: PayloadsTreeItem) => {
const payloadFilesUris = await window.showOpenDialog({
title: 'Locate Payload Files',
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: true,
defaultUri: payloadsTreeItem.workspaceFolder.uri
});

if (payloadFilesUris) {
await act.settingsManager.locateSettingFile(payloadsTreeItem.workspaceFolder, payloadsTreeItem.storageKey, payloadFilesUris);
this.refresh();
}
}),
commands.registerCommand('githubLocalActions.openSettingFile', async (settingFileTreeItem: SettingFileTreeItem) => {
const document = await workspace.openTextDocument(settingFileTreeItem.settingFile.path);
await window.showTextDocument(document);
Expand Down
4 changes: 3 additions & 1 deletion src/views/settings/workspaceFolderSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "
import { act } from "../../extension";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import InputsTreeItem from "./inputs";
import PayloadsTreeItem from "./payloads";
import RunnersTreeItem from "./runners";
import SecretsTreeItem from "./secrets";
import VariablesTreeItem from "./variables";
Expand All @@ -23,7 +24,8 @@ export default class WorkspaceFolderSettingsTreeItem extends TreeItem implements
new SecretsTreeItem(this.workspaceFolder, settings.secrets, settings.secretFiles),
new VariablesTreeItem(this.workspaceFolder, settings.variables, settings.variableFiles),
new InputsTreeItem(this.workspaceFolder, settings.inputs, settings.inputFiles),
new RunnersTreeItem(this.workspaceFolder, settings.runners)
new RunnersTreeItem(this.workspaceFolder, settings.runners),
new PayloadsTreeItem(this.workspaceFolder, settings.payloadFiles)
]);

return items;
Expand Down

0 comments on commit 0e3c278

Please sign in to comment.