@@ -15,6 +15,7 @@ import { Operation } from './operation/operation';
15
15
import { Task } from './operation/task' ;
16
16
import { ResourceConfig } from '../config/resource-config' ;
17
17
import { OperationConfig } from '../config/operation-config' ;
18
+ import { TaskArgData } from '../config/types' ;
18
19
import { octokitAuth } from '../utility/probot/octokit' ;
19
20
20
21
export class Service {
@@ -78,31 +79,13 @@ export class Service {
78
79
console . error ( `ERROR: ${ e } ` ) ;
79
80
}
80
81
82
+
81
83
const callStack = await import ( callPath ) ;
84
+ const callArgsSub = await this . _outputsSubstitution ( { ...callArgs } , event ) ;
85
+
82
86
if ( callFunc === 'default' ) {
83
87
console . log ( `[${ event } ]: Call default function: [${ callStack . default . name } ]` ) ;
84
- if ( callArgs ) {
85
- console . log ( `[${ event } ]: Call with args:` ) ;
86
- for ( const name2 in callArgs ) {
87
- console . log ( `[${ event } ]: args: ${ name2 } : ${ callArgs [ name2 ] } ` ) ;
88
- if ( Array . isArray ( callArgs [ name2 ] ) ) {
89
- for ( let i = 0 ; i < callArgs [ name2 ] . length ; i ++ ) {
90
- if ( this . subPattern . test ( callArgs [ name2 ] [ i ] ) ) {
91
- console . log ( `Array: ${ callArgs [ name2 ] [ i ] } ` ) ;
92
- }
93
- }
94
- } else {
95
- const match = ( callArgs [ name2 ] as string ) . match ( this . subPattern ) ;
96
- if ( match ) {
97
- console . log ( `StrSub: ${ callArgs [ name2 ] } , Match: ${ match [ 1 ] } , ${ match [ 1 ] . replace ( 'outputs.' , '' ) } ` ) ;
98
- console . log ( this . _outputs . get ( event ) ?. get ( match [ 1 ] . replace ( 'outputs.' , '' ) ) )
99
- callArgs [ name2 ] = JSON . stringify ( Object . fromEntries ( this . _outputs . get ( event ) ?. get ( match [ 1 ] . replace ( 'outputs.' , '' ) ) ) )
100
- }
101
- }
102
- }
103
- }
104
-
105
- const resultDefault = await callStack . default ( this . app , context , this . resource , { ...callArgs } ) ;
88
+ const resultDefault = await callStack . default ( this . app , context , this . resource , { ...callArgsSub } ) ;
106
89
this . _outputs . get ( event ) ?. set ( name , resultDefault ) ;
107
90
console . log ( this . _outputs . get ( event ) ) ;
108
91
} else {
@@ -112,11 +95,36 @@ export class Service {
112
95
if ( ! ( typeof callFuncCustom === 'function' ) ) {
113
96
throw new Error ( `[${ event } ]: ${ callFuncCustom } is not a function, please verify in ${ callPath } ` ) ;
114
97
}
115
- this . _outputs . get ( event ) ?. set ( name , await callFuncCustom ( this . app , context , this . resource , { ...callArgs } ) ) ;
98
+ this . _outputs . get ( event ) ?. set ( name , await callFuncCustom ( this . app , context , this . resource , { ...callArgsSub } ) ) ;
116
99
}
117
100
} , Promise . resolve ( ) ) ;
118
101
}
119
102
103
+ private async _outputsSubstitution ( callArgsData : TaskArgData , event : string ) : Promise < TaskArgData > {
104
+ console . log ( `[${ event } ]: Call with args:` ) ;
105
+ for ( const argName in callArgsData ) {
106
+ console . log ( `[${ event } ]: args: ${ argName } : ${ callArgsData [ argName ] } ` ) ;
107
+ if ( Array . isArray ( callArgsData [ argName ] ) ) {
108
+ for ( let i = 0 ; i < callArgsData [ argName ] . length ; i ++ ) {
109
+ ( callArgsData [ argName ] as string [ ] ) [ i ] = await this . _matchSubPattern ( ( callArgsData [ argName ] [ i ] as string ) , event ) ;
110
+ }
111
+ } else {
112
+ ( callArgsData [ argName ] as string ) = await this . _matchSubPattern ( ( callArgsData [ argName ] as string ) , event ) ;
113
+ }
114
+ }
115
+ return callArgsData ;
116
+ }
117
+
118
+ private async _matchSubPattern ( callArgsValue : string , event : string ) : Promise < string > {
119
+ const match = callArgsValue . match ( this . subPattern ) ;
120
+ if ( match ) {
121
+ const outputMatch = this . _outputs . get ( event ) ?. get ( match [ 1 ] . replace ( 'outputs.' , '' ) ) ;
122
+ console . log ( `StrSub: ${ callArgsValue } , Match: ${ match [ 1 ] } , Output: ${ outputMatch } ` ) ;
123
+ return outputMatch ;
124
+ }
125
+ return callArgsValue ;
126
+ }
127
+
120
128
private async _registerEvents ( ) : Promise < void > {
121
129
const { events, tasks } = this . operation ;
122
130
console . log ( `Evaluate events: [${ events } ]` ) ;
0 commit comments