1
1
import { Context } from '@actions/github/lib/context' ;
2
2
import { Octokit } from '@technote-space/github-action-helper/dist/types' ;
3
3
import { Logger } from '@technote-space/github-action-log-helper' ;
4
+ import { Utils } from '@technote-space/github-action-helper' ;
4
5
import { PaginateInterface } from '@octokit/plugin-paginate-rest' ;
5
6
import { RestEndpointMethods } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types' ;
6
- import { ActionsListWorkflowRunsResponseData , ActionsGetWorkflowRunResponseData } from '@octokit/types' ;
7
+ import { components } from '@octokit/openapi- types' ;
7
8
import { getTargetBranch , isNotExcludeRun } from './misc' ;
8
9
10
+ type ActionsGetWorkflowRunResponseData = components [ 'schemas' ] [ 'workflow-run' ] ;
11
+ type ActionsListWorkflowRunsResponseData = components [ 'schemas' ] [ 'workflow-run' ] ;
12
+
9
13
export const getWorkflowRun = async ( octokit : Octokit , context : Context ) : Promise < ActionsGetWorkflowRunResponseData > => {
10
14
return ( await octokit . actions . getWorkflowRun ( {
11
15
owner : context . repo . owner ,
@@ -23,11 +27,11 @@ export const getWorkflowId = (run: ActionsGetWorkflowRunResponseData): number |
23
27
return Number ( matches [ 0 ] ) ;
24
28
} ;
25
29
26
- export const getWorkflowRunCreatedAt = ( run : ActionsGetWorkflowRunResponseData ) : string => run . created_at ;
30
+ export const getWorkflowRunCreatedAt = ( run : ActionsGetWorkflowRunResponseData ) : string => Utils . ensureNotNull ( run . created_at ) ;
27
31
28
32
export const getWorkflowRunNumber = ( run : ActionsGetWorkflowRunResponseData ) : number => run . run_number ;
29
33
30
- export const getWorkflowRuns = async ( workflowId : number , logger : Logger , octokit : Octokit , context : Context ) : Promise < ActionsListWorkflowRunsResponseData [ 'workflow_runs' ] > => {
34
+ export const getWorkflowRuns = async ( workflowId : number , logger : Logger , octokit : Octokit , context : Context ) : Promise < Array < ActionsListWorkflowRunsResponseData > > => {
31
35
const options : {
32
36
owner : string ;
33
37
repo : string ;
@@ -57,7 +61,7 @@ export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit
57
61
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
58
62
// @ts -ignore
59
63
options ,
60
- ) ) . map ( run => run as ActionsListWorkflowRunsResponseData [ 'workflow_runs' ] [ number ] ) . filter ( run => run . event === context . eventName ) . filter ( isNotExcludeRun ) ;
64
+ ) ) . map ( run => run as ActionsListWorkflowRunsResponseData ) . filter ( run => run . event === context . eventName ) . filter ( isNotExcludeRun ) ;
61
65
} ;
62
66
63
67
// eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments