@@ -3,43 +3,29 @@ import { type GithubDeploymentService } from '../services/GithubDeploymentServic
33
44const identifierToSlackTs : Record < string , string > = { } ;
55
6+ const unknown = '@unknown' ;
7+
68export const implementDeploymentService = ( {
79 messengerPresenter,
810} : {
911 messengerPresenter : MessengerPresenter ;
1012} ) : GithubDeploymentService => {
1113 return {
12- handleCreateRelease : async ( body ) => {
13- const author : string = body . release . author . login ;
14- const releaseBody : string = body . release . body ;
15- const tag : string = body . release . tag_name ;
16- const releaseUrl : string = body . release . html_url ;
17- const repository = body . repository . name ;
18-
19- const changes = releaseBody . split ( '\n' ) . reduce < { content : string ; contributor : string } [ ] > ( ( acc , cur ) => {
20- const match = cur . match ( / \* ( .* ) b y @ ( .* ) i n ( .* ) / ) ;
21- if ( ! match ) return acc ;
22- return [ ...acc , { content : match [ 1 ] , contributor : match [ 2 ] } ] ;
23- } , [ ] ) ;
24-
25- const { ts } = await messengerPresenter . sendMessage ( ( { formatEmoji, formatLink } ) => ( {
14+ handleCreateRelease : async ( { changes, author, tag, releaseUrl, repository } ) => {
15+ const { ts } = await messengerPresenter . sendMessage ( ( { formatMemberMention, formatEmoji, formatLink } ) => ( {
2616 text : [
27- `${ formatEmoji ( 'rocket' ) } *${ repository } * by @${ author } (${ formatLink ( tag , { url : releaseUrl } ) } )` ,
28- ...changes . map ( ( c ) => ` - ${ c . content } @${ c . contributor } ` ) ,
17+ `${ formatEmoji ( 'rocket' ) } *${ repository } * by ${ author ? formatMemberMention ( author ) : unknown } (${ formatLink (
18+ tag ,
19+ { url : releaseUrl } ,
20+ ) } )`,
21+ ...changes . map ( ( c ) => ` - ${ c . content } by ${ c . author ? formatMemberMention ( c . author ) : unknown } ` ) ,
2922 ] . join ( '\n' ) ,
3023 } ) ) ;
3124
3225 identifierToSlackTs [ toIdentifier ( { tag, repository } ) ] = ts ;
3326 } ,
34- handleActionStart : async ( body ) => {
35- const workflowName : string = body . workflow_run . name ;
36- const tag : string = body . workflow_run . head_branch ;
37- const repository : string = body . repository . name ;
38- const workflowId : number = body . workflow_run . id ;
39- const workflowUrl : string = body . workflow_run . html_url ;
40-
41- const isDeploy = workflowName . toLowerCase ( ) . includes ( 'deploy' ) ;
42- if ( ! isDeploy ) return ;
27+ handleActionStart : async ( { workflowName, workflowId, workflowUrl, tag, repository } ) => {
28+ if ( ! isDeployWorkflow ( workflowName ) ) return ;
4329
4430 const ts = identifierToSlackTs [ toIdentifier ( { tag, repository } ) ] ;
4531 if ( ! ts ) return ;
@@ -53,15 +39,8 @@ export const implementDeploymentService = ({
5339 options : { ts } ,
5440 } ) ) ;
5541 } ,
56- handleActionComplete : async ( body ) => {
57- const workflowName : string = body . workflow_run . name ;
58- const tag : string = body . workflow_run . head_branch ;
59- const repository : string = body . repository . name ;
60- const workflowId : number = body . workflow_run . id ;
61- const workflowUrl : string = body . workflow_run . html_url ;
62-
63- const isDeploy = workflowName . toLowerCase ( ) . includes ( 'deploy' ) ;
64- if ( ! isDeploy ) return ;
42+ handleActionComplete : async ( { workflowName, workflowId, workflowUrl, tag, repository } ) => {
43+ if ( ! isDeployWorkflow ( workflowName ) ) return ;
6544
6645 const ts = identifierToSlackTs [ toIdentifier ( { tag, repository } ) ] ;
6746 if ( ! ts ) return ;
@@ -79,3 +58,4 @@ export const implementDeploymentService = ({
7958} ;
8059
8160const toIdentifier = ( { tag, repository } : { repository : string ; tag : string } ) => `${ repository } :${ tag } ` ;
61+ const isDeployWorkflow = ( workflowName : string ) => workflowName . toLowerCase ( ) . includes ( 'deploy' ) ;
0 commit comments