Aethel Bot OSS repository! aethel.xyz
bot fun ai discord discord-bot aethel
at dev 2.5 kB view raw
1import { WebhookClient } from 'discord.js'; 2import { execSync } from 'child_process'; 3import logger from './logger'; 4 5function getGitInfo() { 6 try { 7 const commitHash = 8 process.env.SOURCE_COMMIT || execSync('git rev-parse HEAD').toString().trim(); 9 const commitMessage = execSync('git log -1 --pretty=%B').toString().trim(); 10 const branch = 11 process.env.GIT_BRANCH || 12 process.env.VERCEL_GIT_COMMIT_REF || 13 process.env.COOLIFY_BRANCH || 14 execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); 15 16 return { 17 commitHash: commitHash.substring(0, 7), 18 commitMessage, 19 branch, 20 }; 21 } catch (error) { 22 logger.warn('Failed to get git info:', error); 23 return { 24 commitHash: 'unknown', 25 commitMessage: 'No commit message', 26 branch: 'unknown', 27 }; 28 } 29} 30 31export async function sendDeploymentNotification(startTime: number) { 32 const webhookUrl = process.env.DEPLOYMENT_WEBHOOK_URL; 33 if (!webhookUrl) { 34 logger.warn('DEPLOYMENT_WEBHOOK_URL not set, skipping deployment notification'); 35 return; 36 } 37 38 try { 39 const webhook = new WebhookClient({ url: webhookUrl }); 40 const deploymentTime = Date.now() - startTime; 41 const seconds = (deploymentTime / 1000).toFixed(2); 42 43 const { commitHash, commitMessage, branch } = getGitInfo(); 44 45 await webhook.send({ 46 embeds: [ 47 { 48 title: '<:check:942538737332662282> Aethel was deployed successfully', 49 color: 0xf4f4f4, 50 fields: [ 51 { 52 name: '<:development:1269783674782748775> Branch', 53 value: branch, 54 inline: true, 55 }, 56 { 57 name: '<:4_:1387343665264853092> Commit', 58 value: `\`${commitHash}\``, 59 inline: true, 60 }, 61 { 62 name: '<a:Time:1186795135263051847> Deployment Time', 63 value: `${seconds}s`, 64 inline: true, 65 }, 66 { 67 name: '<:github:1371987360044159016> Commit Message', 68 value: 69 commitMessage.length > 100 70 ? `${commitMessage.substring(0, 100)}...` 71 : commitMessage, 72 }, 73 ], 74 timestamp: new Date().toISOString(), 75 }, 76 ], 77 }); 78 79 logger.info('Deployment notification sent successfully'); 80 } catch (error) { 81 logger.error('Failed to send deployment notification:', error); 82 } 83}