feat(gitea): add embeds, modals and the issue and pull request commands

Creating an issue or a pull request needs a title and a description, which do not fit in a slash command option, so the branches chosen as options are kept in memory for a few minutes until the modal is submitted.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:40 +02:00
1 parent 66be463ba3
commit 76d0bf9250
7 files changed
+470 -12

No files matched your search

+61 -4
View File
@@ -1,6 +1,8 @@
import { SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { notImplementedEmbed } from '../../ui/embeds.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 { baseEmbed, successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.USER;
@@ -10,7 +12,62 @@ export const data = new SlashCommandBuilder()
.addSubcommand((sub) => sub.setName('activity').setDescription('Commits, issues et PR récents'))
.addSubcommand((sub) => sub.setName('release').setDescription('Releases disponibles'));
// TODO(M5-T06 / M5-T07): implement with services/gitea/gitea-client.js.
const commitLines = (commits) =>
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 ?? 'inconnu'}*`;
})
.join('\n');
/** Read-only summaries of the repository (M5-T06 / M5-T07). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed(`/gitea ${interaction.options.getSubcommand()}`)] });
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
? `<t:${Math.floor(new Date(release.published_at).getTime() / 1000)}:D>`
: '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.')
.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);
}
}