@@ -4055,45 +4055,45 @@ module.exports = require("util");
40554055/***/ 676 :
40564056/***/ ( function ( __unusedmodule , __unusedexports , __webpack_require__ ) {
40574057
4058- const { WebClient } = __webpack_require__ ( 114 )
4059- const core = __webpack_require__ ( 470 )
4058+ const { WebClient } = __webpack_require__ ( 114 ) ;
4059+ const core = __webpack_require__ ( 470 ) ;
40604060
40614061// Replace this tag in raw JSONs with current time value (ready for slack `ts` values)
4062- const NOW_TS_TAG = ' %NOW-TS%'
4062+ const NOW_TS_TAG = " %NOW-TS%" ;
40634063
40644064async function run ( ) {
40654065 try {
4066- const token = core . getInput ( ' token' , { required : true } )
4067- const channel = core . getInput ( ' channel' , { required : true } )
4068- const text = core . getInput ( ' text' , { required : false } )
4069- const blocksRaw = core . getInput ( ' blocks' , { required : false } )
4070- const attachmentsRaw = core . getInput ( ' attachments' , { required : false } )
4071- const ts = core . getInput ( 'ts' , { required : false } )
4072- const appendText = core . getInput ( ' appendAttachments' , { required : false } )
4073- const appendBlocksRaw = core . getInput ( ' appendAttachments' , {
4066+ const token = core . getInput ( " token" , { required : true } ) ;
4067+ const channel = core . getInput ( " channel" , { required : true } ) ;
4068+ const text = core . getInput ( " text" , { required : false } ) ;
4069+ const blocksRaw = core . getInput ( " blocks" , { required : false } ) ;
4070+ const attachmentsRaw = core . getInput ( " attachments" , { required : false } ) ;
4071+ const ts = core . getInput ( "ts" , { required : false } ) ;
4072+ const appendText = core . getInput ( " appendAttachments" , { required : false } ) ;
4073+ const appendBlocksRaw = core . getInput ( " appendAttachments" , {
40744074 required : false ,
4075- } )
4076- const appendAttachmentsRaw = core . getInput ( ' appendAttachments' , {
4075+ } ) ;
4076+ const appendAttachmentsRaw = core . getInput ( " appendAttachments" , {
40774077 required : false ,
4078- } )
4078+ } ) ;
40794079
40804080 if ( ! token ) {
4081- throw new Error ( ' Missing input `token`' )
4081+ throw new Error ( " Missing input `token`" ) ;
40824082 }
40834083
4084- const client = new WebClient ( token )
4084+ const client = new WebClient ( token ) ;
40854085 const blocks = blocksRaw
40864086 ? JSON . parse ( blocksRaw . replace ( NOW_TS_TAG , toSlackTS ( ) ) )
4087- : undefined
4087+ : undefined ;
40884088 const attachments = attachmentsRaw
40894089 ? JSON . parse ( attachmentsRaw . replace ( NOW_TS_TAG , toSlackTS ( ) ) )
4090- : undefined
4090+ : undefined ;
40914091 const appendAttachments = appendAttachmentsRaw
40924092 ? JSON . parse ( appendAttachmentsRaw . replace ( NOW_TS_TAG , toSlackTS ( ) ) )
4093- : undefined
4093+ : undefined ;
40944094 const appendBlocks = appendBlocksRaw
40954095 ? JSON . parse ( appendBlocksRaw . replace ( NOW_TS_TAG , toSlackTS ( ) ) )
4096- : undefined
4096+ : undefined ;
40974097
40984098 if ( ! ts ) {
40994099 // just post a new message
@@ -4102,16 +4102,16 @@ async function run() {
41024102 text,
41034103 blocks,
41044104 attachments,
4105- }
4106- const result = await client . chat . postMessage ( message )
4105+ } ;
4106+ const result = await client . chat . postMessage ( message ) ;
41074107 if ( result . error ) {
41084108 throw new Error (
41094109 `Error happendAttachments while posting slack message: ${ result . error } `
4110- )
4110+ ) ;
41114111 }
4112- const { ts } = result
4113- core . setOutput ( 'ts' , ts )
4114- return
4112+ const { ts } = result ;
4113+ core . setOutput ( "ts" , ts ) ;
4114+ return ;
41154115 }
41164116
41174117 // retrive the original message
@@ -4121,44 +4121,60 @@ async function run() {
41214121 latest : ts ,
41224122 inclusive : true ,
41234123 limit : 1 ,
4124- } )
4124+ } ) ;
41254125
4126- const [ message ] = response . messages
4126+ const [ message ] = response . messages ;
41274127
41284128 const result = await client . chat . update ( {
41294129 // required refs
41304130 channel,
41314131 ts,
41324132 // new attributes
41334133 text : appendText
4134- ? [ message . text , appendText ] . filter ( Boolean ) . join ( '' )
4134+ ? [ message . text , appendText ] . filter ( Boolean ) . join ( "" )
41354135 : text || message . text ,
4136- blocks : appendBlocks
4137- ? [ ... ( message . blocks || [ ] ) , ... appendBlocks ] . filter ( Boolean )
4138- : blocks || message . blocks ,
4139- attachments : appendAttachments
4140- ? [ ... ( message . attachments || [ ] ) , ... appendAttachments ] . filter ( Boolean )
4141- : attachments || message . attachments ,
4142- } )
4136+ blocks : mergeItems ( message . blocks , blocks , appendBlocks ) ,
4137+ attachments : mergeItems (
4138+ message . attachments ,
4139+ attachments ,
4140+ appendAttachments
4141+ ) ,
4142+ } ) ;
41434143
41444144 if ( result . error ) {
41454145 throw new Error (
41464146 `Error happend while updating slack message: ${ result . error } `
4147- )
4147+ ) ;
41484148 }
4149- core . setOutput ( 'ts' , ts )
4149+ core . setOutput ( "ts" , ts ) ;
41504150 } catch ( error ) {
4151- core . debug ( error . message )
4151+ core . debug ( error . message ) ;
41524152 core . setFailed (
41534153 `Something went wrong while sending a message to slack: ${ error . message } `
4154- )
4154+ ) ;
41554155 }
41564156}
41574157
4158- run ( )
4158+ run ( ) ;
41594159
41604160function toSlackTS ( timestamp = Date . now ( ) ) {
4161- return `${ Math . floor ( timestamp / 1000 ) } `
4161+ return `${ Math . floor ( timestamp / 1000 ) } ` ;
4162+ }
4163+
4164+ function mergeItems ( originalItems , newItems , appenedItems ) {
4165+ if ( ! originalItems ) {
4166+ return newItems || appenedItems ;
4167+ }
4168+
4169+ if ( ! appenedItems ) {
4170+ return newItems ;
4171+ }
4172+
4173+ const items = [ ...originalItems , ...appenedItems ] ;
4174+ if ( ! items . lenght ) {
4175+ return undefined ;
4176+ }
4177+ return items ;
41624178}
41634179
41644180
0 commit comments