1+ import { t as setOutput } from "./utils-DQae65qb.mjs" ;
2+ //#region src/mergebot.ts
3+ const { COMMIT_AUTHOR , COMMIT_ID , COMMIT_MESSAGE , GITHUB_REPO } = process . env ;
4+ if ( ! COMMIT_AUTHOR || ! COMMIT_ID || ! COMMIT_MESSAGE || ! GITHUB_REPO ) throw new Error ( `Missing input.\nRequired environment variables: COMMIT_AUTHOR, COMMIT_ID, COMMIT_MESSAGE, GITHUB_REPO\n\nAvailable environment variables: ${ Object . keys ( process . env ) . join ( ", " ) } \n` ) ;
5+ setDiscordMessage ( COMMIT_AUTHOR , COMMIT_ID , COMMIT_MESSAGE , GITHUB_REPO ) ;
6+ function setDiscordMessage ( author , id , commitMsg , repo ) {
7+ const commitMessage = commitMsg . split ( "\n" ) [ 0 ] . replaceAll ( "`" , "" ) . replaceAll ( "-" , "–" ) ;
8+ const coAuthors = commitMsg . split ( "\n" ) . slice ( 2 ) . filter ( ( line ) => line . match ( / C o - a u t h o r e d - b y : ( .+ ) < .+ > / i) ) . map ( ( line ) => line . match ( / C o - a u t h o r e d - b y : ( .+ ) < .+ > / i) [ 1 ] ) . filter ( ( name ) => name !== "github-actions[bot]" ) ;
9+ let coAuthorThanks = "" ;
10+ if ( coAuthors . length > 0 ) coAuthorThanks = `\n${ getCoAuthorsMessage ( formatAsCommaSeparatedList ( [ ...new Set ( coAuthors ) ] ) ) } ` ;
11+ const defaultEmoji = [
12+ "🎉" ,
13+ "🎊" ,
14+ "🧑🚀" ,
15+ "🥳" ,
16+ "🙌" ,
17+ "🚀"
18+ ] ;
19+ const userEmoji = process . env . EMOJIS ?. split ( "," ) ;
20+ setOutput ( "DISCORD_MESSAGE" , `${ pick ( userEmoji && userEmoji . length > 0 ? userEmoji : defaultEmoji ) } **Merged!** ${ author } : [\`${ commitMessage } \`](<https://github.com/${ repo } /commit/${ id } >)${ coAuthorThanks } ` ) ;
21+ }
22+ function formatAsCommaSeparatedList ( list ) {
23+ if ( list . length === 1 ) return list [ 0 ] ;
24+ return `${ list . slice ( 0 , - 1 ) . join ( ", " ) } & ${ list . at ( - 1 ) } ` ;
25+ }
26+ function pick ( items ) {
27+ return items [ Math . floor ( Math . random ( ) * items . length ) ] ;
28+ }
29+ function getCoAuthorsMessage ( names ) {
30+ let messages = [ ] ;
31+ try {
32+ messages = JSON . parse ( process . env . COAUTHOR_TEMPLATES || "[]" ) ;
33+ } catch ( err ) {
34+ console . error ( "Failed to parse `COAUTHOR_TEMPLATES` as JSON. Falling back to default templates.\n " , err ) ;
35+ }
36+ if ( ! messages || messages . length === 0 ) messages = [
37+ "Thanks <names> for helping! ✨" ,
38+ "<names> stepped up to lend a hand — thank you! 🙌" ,
39+ "<names> with the assist! 💪" ,
40+ "Couldn't have done this without <names>! 💜" ,
41+ "Made even better by <names>! 🚀" ,
42+ "And the team effort award goes to… <names>! 🏆" ,
43+ "Featuring contributions by <names>! 🌟"
44+ ] ;
45+ return `_${ pick ( messages ) . replace ( "<names>" , names ) . trim ( ) } _` ;
46+ }
47+ //#endregion
48+ export { } ;
49+
50+ //# sourceMappingURL=mergebot.mjs.map
0 commit comments