11import * as vscode from "vscode" ;
2- import { enableOrgFeatures } from "./auth/auth" ;
3- import { initConfiguration } from "./configuration/configuration" ;
4- import { getGitHubContext , GitHubContext } from "./git/repository" ;
5- import { LogScheme } from "./logs/constants" ;
6- import { WorkflowStepLogProvider } from "./logs/fileProvider" ;
7- import { WorkflowStepLogFoldingProvider } from "./logs/foldingProvider" ;
8- import { updateDecorations } from "./logs/formatProvider" ;
9- import { getLogInfo } from "./logs/logInfoProvider" ;
10- import { buildLogURI } from "./logs/scheme" ;
11- import { WorkflowStepLogSymbolProvider } from "./logs/symbolProvider" ;
2+
3+ import { GitHubContext , getGitHead , getGitHubContext } from "./git/repository" ;
124import {
135 OrgSecret ,
146 RepoSecret ,
@@ -17,17 +9,24 @@ import {
179 WorkflowRun ,
1810 WorkflowStep ,
1911} from "./model" ;
20- import { initPinnedWorkflows } from "./pinnedWorkflows/pinnedWorkflows" ;
21- import { encodeSecret } from "./secrets" ;
22- import { initWorkflowDocumentTracking } from "./tracker/workflowDocumentTracker" ;
23- import { initResources } from "./treeViews/icons" ;
12+ import { getWorkflowUri , parseWorkflow } from "./workflow/workflow" ;
13+
14+ import { LogScheme } from "./logs/constants" ;
2415import { SettingsTreeProvider } from "./treeViews/settings" ;
16+ import { WorkflowStepLogFoldingProvider } from "./logs/foldingProvider" ;
17+ import { WorkflowStepLogProvider } from "./logs/fileProvider" ;
18+ import { WorkflowStepLogSymbolProvider } from "./logs/symbolProvider" ;
2519import { ActionsExplorerProvider as WorkflowsTreeProvider } from "./treeViews/workflows" ;
20+ import { buildLogURI } from "./logs/scheme" ;
21+ import { enableOrgFeatures } from "./auth/auth" ;
22+ import { encodeSecret } from "./secrets" ;
23+ import { getLogInfo } from "./logs/logInfoProvider" ;
2624import { init } from "./workflow/diagnostics" ;
27- import {
28- getRepositoryDispatchTypes ,
29- getWorkflowUri ,
30- } from "./workflow/workflow" ;
25+ import { initConfiguration } from "./configuration/configuration" ;
26+ import { initPinnedWorkflows } from "./pinnedWorkflows/pinnedWorkflows" ;
27+ import { initResources } from "./treeViews/icons" ;
28+ import { initWorkflowDocumentTracking } from "./tracker/workflowDocumentTracker" ;
29+ import { updateDecorations } from "./logs/formatProvider" ;
3130
3231export function activate ( context : vscode . ExtensionContext ) {
3332 // Prefetch git repository origin url
@@ -97,10 +96,7 @@ export function activate(context: vscode.ExtensionContext) {
9796 vscode . commands . registerCommand (
9897 "github-actions.explorer.triggerRun" ,
9998 async ( args ) => {
100- let event_type : string | undefined ;
101-
10299 let workflowUri : vscode . Uri | null = null ;
103-
104100 const wf : Workflow = args . wf ;
105101 if ( wf ) {
106102 workflowUri = getWorkflowUri ( wf . path ) ;
@@ -112,47 +108,130 @@ export function activate(context: vscode.ExtensionContext) {
112108 return ;
113109 }
114110
115- const event_types = getRepositoryDispatchTypes ( workflowUri . fsPath ) ;
116- if ( event_types ?. length > 0 ) {
117- const custom_type = "✐ Enter custom type" ;
118- const selection = await vscode . window . showQuickPick (
119- [ custom_type , ...event_types ] ,
111+ // Parse
112+ const gitHubContext : GitHubContext =
113+ args . gitHubContext || ( await getGitHubContext ( ) ) ;
114+ const workflow = await parseWorkflow ( workflowUri , gitHubContext ) ;
115+ if ( ! workflow ) {
116+ return ;
117+ }
118+
119+ let selectedEvent : string | undefined ;
120+ if (
121+ workflow . on . workflow_dispatch !== undefined &&
122+ workflow . on . repository_dispatch !== undefined
123+ ) {
124+ selectedEvent = await vscode . window . showQuickPick (
125+ [ "repository_dispatch" , "workflow_dispatch" ] ,
120126 {
121- placeHolder : "Select an event_type to dispatch " ,
127+ placeHolder : "Which event to trigger? " ,
122128 }
123129 ) ;
124-
125- if ( selection === undefined ) {
130+ if ( ! selectedEvent ) {
126131 return ;
127- } else if ( selection != custom_type ) {
128- event_type = selection ;
129132 }
130133 }
131134
132- if ( event_type === undefined ) {
133- event_type = await vscode . window . showInputBox ( {
134- prompt : "Enter `event_type` to dispatch to the repository" ,
135- value : "default" ,
135+ if (
136+ ( ! selectedEvent || selectedEvent === "workflow_dispatch" ) &&
137+ workflow . on . workflow_dispatch !== undefined
138+ ) {
139+ const ref = await vscode . window . showInputBox ( {
140+ prompt : "Enter ref to trigger workflow on" ,
141+ value : ( await getGitHead ( ) ) || gitHubContext . defaultBranch ,
136142 } ) ;
137- }
138143
139- if ( event_type ) {
140- const gitHubContext : GitHubContext =
141- args . gitHubContext || ( await getGitHubContext ( ) ) ;
142- await gitHubContext . client . repos . createDispatchEvent ( {
143- owner : gitHubContext . owner ,
144- repo : gitHubContext . name ,
145- event_type,
146- client_payload : { } ,
147- } ) ;
144+ if ( ref ) {
145+ // Inputs
146+ let inputs : { [ key : string ] : string } | undefined ;
147+ const definedInputs = workflow . on . workflow_dispatch . inputs ;
148+ if ( definedInputs ) {
149+ inputs = { } ;
150+
151+ for ( const definedInput of Object . keys ( definedInputs ) ) {
152+ const value = await vscode . window . showInputBox ( {
153+ prompt : `Value for input ${ definedInput } ${
154+ definedInputs [ definedInput ] . required ? "[required]" : ""
155+ } `,
156+ value : definedInputs [ definedInput ] . default ,
157+ } ) ;
158+ if ( ! value && definedInputs [ definedInput ] . required ) {
159+ vscode . window . showErrorMessage (
160+ `Input ${ definedInput } is required`
161+ ) ;
162+ return ;
163+ }
164+
165+ if ( value ) {
166+ inputs [ definedInput ] = value ;
167+ }
168+ }
169+ }
148170
149- vscode . window . setStatusBarMessage (
150- `GitHub Actions: Repository event '${ event_type } ' dispatched` ,
151- 2000
152- ) ;
171+ try {
172+ await gitHubContext . client . actions . createWorkflowDispatch ( {
173+ owner : gitHubContext . owner ,
174+ repo : gitHubContext . name ,
175+ workflow_id : wf . id ,
176+ ref,
177+ inputs,
178+ } ) ;
179+
180+ vscode . window . setStatusBarMessage (
181+ `GitHub Actions: Workflow event dispatched` ,
182+ 2000
183+ ) ;
184+ } catch ( error ) {
185+ vscode . window . showErrorMessage (
186+ `Could not create workflow dispatch: ${ error . message } `
187+ ) ;
188+ }
189+ }
190+ } else if (
191+ ( ! selectedEvent || selectedEvent === "repository_dispatch" ) &&
192+ workflow . on . repository_dispatch !== undefined
193+ ) {
194+ let event_type : string | undefined ;
195+ const event_types = workflow . on . repository_dispatch . types ;
196+ if ( Array . isArray ( event_types ) && event_types ?. length > 0 ) {
197+ const custom_type = "✐ Enter custom type" ;
198+ const selection = await vscode . window . showQuickPick (
199+ [ custom_type , ...event_types ] ,
200+ {
201+ placeHolder : "Select an event_type to dispatch" ,
202+ }
203+ ) ;
204+
205+ if ( selection === undefined ) {
206+ return ;
207+ } else if ( selection != custom_type ) {
208+ event_type = selection ;
209+ }
210+ }
153211
154- workflowTreeProvider . refresh ( ) ;
212+ if ( event_type === undefined ) {
213+ event_type = await vscode . window . showInputBox ( {
214+ prompt : "Enter `event_type` to dispatch to the repository" ,
215+ value : "default" ,
216+ } ) ;
217+ }
218+
219+ if ( event_type ) {
220+ await gitHubContext . client . repos . createDispatchEvent ( {
221+ owner : gitHubContext . owner ,
222+ repo : gitHubContext . name ,
223+ event_type,
224+ client_payload : { } ,
225+ } ) ;
226+
227+ vscode . window . setStatusBarMessage (
228+ `GitHub Actions: Repository event '${ event_type } ' dispatched` ,
229+ 2000
230+ ) ;
231+ }
155232 }
233+
234+ workflowTreeProvider . refresh ( ) ;
156235 }
157236 )
158237 ) ;
0 commit comments