This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import { Express, Request, Response } from "express";
|
||||
import { EmbedBuilder, TextChannel } from "discord.js";
|
||||
import {
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
ContainerBuilder,
|
||||
MessageFlags,
|
||||
SectionBuilder,
|
||||
SeparatorBuilder,
|
||||
SeparatorSpacingSize,
|
||||
TextChannel,
|
||||
TextDisplayBuilder,
|
||||
ThumbnailBuilder,
|
||||
} from "discord.js";
|
||||
import { CHANNELS } from "../config";
|
||||
import { client, db } from "../index";
|
||||
|
||||
@@ -17,12 +28,10 @@ export default async function gitCommitPOST(app: Express) {
|
||||
}
|
||||
|
||||
if (event !== "push") {
|
||||
return res
|
||||
.status(200)
|
||||
.json({
|
||||
success: true,
|
||||
message: `Event '${event}' ignored`,
|
||||
});
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `Event '${event}' ignored`,
|
||||
});
|
||||
}
|
||||
|
||||
const body = req.body;
|
||||
@@ -51,32 +60,87 @@ export default async function gitCommitPOST(app: Express) {
|
||||
commitLines.push(`...and ${commits.length - SHOW_MAX} more`);
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(forced ? 0xff4444 : 0x2ea44f)
|
||||
.setTitle(
|
||||
`${forced ? "⚠️ Force Push" : "📦 New Push"} to \`${branch}\``,
|
||||
)
|
||||
.setURL(compareUrl)
|
||||
.setAuthor({
|
||||
name: pusher.name,
|
||||
iconURL: `https://github.com/${pusher.name}.png`,
|
||||
url: `https://github.com/${pusher.name}`,
|
||||
})
|
||||
.addFields(
|
||||
{ name: "🌿 Branch", value: `\`${branch}\``, inline: true },
|
||||
{
|
||||
name: `📝 Commits (${commits.length})`,
|
||||
value: commitLines.join("\n") || "_No commits_",
|
||||
},
|
||||
)
|
||||
.setFooter({
|
||||
text: `Delivery: ${req.headers["x-github-delivery"] ?? "unknown"}`,
|
||||
})
|
||||
.setTimestamp(
|
||||
headCommit.timestamp
|
||||
? new Date(headCommit.timestamp)
|
||||
: new Date(),
|
||||
const container = new ContainerBuilder().setAccentColor(
|
||||
forced ? 0xff4444 : 0x2ea44f,
|
||||
);
|
||||
|
||||
// Author + title section
|
||||
container.addSectionComponents(
|
||||
new SectionBuilder()
|
||||
.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
`## ${forced ? "⚠️ Force Push" : "📦 New Push"} to \`${branch}\``,
|
||||
),
|
||||
)
|
||||
.setThumbnailAccessory(
|
||||
new ThumbnailBuilder({
|
||||
media: {
|
||||
url: `https://github.com/${pusher.name}.png`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
container.addSeparatorComponents(
|
||||
new SeparatorBuilder()
|
||||
.setDivider(true)
|
||||
.setSpacing(SeparatorSpacingSize.Small),
|
||||
);
|
||||
|
||||
// Branch & commits
|
||||
container.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
`**🌿 Branch:** \`${branch}\``,
|
||||
),
|
||||
);
|
||||
container.addSeparatorComponents(
|
||||
new SeparatorBuilder()
|
||||
.setDivider(false)
|
||||
.setSpacing(SeparatorSpacingSize.Small),
|
||||
);
|
||||
container.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
`**📝 Commits (${commits.length})**\n${
|
||||
commitLines.join("\n") || "_No commits_"
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
// Compare link button (only if a URL is available)
|
||||
if (compareUrl) {
|
||||
container.addSeparatorComponents(
|
||||
new SeparatorBuilder()
|
||||
.setDivider(true)
|
||||
.setSpacing(SeparatorSpacingSize.Small),
|
||||
);
|
||||
container.addSectionComponents(
|
||||
new SectionBuilder()
|
||||
.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
"🔗 **View Changes**",
|
||||
),
|
||||
)
|
||||
.setButtonAccessory(
|
||||
new ButtonBuilder()
|
||||
.setLabel("Compare")
|
||||
.setURL(compareUrl)
|
||||
.setStyle(ButtonStyle.Link),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Footer
|
||||
container.addSeparatorComponents(
|
||||
new SeparatorBuilder()
|
||||
.setDivider(false)
|
||||
.setSpacing(SeparatorSpacingSize.Small),
|
||||
);
|
||||
container.addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
`-# Delivery: ${
|
||||
req.headers["x-github-delivery"] ?? "unknown"
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
const channel = (await client.channels.fetch(
|
||||
configured_channel,
|
||||
@@ -90,7 +154,10 @@ export default async function gitCommitPOST(app: Express) {
|
||||
.json({ error: "Discord channel unavailable" });
|
||||
}
|
||||
|
||||
const message = await channel.send({ embeds: [embed] });
|
||||
const message = await channel.send({
|
||||
flags: MessageFlags.IsComponentsV2,
|
||||
components: [container],
|
||||
});
|
||||
console.log(
|
||||
`[WEB-gitCommit] Push event sent to configured channel (${commits.length} commits on ${branch})`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user