File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ type APIMessageTopLevelComponent ,
3+ ComponentType ,
4+ SeparatorSpacingSize ,
5+ } from "@discordjs/core/http-only" ;
6+ import type { PushEvent } from "@octokit/webhooks-types" ;
7+
8+ export function pushCreatedComponents ( payload : PushEvent ) : APIMessageTopLevelComponent [ ] {
9+ const branch = payload . ref . replace ( "refs/heads/" , "" ) ;
10+
11+ const commits = payload . commits . map (
12+ ( commit ) =>
13+ `[\`${ commit . id . slice ( 0 , 7 ) } \`](${ commit . url } ) ${ commit . committer . name } : ${ commit . message } <t:${ Date . parse ( commit . timestamp ) / 1000 } :R>` ,
14+ ) ;
15+
16+ const commitDescription =
17+ commits . length > 1
18+ ? `[${ payload . before . slice ( 0 , 7 ) } ...${ payload . after . slice ( 0 , 7 ) } ](${ payload . compare } )\n${ commits . join ( "\n" ) } `
19+ : commits [ 0 ] ! ;
20+
21+ return [
22+ {
23+ type : ComponentType . Container ,
24+ components : [
25+ {
26+ type : ComponentType . TextDisplay ,
27+ content : `[${ payload . sender . name ?? payload . sender . login } ](${ payload . sender . html_url } ) committed to [${ payload . repository . name } :${ branch } ](${ payload . repository . html_url } ).\n${ commitDescription } ` ,
28+ } ,
29+ {
30+ type : ComponentType . Separator ,
31+ divider : true ,
32+ spacing : SeparatorSpacingSize . Small ,
33+ } ,
34+ {
35+ type : ComponentType . TextDisplay ,
36+ content : `-# [${ payload . repository . full_name } ](${ payload . repository . html_url } )` ,
37+ } ,
38+ ] ,
39+ } ,
40+ ] ;
41+ }
Original file line number Diff line number Diff line change 66} from "@discordjs/core/http-only" ;
77import { REST } from "@discordjs/rest" ;
88import { Webhooks } from "@octokit/webhooks" ;
9- import type { StarEvent , WebhookEvent , WebhookEventName } from "@octokit/webhooks-types" ;
9+ import type { PushEvent , StarEvent , WebhookEvent , WebhookEventName } from "@octokit/webhooks-types" ;
1010import { starCreatedComponents } from "../events/star.js" ;
11+ import { pushCreatedComponents } from "../events/push.js" ;
1112
1213interface Env {
1314 GITHUB_WEBHOOK_SERCET : string ;
@@ -47,7 +48,9 @@ export default {
4748 const payload = JSON . parse ( text ) as WebhookEvent ;
4849 let components : APIMessageTopLevelComponent [ ] | undefined ;
4950
50- if ( eventType === "star" ) {
51+ if ( eventType === "push" ) {
52+ components = pushCreatedComponents ( payload as PushEvent ) ;
53+ } else if ( eventType === "star" ) {
5154 const starEvent = payload as StarEvent ;
5255
5356 if ( starEvent . action === "deleted" ) {
You can’t perform that action at this time.
0 commit comments