import { SlashCommandBuilder } from 'discord.js'; import { ACCESS_LEVELS, COLORS } from '../../config/constants.js'; import { asList, gitea, repositoryUrl } from '../../services/gitea/gitea-client.js'; import { replyGiteaFailure, assertGiteaConfigured } from '../../services/gitea/gitea-modals.js'; import { openPanelEditor } from '../../services/gitea/team-recruitment.js'; import { baseEmbed, bullets, successEmbed } from '../../ui/embeds.js'; export const access = ACCESS_LEVELS.USER; export const subcommandAccess = { panel: ACCESS_LEVELS.STAFF }; export const data = new SlashCommandBuilder() .setName('gitea') .setDescription('Activité Gitea de FWS Arch') .addSubcommand((sub) => sub.setName('activity').setDescription('Commits, issues et PR récents')) .addSubcommand((sub) => sub.setName('release').setDescription('Releases disponibles')) .addSubcommand((sub) => sub.setName('panel').setDescription('Publier ou modifier le panneau de recrutement Gitea'), ); const commitLines = (commits) => bullets( asList(commits) .slice(0, 5) .map((commit) => { const message = commit.commit?.message?.split('\n')[0] ?? '(sans message)'; return `\`${commit.sha?.slice(0, 7)}\` ${message} — *${commit.commit?.author?.name ?? 'un compte inconnu'}*`; }), ); /** Read-only summaries of the repository (M5-T06 / M5-T07), plus the panel editor. */ export async function execute(interaction) { if (interaction.options.getSubcommand() === 'panel') { await openPanelEditor(interaction); return; } assertGiteaConfigured(); await interaction.deferReply(); try { if (interaction.options.getSubcommand() === 'release') { const releases = asList(await gitea.listReleases(5)); if (releases.length === 0) { await interaction.editReply({ embeds: [successEmbed('Aucune release publiée pour le moment.')] }); return; } const embed = baseEmbed(COLORS.gitea) .setTitle('📦 Releases FWS Arch') .setURL(repositoryUrl()) .setDescription( releases .map((release) => { const date = release.published_at ? `` : 'date inconnue'; const tag = release.html_url ? `[${release.tag_name}](${release.html_url})` : release.tag_name; return `${release.prerelease ? '🧪' : '📦'} **${tag}** — ${release.name || 'sans titre'} · ${date}`; }) .join('\n'), ); await interaction.editReply({ embeds: [embed] }); return; } const [issues, pulls, commits] = await Promise.all([ gitea.listIssues('state=open&type=issues&limit=50'), gitea.listPullRequests('state=open&limit=50'), gitea.listCommits(5), ]); const embed = baseEmbed(COLORS.gitea) .setTitle('📈 Activité récente') .setURL(repositoryUrl()) .setDescription(commitLines(commits) || 'Aucun commit récent pour le moment.') .addFields( { name: 'Issues ouvertes', value: String(asList(issues).length), inline: true }, { name: 'PR ouvertes', value: String(asList(pulls).length), inline: true }, ); await interaction.editReply({ embeds: [embed] }); } catch (error) { await replyGiteaFailure(interaction, error); } }