refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
+74
-74
@@ -1,74 +1,74 @@
|
||||
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 { baseEmbed, bullets, successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.USER;
|
||||
|
||||
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'));
|
||||
|
||||
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). */
|
||||
export async function execute(interaction) {
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
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 { baseEmbed, bullets, successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.USER;
|
||||
|
||||
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'));
|
||||
|
||||
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). */
|
||||
export async function execute(interaction) {
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user