fix(web): let a deploy target be created without a reachable Gitea
The « Nouvelle cible » button was hidden whenever the repository list came back empty, and a Gitea answering 403 took the whole page down with it — so a forge problem removed every way to set up a deployment, including webhook and shell targets that never talk to Gitea at all. The list is now a convenience: its failure is reported as a warning and the repository falls back to a free-text field. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+28
-8
@@ -45,10 +45,17 @@ const KIND_HELP = {
|
||||
|
||||
async function editTarget(existing, repositories, commandsAllowed, level, reload) {
|
||||
const name = input({ value: existing?.name ?? '', placeholder: 'production-web' });
|
||||
const repository = select(
|
||||
repositories.map((item) => ({ value: item.fullName, label: item.fullName })),
|
||||
{ value: existing?.repository ?? repositories[0]?.fullName },
|
||||
);
|
||||
|
||||
// A webhook or a shell command needs no Gitea at all, so an unreachable forge
|
||||
// must not stand between the user and a deploy target: the repository then
|
||||
// falls back to a free-text field.
|
||||
const repository =
|
||||
repositories.length > 0
|
||||
? select(
|
||||
repositories.map((item) => ({ value: item.fullName, label: item.fullName })),
|
||||
{ value: existing?.repository ?? repositories[0]?.fullName },
|
||||
)
|
||||
: input({ value: existing?.repository ?? '', placeholder: 'FWS/FWS-Arch' });
|
||||
const environment = input({ value: existing?.environment ?? 'production' });
|
||||
const kindOptions = KINDS.filter(
|
||||
(kind) => kind.value !== 'command' || (commandsAllowed && level >= LEVELS.OWNER),
|
||||
@@ -104,7 +111,12 @@ async function editTarget(existing, repositories, commandsAllowed, level, reload
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
field('Nom', name),
|
||||
field('Dépôt', repository),
|
||||
field('Dépôt', repository, {
|
||||
help:
|
||||
repositories.length > 0
|
||||
? undefined
|
||||
: 'Format `organisation/depot`. La liste est vide : Gitea est injoignable ou non configuré.',
|
||||
}),
|
||||
field('Environnement', environment, { help: 'production, staging, preview…' }),
|
||||
field('Type', kind),
|
||||
help,
|
||||
@@ -116,7 +128,7 @@ async function editTarget(existing, repositories, commandsAllowed, level, reload
|
||||
),
|
||||
toggle(enabled, (checked) => (enabled = checked), 'Cible active'),
|
||||
),
|
||||
submit: () => name.value.trim() !== '',
|
||||
submit: () => name.value.trim() !== '' && repository.value.trim() !== '',
|
||||
}),
|
||||
{ confirmLabel: existing ? 'Enregistrer' : 'Créer', tone: 'primary' },
|
||||
);
|
||||
@@ -211,15 +223,18 @@ export function render(host, { state }) {
|
||||
return renderAsync(
|
||||
host,
|
||||
async () => {
|
||||
// The repository list is a convenience, not a prerequisite: a Gitea that
|
||||
// answers 403 must not take the whole deployment page down with it.
|
||||
const [targets, deployments, repositories] = await Promise.all([
|
||||
api.get('/api/deploy/targets'),
|
||||
api.get('/api/deployments', { limit: 40 }),
|
||||
api.get('/api/repositories'),
|
||||
api.get('/api/repositories').catch((error) => ({ repositories: [], error: error.message })),
|
||||
]);
|
||||
return {
|
||||
...targets,
|
||||
deployments: deployments.deployments,
|
||||
repositories: repositories.repositories ?? [],
|
||||
repositoriesError: repositories.error ?? null,
|
||||
};
|
||||
},
|
||||
(data) =>
|
||||
@@ -239,7 +254,6 @@ export function render(host, { state }) {
|
||||
}),
|
||||
),
|
||||
level >= LEVELS.DEV &&
|
||||
data.repositories.length > 0 &&
|
||||
button(
|
||||
'Nouvelle cible',
|
||||
() => editTarget(null, data.repositories, data.commandDeploysAllowed, level, reload),
|
||||
@@ -247,6 +261,12 @@ export function render(host, { state }) {
|
||||
),
|
||||
),
|
||||
|
||||
data.repositoriesError &&
|
||||
notice(
|
||||
`Liste des dépôts indisponible (${data.repositoriesError}). Tu peux quand même créer une cible en saisissant le dépôt à la main ; seules les cibles Gitea Actions ont réellement besoin de la forge.`,
|
||||
'warning',
|
||||
),
|
||||
|
||||
!data.commandDeploysAllowed &&
|
||||
notice(
|
||||
'Les déploiements par commande shell sont désactivés (`WEB_ALLOW_COMMAND_DEPLOYS=false`). Les cibles webhook et Gitea Actions restent disponibles.',
|
||||
|
||||
Reference in new issue
Block a user