feat(core): add shared constants, interaction components and Gitea client helpers

Moderation, tickets, polls and Gitea events reuse the same labels, colours and buttons; normalising list responses in the client keeps both commands and webhooks free of version quirks.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:34 +02:00
1 parent 03a217c775
commit 66be463ba3
4 files changed
+77 -6

No files matched your search

+18
View File
@@ -34,6 +34,22 @@ export async function giteaRequest(endpoint, { method = 'GET', body } = {}) {
);
}
/** True when both the Gitea URL and token are configured (M5-T01). */
export function isGiteaConfigured() {
return Boolean(env.gitea.url && env.gitea.token);
}
/** Gitea returns either a bare array or a `{ data: [...] }` wrapper depending on the version. */
export function asList(payload) {
if (Array.isArray(payload)) return payload;
return Array.isArray(payload?.data) ? payload.data : [];
}
/** Human readable URL of the configured repository, used in embeds. */
export function repositoryUrl() {
return env.gitea.url ? `${env.gitea.url}/${env.gitea.owner}/${env.gitea.repo}` : '';
}
const repoPath = () => `/repos/${env.gitea.owner}/${env.gitea.repo}`;
export const gitea = {
@@ -48,4 +64,6 @@ export const gitea = {
listCommits: (limit = 10) => giteaRequest(`${repoPath()}/commits?limit=${limit}`),
listReleases: (limit = 5) => giteaRequest(`${repoPath()}/releases?limit=${limit}`),
getLatestRelease: () => giteaRequest(`${repoPath()}/releases/latest`),
getReleaseByTag: (tag) => giteaRequest(`${repoPath()}/releases/tags/${encodeURIComponent(tag)}`),
listBranches: (limit = 20) => giteaRequest(`${repoPath()}/branches?limit=${limit}`),
};