@@ -5,6 +5,27 @@ import { Client } from '@larksuiteoapi/node-sdk';
55
66import { larkOptionSchema , messageReceiverSchema } from './schema' ;
77
8+ function makeCRUrl ( pr_url ?: string ) {
9+ const baseUrl = process . env . PR_CR_BASE_URL ;
10+
11+ if ( ! pr_url || ! baseUrl ) {
12+ return ;
13+ }
14+
15+ const docUrl = process . env . PR_CR_DOC_URL || '' ;
16+ const formData = JSON . stringify ( [
17+ { name : 'pr_url' , value : pr_url } ,
18+ { name : 'doc_url' , value : docUrl } ,
19+ ] ) ;
20+
21+ const cr_url = new URL ( baseUrl ) ;
22+ cr_url . searchParams . append ( 'formData' , formData ) ;
23+ cr_url . searchParams . append ( 'autoreg' , 'true' ) ;
24+ cr_url . searchParams . append ( 'fromapp' , 'GitHub' ) ;
25+
26+ return cr_url . toString ( ) ;
27+ }
28+
829function makePrMessage ( ) {
930 const repo_name = process . env . REPO_NAME ;
1031 const pr_action = process . env . PR_ACTION ;
@@ -17,11 +38,14 @@ function makePrMessage() {
1738 const pr_target_owner = process . env . PR_TARGET_OWNER ;
1839 const pr_target_ref = process . env . PR_TARGET_REF ;
1940 const pr_merged = process . env . PR_MERGED ;
41+ const cr_url = makeCRUrl ( pr_url ) ;
2042
21- const title =
22- pr_action === 'closed' && pr_merged === 'true'
23- ? `🎉 PR #${ pr_number } merged`
24- : `📢 PR #${ pr_number } ${ pr_action } ` ;
43+ const isOpen = pr_action === 'opened' || pr_action === 'reopened' ;
44+ const isMerged = pr_action === 'closed' && pr_merged === 'true' ;
45+
46+ const title = isMerged
47+ ? `🎉 PR #${ pr_number } merged`
48+ : `📢 PR #${ pr_number } ${ pr_action } ` ;
2549
2650 return JSON . stringify ( {
2751 schema : '2.0' ,
@@ -59,13 +83,43 @@ function makePrMessage() {
5983 margin : '0px 0px 0px 0px' ,
6084 } ,
6185 {
62- tag : 'markdown' ,
63- content : `<a href="${ pr_url } ">👉 前往查看</a>` ,
64- text_align : 'left' ,
65- text_size : 'normal_v2' ,
66- margin : '0px 0px 0px 0px' ,
86+ tag : 'column_set' ,
87+ columns : [
88+ {
89+ tag : 'column' ,
90+ width : 'weighted' ,
91+ elements : [
92+ {
93+ tag : 'markdown' ,
94+ content : `<a href="${ pr_url } ">👉 前往查看</a>` ,
95+ text_align : 'left' ,
96+ text_size : 'normal_v2' ,
97+ margin : '0px 0px 0px 0px' ,
98+ } ,
99+ ] ,
100+ vertical_align : 'top' ,
101+ weight : 1 ,
102+ } ,
103+ isOpen && cr_url
104+ ? {
105+ tag : 'column' ,
106+ width : 'weighted' ,
107+ elements : [
108+ {
109+ tag : 'markdown' ,
110+ content : `<a href="${ cr_url } ">🔍 Aime CR</a>` ,
111+ text_align : 'left' ,
112+ text_size : 'normal_v2' ,
113+ margin : '0px 0px 0px 0px' ,
114+ } ,
115+ ] ,
116+ vertical_align : 'top' ,
117+ weight : 1 ,
118+ }
119+ : undefined ,
120+ ] ,
67121 } ,
68- ] ,
122+ ] . filter ( v => Boolean ( v ) ) ,
69123 } ,
70124 header : {
71125 title : {
0 commit comments