@@ -19,48 +19,57 @@ interface GitHubAction
1919}
2020
2121// Helper functions
22- const getActionText = ( action ?: string ) =>
22+ const getActionText = ( action ?: string ) =>
2323 action === "closed" ? "关闭" : action ?. includes ( "open" ) ? "打开" : "编辑" ;
2424
25- const createLink = ( text : string , href ?: string ) => ( {
26- tag : "a" ,
27- text,
28- href
29- } ) ;
25+ const createLink = ( href : string , text = href ) => ( { tag : "a" , href, text } ) ;
3026
31- const createText = ( text : string ) => ( {
32- tag : "text" ,
33- text
34- } ) ;
27+ const createText = ( text : string ) => ( { tag : "text" , text } ) ;
3528
3629// Event handlers
37- const handlePushEvent = ( event : GitHubAction ) => {
38- const { head_commit, ref, ref_name, server_url, repository, actor } = event ;
39- return {
40- title : "GitHub 代码提交" ,
41- content : [
42- [ createText ( "提交链接:" ) , createLink ( head_commit ?. url , head_commit ?. url ) ] ,
43- [ createText ( "代码分支:" ) , createLink ( ref , `${ server_url } /${ repository } /tree/${ ref_name } ` ) ] ,
44- [ createText ( "提交作者:" ) , createLink ( actor , `${ server_url } /${ actor } ` ) ] ,
45- [ createText ( "提交信息:" ) , createText ( head_commit ?. message ) ]
46- ]
47- } ;
48- } ;
30+ const handlePushEvent = ( {
31+ head_commit,
32+ ref,
33+ ref_name,
34+ server_url,
35+ repository,
36+ actor,
37+ } : GitHubAction ) => ( {
38+ title : "GitHub 代码提交" ,
39+ content : [
40+ [ createText ( "提交链接:" ) , createLink ( head_commit ?. url , head_commit ?. url ) ] ,
41+ [
42+ createText ( "代码分支:" ) ,
43+ createLink ( ref , `${ server_url } /${ repository } /tree/${ ref_name } ` ) ,
44+ ] ,
45+ [ createText ( "提交作者:" ) , createLink ( actor , `${ server_url } /${ actor } ` ) ] ,
46+ [ createText ( "提交信息:" ) , createText ( head_commit ?. message ) ] ,
47+ ] ,
48+ } ) ;
4949
50- const handleIssueEvent = ( event : GitHubAction , actionText : string ) => {
51- const { issue } = event ;
52- return {
53- title : `GitHub issue ${ actionText } :${ issue ?. title } ` ,
54- content : [
55- [ createText ( "链接:" ) , createLink ( issue ?. html_url , issue ?. html_url ) ] ,
56- [ createText ( "作者:" ) , createLink ( issue ?. user ?. login , issue ?. user ?. html_url ) ] ,
57- [ createText ( "指派:" ) , issue ?. assignee ? createLink ( issue . assignee . login , issue . assignee . html_url ) : createText ( "" ) ] ,
58- [ createText ( `标签:${ issue ?. labels ?. map ( ( { name } ) => name ) . join ( ", " ) || "" } ` ) ] ,
59- [ createText ( `里程碑:${ issue ?. milestone ?. title || "" } ` ) ] ,
60- [ createText ( "描述:" ) , createText ( issue ?. body ) ]
61- ]
62- } ;
63- } ;
50+ const handleIssueEvent = ( { issue } : GitHubAction , actionText : string ) => ( {
51+ title : `GitHub issue ${ actionText } :${ issue ?. title } ` ,
52+ content : [
53+ [ createText ( "链接:" ) , createLink ( issue ?. html_url , issue ?. html_url ) ] ,
54+ [
55+ createText ( "作者:" ) ,
56+ createLink ( issue ?. user ?. login , issue ?. user ?. html_url ) ,
57+ ] ,
58+ [
59+ createText ( "指派:" ) ,
60+ issue ?. assignee
61+ ? createLink ( issue . assignee . login , issue . assignee . html_url )
62+ : createText ( "" ) ,
63+ ] ,
64+ [
65+ createText (
66+ `标签:${ issue ?. labels ?. map ( ( { name } ) => name ) . join ( ", " ) || "" } `
67+ ) ,
68+ ] ,
69+ [ createText ( `里程碑:${ issue ?. milestone ?. title || "" } ` ) ] ,
70+ [ createText ( "描述:" ) , createText ( issue ?. body ) ] ,
71+ ] ,
72+ } ) ;
6473
6574// ... other event handlers (pull_request, discussion, comment, release) ...
6675
@@ -80,16 +89,14 @@ const processEvent = (event: GitHubAction) => {
8089 }
8190} ;
8291
83- // Main execution
84- const main = async ( ) => {
85- const event = JSON . parse ( ( await stdin ( ) ) || "{}" ) as GitHubAction ;
86- const zh_cn = processEvent ( event ) ;
87-
88- if ( zh_cn ) {
89- console . log ( JSON . stringify ( { post : { zh_cn } } ) ) ;
90- } else {
91- console . error ( `Unsupported ${ event . event_name } event & ${ event . action } action` ) ;
92- }
93- } ;
92+ // Main execution:Processing GitHub Events and Outputting Results
93+ const event = JSON . parse ( ( await stdin ( ) ) || "{}" ) as GitHubAction ;
94+ const zh_cn = processEvent ( event ) ;
9495
95- main ( ) ;
96+ if ( zh_cn ) {
97+ console . log ( JSON . stringify ( { post : { zh_cn } } ) ) ;
98+ } else {
99+ console . error (
100+ `Unsupported ${ event . event_name } event & ${ event . action } action`
101+ ) ;
102+ }
0 commit comments