@@ -37,6 +37,9 @@ export default class Content {
3737 this . values = github . context ;
3838 break ;
3939 }
40+ if ( config . inputs . payloadTemplated ) {
41+ this . values = this . templatize ( this . values ) ;
42+ }
4043 if ( config . inputs . payloadDelimiter ) {
4144 this . values = flatten ( this . values , {
4245 delimiter : config . inputs . payloadDelimiter ,
@@ -63,9 +66,8 @@ export default class Content {
6366 ) ;
6467 }
6568 try {
66- const input = this . templatize ( config , config . inputs . payload ) ;
6769 const content = /** @type {Content } */ (
68- yaml . load ( input , {
70+ yaml . load ( config . inputs . payload , {
6971 schema : yaml . JSON_SCHEMA ,
7072 } )
7173 ) ;
@@ -119,18 +121,17 @@ export default class Content {
119121 path . resolve ( config . inputs . payloadFilePath ) ,
120122 "utf-8" ,
121123 ) ;
122- const content = this . templatize ( config , input ) ;
123124 if (
124125 config . inputs . payloadFilePath . endsWith ( "yaml" ) ||
125126 config . inputs . payloadFilePath . endsWith ( "yml" )
126127 ) {
127- const load = yaml . load ( content , {
128+ const load = yaml . load ( input , {
128129 schema : yaml . JSON_SCHEMA ,
129130 } ) ;
130131 return /** @type {Content } */ ( load ) ;
131132 }
132133 if ( config . inputs . payloadFilePath . endsWith ( "json" ) ) {
133- return JSON . parse ( content ) ;
134+ return JSON . parse ( input ) ;
134135 }
135136 throw new SlackError (
136137 config . core ,
@@ -148,20 +149,32 @@ export default class Content {
148149 }
149150
150151 /**
151- * Replace templated variables in the provided content if requested.
152- * @param {Config } config
153- * @param {string } input - The initial value of the content.
154- * @returns {string } Content with templatized variables replaced.
152+ * Replace templated variables in the provided content as requested.
153+ * @param {unknown } input - The initial value of the content.
154+ * @returns {unknown } Content with templatized variables replaced.
155155 */
156- templatize ( config , input ) {
157- if ( ! config . inputs . payloadTemplated ) {
158- return input ;
156+ templatize ( input ) {
157+ if ( Array . isArray ( input ) ) {
158+ return input . map ( ( v ) => this . templatize ( v ) ) ;
159+ }
160+ if ( input && typeof input === "object" ) {
161+ /**
162+ * @type {any }
163+ */
164+ const out = { } ;
165+ for ( const [ k , v ] of Object . entries ( input ) ) {
166+ out [ k ] = this . templatize ( v ) ;
167+ }
168+ return out ;
169+ }
170+ if ( typeof input === "string" ) {
171+ const template = input . replace ( / \$ \{ \{ / g, "{{" ) ; // swap ${{ for {{
172+ const context = {
173+ env : process . env ,
174+ github : github . context ,
175+ } ;
176+ return markup . up ( template , context ) ;
159177 }
160- const template = input . replace ( / \$ \{ \{ / g, "{{" ) ; // swap ${{ for {{
161- const context = {
162- env : process . env ,
163- github : github . context ,
164- } ;
165- return markup . up ( template , context ) ;
178+ return input ;
166179 }
167180}
0 commit comments