11import * as core from '@actions/core'
22import * as github from '@actions/github'
3+ import { ActionsGetWorkflowResponseData } from '@octokit/types'
34
45// async wrapper function
56async function run ( ) : Promise < void > {
@@ -9,7 +10,9 @@ async function run(): Promise<void> {
910 const workflowName = core . getInput ( 'workflow' )
1011 // Optional inputs, with defaults
1112 const ref = core . getInput ( 'ref' ) || github . context . ref
12- const repo = core . getInput ( 'repo' ) || `${ github . context . repo . owner } /${ github . context . repo . repo } `
13+ const [ owner , repo ] = core . getInput ( 'repo' )
14+ ? core . getInput ( 'repo' ) . split ( '/' )
15+ : [ github . context . repo . owner , github . context . repo . repo ]
1316
1417 // Decode inputs, these MUST be a valid JSON string
1518 let inputs = { }
@@ -22,24 +25,16 @@ async function run(): Promise<void> {
2225 const octokit = github . getOctokit ( token )
2326
2427 // List workflows via API
25- const listResp = await octokit . request ( `GET /repos/${ repo } /actions/workflows` , {
26- ref : ref ,
27- inputs : inputs
28- } )
29- if ( listResp . status != 200 ) throw new Error ( `Got HTTP ${ listResp . status } calling list workflows API 💩` )
30-
31- // Debug response if ACTIONS_STEP_DEBUG is enabled
32- core . debug ( listResp . data )
28+ const workflows : ActionsGetWorkflowResponseData [ ] =
29+ await octokit . paginate ( octokit . actions . listRepoWorkflows . endpoint . merge ( { owner, repo, ref, inputs } ) )
3330
3431 // Locate workflow by name as we need it's id
35- const workflowFind = listResp . data . workflows . find ( ( wf : Record < string , string > ) => {
36- return wf [ 'name' ] === workflowName
37- } )
38- if ( ! workflowFind ) throw new Error ( `Unable to find workflow named '${ workflowName } ' in ${ repo } 😥` )
32+ const workflowFind = workflows . find ( ( workflow ) => workflow . name === workflowName )
33+ if ( ! workflowFind ) throw new Error ( `Unable to find workflow named '${ workflowName } ' in ${ owner } /${ repo } 😥` )
3934 console . log ( `Workflow id is: ${ workflowFind . id } ` )
4035
4136 // Call workflow_dispatch API
42- const dispatchResp = await octokit . request ( `POST /repos/${ repo } /actions/workflows/${ workflowFind . id } /dispatches` , {
37+ const dispatchResp = await octokit . request ( `POST /repos/${ owner } / ${ repo } /actions/workflows/${ workflowFind . id } /dispatches` , {
4338 ref : ref ,
4439 inputs : inputs
4540 } )
0 commit comments