diff --git a/package.json b/package.json index 656d7c0..25de732 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,12 @@ "title": "Run All Workflows", "icon": "$(run-all)" }, + { + "category": "GitHub Local Actions", + "command": "githubLocalActions.runEvent", + "title": "Run Event", + "icon": "$(symbol-event)" + }, { "category": "GitHub Local Actions", "command": "githubLocalActions.refreshWorkflows", @@ -107,6 +113,10 @@ "command": "githubLocalActions.runAllWorkflows", "when": "never" }, + { + "command": "githubLocalActions.runEvent", + "when": "never" + }, { "command": "githubLocalActions.refreshWorkflows", "when": "never" @@ -136,10 +146,15 @@ "group": "navigation@0" }, { - "command": "githubLocalActions.refreshWorkflows", + "command": "githubLocalActions.runEvent", "when": "view == workflows", "group": "navigation@1" }, + { + "command": "githubLocalActions.refreshWorkflows", + "when": "view == workflows", + "group": "navigation@2" + }, { "command": "githubLocalActions.refreshSettings", "when": "view == settings", @@ -161,24 +176,24 @@ }, "colors": [ { - "id": "GitHubLocalActions.enabled", - "description": "Color for a component success state", + "id": "GitHubLocalActions.green", + "description": "Color for green in GitHub Local Actions extension", "defaults": { "dark": "#89d185", "light": "#89d185" } }, { - "id": "GitHubLocalActions.warning", - "description": "Color for a component warning state", + "id": "GitHubLocalActions.yellow", + "description": "Color for yellow in GitHub Local Actions extension", "defaults": { "dark": "#cca700", "light": "#cca700" } }, { - "id": "GitHubLocalActions.disabled", - "description": "Color for a component disabled state", + "id": "GitHubLocalActions.red", + "description": "Color for red in GitHub Local Actions extension", "defaults": { "dark": "#f48771", "light": "#f48771" diff --git a/src/act.ts b/src/act.ts index 5659a99..22cba2a 100644 --- a/src/act.ts +++ b/src/act.ts @@ -1,9 +1,45 @@ import * as path from "path"; -import { commands, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, window, workspace } from "vscode"; +import { commands, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, window } from "vscode"; import { ComponentManager } from "./componentManager"; import { Workflow } from "./workflowManager"; -export enum Options { +export enum EventTrigger { + BranchProtectionRule = 'branch_protection_rule', + CheckRun = 'check_run', + CheckSuite = 'check_suite', + Create = 'create', + Delete = 'delete', + Deployment = 'deployment', + DeploymentStatus = 'deployment_status', + Discussion = 'discussion', + DiscussionComment = 'discussion_comment', + Fork = 'fork', + Gollum = 'gollum', + IssueComment = 'issue_comment', + Issues = 'issues', + Label = 'label', + MergeGroup = 'merge_group', + Milestone = 'milestone', + PageBuild = 'page_build', + Public = 'public', + PullRequest = 'pull_request', + PullRequestComment = 'pull_request_comment', + PullRequestReview = 'pull_request_review', + PullRequestReviewComment = 'pull_request_review_comment', + PullRequestTarget = 'pull_request_target', + Push = 'push', + RegistryPackage = 'registry_package', + Release = 'release', + RepositoryDispatch = 'repository_dispatch', + Schedule = 'schedule', + Status = 'status', + Watch = 'watch', + WorkflowCall = 'workflow_call', + WorkflowDispatch = 'workflow_dispatch', + WorkflowRun = 'workflow_run' +} + +export enum Option { Workflows = '-W' } @@ -14,11 +50,15 @@ export class Act { // TODO: Implement } - static async runWorkflow(workflow: Workflow) { - return await Act.runCommand(workflow, `${Act.base} ${Options.Workflows} '.github/workflows/${path.parse(workflow.uri.fsPath).base}'`); + static async runEvent(eventTrigger: EventTrigger) { + return await Act.runCommand(`${Act.base} ${eventTrigger}`); } - static async runCommand(workflow: Workflow, command: string) { + static async runWorkflow(workflow: Workflow) { + return await Act.runCommand(`${Act.base} ${Option.Workflows} '.github/workflows/${path.parse(workflow.uri.fsPath).base}'`, workflow); + } + + static async runCommand(command: string, workflow?: Workflow) { const unreadyComponents = await ComponentManager.getUnreadyComponents(); if (unreadyComponents.length > 0) { @@ -31,11 +71,11 @@ export class Act { } await tasks.executeTask({ - name: workflow.name, + name: workflow?.name || 'act', detail: 'Run workflow', definition: { type: 'GitHub Local Actions' }, source: 'GitHub Local Actions', - scope: workspace.getWorkspaceFolder(workflow.uri), + scope: TaskScope.Workspace, isBackground: true, presentationOptions: { reveal: TaskRevealKind.Always, diff --git a/src/views/decorationProvider.ts b/src/views/decorationProvider.ts index 870d1e1..e0634e2 100644 --- a/src/views/decorationProvider.ts +++ b/src/views/decorationProvider.ts @@ -12,17 +12,17 @@ export class DecorationProvider implements FileDecorationProvider { if (params.get('status') === Status.Enabled) { return { badge: '✅', - color: new ThemeColor('GitHubLocalActions.enabled') + color: new ThemeColor('GitHubLocalActions.green') }; } else if (params.get('status') === Status.Warning) { return { badge: '⚠️', - color: new ThemeColor('GitHubLocalActions.warning') + color: new ThemeColor('GitHubLocalActions.yellow') }; } else if (params.get('status') === Status.Disabled) { return { badge: '❌', - color: new ThemeColor('GitHubLocalActions.disabled') + color: new ThemeColor('GitHubLocalActions.red') }; } } else if (uri.scheme === WorkflowTreeItem.contextValue) { @@ -30,7 +30,7 @@ export class DecorationProvider implements FileDecorationProvider { if (params.get('error')) { return { badge: '❌', - color: new ThemeColor('GitHubLocalActions.disabled') + color: new ThemeColor('GitHubLocalActions.red') }; } } diff --git a/src/views/workflows/workflowsTreeDataProvider.ts b/src/views/workflows/workflowsTreeDataProvider.ts index ebf63dd..32a04b1 100644 --- a/src/views/workflows/workflowsTreeDataProvider.ts +++ b/src/views/workflows/workflowsTreeDataProvider.ts @@ -1,5 +1,5 @@ import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, window, workspace } from "vscode"; -import { Act } from "../../act"; +import { Act, EventTrigger } from "../../act"; import { WorkflowManager } from "../../workflowManager"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; import WorkflowTreeItem from "./workflow"; @@ -14,6 +14,16 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider { await Act.runAllWorkflows(); }), + commands.registerCommand('githubLocalActions.runEvent', async () => { + const event = await window.showQuickPick(Object.values(EventTrigger), { + title: 'Select the event to run', + placeHolder: 'Event' + }); + + if(event) { + await Act.runEvent(event as EventTrigger); + } + }), commands.registerCommand('githubLocalActions.refreshWorkflows', async () => { this.refresh(); }),