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
+26
-6
@@ -45,10 +45,17 @@ const KIND_HELP = {
|
|||||||
|
|
||||||
async function editTarget(existing, repositories, commandsAllowed, level, reload) {
|
async function editTarget(existing, repositories, commandsAllowed, level, reload) {
|
||||||
const name = input({ value: existing?.name ?? '', placeholder: 'production-web' });
|
const name = input({ value: existing?.name ?? '', placeholder: 'production-web' });
|
||||||
const repository = select(
|
|
||||||
|
// 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 })),
|
repositories.map((item) => ({ value: item.fullName, label: item.fullName })),
|
||||||
{ value: existing?.repository ?? repositories[0]?.fullName },
|
{ value: existing?.repository ?? repositories[0]?.fullName },
|
||||||
);
|
)
|
||||||
|
: input({ value: existing?.repository ?? '', placeholder: 'FWS/FWS-Arch' });
|
||||||
const environment = input({ value: existing?.environment ?? 'production' });
|
const environment = input({ value: existing?.environment ?? 'production' });
|
||||||
const kindOptions = KINDS.filter(
|
const kindOptions = KINDS.filter(
|
||||||
(kind) => kind.value !== 'command' || (commandsAllowed && level >= LEVELS.OWNER),
|
(kind) => kind.value !== 'command' || (commandsAllowed && level >= LEVELS.OWNER),
|
||||||
@@ -104,7 +111,12 @@ async function editTarget(existing, repositories, commandsAllowed, level, reload
|
|||||||
'div',
|
'div',
|
||||||
{ class: 'stack' },
|
{ class: 'stack' },
|
||||||
field('Nom', name),
|
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('Environnement', environment, { help: 'production, staging, preview…' }),
|
||||||
field('Type', kind),
|
field('Type', kind),
|
||||||
help,
|
help,
|
||||||
@@ -116,7 +128,7 @@ async function editTarget(existing, repositories, commandsAllowed, level, reload
|
|||||||
),
|
),
|
||||||
toggle(enabled, (checked) => (enabled = checked), 'Cible active'),
|
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' },
|
{ confirmLabel: existing ? 'Enregistrer' : 'Créer', tone: 'primary' },
|
||||||
);
|
);
|
||||||
@@ -211,15 +223,18 @@ export function render(host, { state }) {
|
|||||||
return renderAsync(
|
return renderAsync(
|
||||||
host,
|
host,
|
||||||
async () => {
|
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([
|
const [targets, deployments, repositories] = await Promise.all([
|
||||||
api.get('/api/deploy/targets'),
|
api.get('/api/deploy/targets'),
|
||||||
api.get('/api/deployments', { limit: 40 }),
|
api.get('/api/deployments', { limit: 40 }),
|
||||||
api.get('/api/repositories'),
|
api.get('/api/repositories').catch((error) => ({ repositories: [], error: error.message })),
|
||||||
]);
|
]);
|
||||||
return {
|
return {
|
||||||
...targets,
|
...targets,
|
||||||
deployments: deployments.deployments,
|
deployments: deployments.deployments,
|
||||||
repositories: repositories.repositories ?? [],
|
repositories: repositories.repositories ?? [],
|
||||||
|
repositoriesError: repositories.error ?? null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
(data) =>
|
(data) =>
|
||||||
@@ -239,7 +254,6 @@ export function render(host, { state }) {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
level >= LEVELS.DEV &&
|
level >= LEVELS.DEV &&
|
||||||
data.repositories.length > 0 &&
|
|
||||||
button(
|
button(
|
||||||
'Nouvelle cible',
|
'Nouvelle cible',
|
||||||
() => editTarget(null, data.repositories, data.commandDeploysAllowed, level, reload),
|
() => 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 &&
|
!data.commandDeploysAllowed &&
|
||||||
notice(
|
notice(
|
||||||
'Les déploiements par commande shell sont désactivés (`WEB_ALLOW_COMMAND_DEPLOYS=false`). Les cibles webhook et Gitea Actions restent disponibles.',
|
'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