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:
7 files changed
+470
-12
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
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 { UserFacingError } from '../../core/errors.js';
|
||||
import { asList, gitea, repositoryUrl } from '../../services/gitea/gitea-client.js';
|
||||
import { issueEmbed } from '../../services/gitea/gitea-embeds.js';
|
||||
import {
|
||||
assertGiteaConfigured,
|
||||
openIssueModal,
|
||||
replyGiteaFailure,
|
||||
} from '../../services/gitea/gitea-modals.js';
|
||||
import { baseEmbed, successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.USER;
|
||||
|
||||
@@ -21,7 +29,43 @@ export const data = new SlashCommandBuilder()
|
||||
)
|
||||
.addSubcommand((sub) => sub.setName('list').setDescription('Lister les issues ouvertes'));
|
||||
|
||||
// TODO(M5-T02 / M5-T03): implement with services/gitea/gitea-client.js.
|
||||
/** Issues can be browsed and created straight from Discord (M5-T02 / M5-T03). */
|
||||
export async function execute(interaction) {
|
||||
await interaction.reply({ embeds: [notImplementedEmbed(`/issue ${interaction.options.getSubcommand()}`)] });
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
if (subcommand === 'create') {
|
||||
await openIssueModal(interaction);
|
||||
return;
|
||||
}
|
||||
|
||||
assertGiteaConfigured();
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
if (subcommand === 'view') {
|
||||
const issue = await gitea.getIssue(interaction.options.getInteger('number', true));
|
||||
if (!issue?.number) throw new UserFacingError('Cette issue est introuvable sur Gitea.');
|
||||
await interaction.editReply({ embeds: [issueEmbed(issue)] });
|
||||
return;
|
||||
}
|
||||
|
||||
const issues = asList(await gitea.listIssues('state=open&type=issues&limit=15'));
|
||||
if (issues.length === 0) {
|
||||
await interaction.editReply({ embeds: [successEmbed('Aucune issue ouverte. 🎉')] });
|
||||
return;
|
||||
}
|
||||
|
||||
const embed = baseEmbed(COLORS.gitea)
|
||||
.setTitle('Issues ouvertes')
|
||||
.setURL(`${repositoryUrl()}/issues`)
|
||||
.setDescription(
|
||||
issues
|
||||
.map((issue) => `**#${issue.number}** ${issue.title} — *${issue.user?.login ?? 'inconnu'}*`)
|
||||
.join('\n'),
|
||||
)
|
||||
.setFooter({ text: `${issues.length} issue(s) affichée(s)` });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
} catch (error) {
|
||||
await replyGiteaFailure(interaction, error);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
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 { UserFacingError } from '../../core/errors.js';
|
||||
import { asList, gitea, repositoryUrl } from '../../services/gitea/gitea-client.js';
|
||||
import { pullRequestEmbed } from '../../services/gitea/gitea-embeds.js';
|
||||
import {
|
||||
assertGiteaConfigured,
|
||||
openPullRequestModal,
|
||||
replyGiteaFailure,
|
||||
} from '../../services/gitea/gitea-modals.js';
|
||||
import { baseEmbed, successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.USER;
|
||||
export const subcommandAccess = { create: ACCESS_LEVELS.DEV };
|
||||
@@ -25,7 +33,47 @@ export const data = new SlashCommandBuilder()
|
||||
)
|
||||
.addSubcommand((sub) => sub.setName('list').setDescription('Lister les pull requests ouvertes'));
|
||||
|
||||
// TODO(M5-T04 / M5-T05): implement with services/gitea/gitea-client.js.
|
||||
/** The title and description are collected through a modal (M5-T04 / M5-T05). */
|
||||
export async function execute(interaction) {
|
||||
await interaction.reply({ embeds: [notImplementedEmbed(`/pr ${interaction.options.getSubcommand()}`)] });
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
if (subcommand === 'create') {
|
||||
await openPullRequestModal(interaction);
|
||||
return;
|
||||
}
|
||||
|
||||
assertGiteaConfigured();
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
if (subcommand === 'view') {
|
||||
const pull = await gitea.getPullRequest(interaction.options.getInteger('number', true));
|
||||
if (!pull?.number) throw new UserFacingError('Cette pull request est introuvable sur Gitea.');
|
||||
await interaction.editReply({ embeds: [pullRequestEmbed(pull)] });
|
||||
return;
|
||||
}
|
||||
|
||||
const pulls = asList(await gitea.listPullRequests('state=open&limit=15'));
|
||||
if (pulls.length === 0) {
|
||||
await interaction.editReply({ embeds: [successEmbed('Aucune pull request ouverte.')] });
|
||||
return;
|
||||
}
|
||||
|
||||
const embed = baseEmbed(COLORS.gitea)
|
||||
.setTitle('Pull requests ouvertes')
|
||||
.setURL(`${repositoryUrl()}/pulls`)
|
||||
.setDescription(
|
||||
pulls
|
||||
.map(
|
||||
(pull) =>
|
||||
`**#${pull.number}** ${pull.title} — ${pull.head?.ref ?? '?'} → ${pull.base?.ref ?? '?'} ` +
|
||||
`(*${pull.user?.login ?? 'inconnu'}*)`,
|
||||
)
|
||||
.join('\n'),
|
||||
)
|
||||
.setFooter({ text: `${pulls.length} PR affichée(s)` });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
} catch (error) {
|
||||
await replyGiteaFailure(interaction, error);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user