refactor: format markdown files using prettier, fix spelling concerns, reduce Taskfile bloat

This commit is contained in:
sam committed 2026-09-25 01:10:28 +10:00
1 parent 2051ca94d2
commit 2e00777f07
608 files changed
+63317 -10219

No files matched your search

+114 -27
View File
@@ -3,11 +3,30 @@ import { computed, ref, watch } from "vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { eventTypeLabel, type EventType } from "@/captures/event-types";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import {
draftFromBinding,
@@ -47,26 +66,43 @@ const draft = ref<BindingDraft>(emptyDraft());
watch(
open,
(isOpen) => {
if (isOpen) draft.value = props.binding ? draftFromBinding(props.binding, props.mappings) : emptyDraft();
if (isOpen)
draft.value = props.binding
? draftFromBinding(props.binding, props.mappings)
: emptyDraft();
},
{ immediate: true },
);
const typeMappings = computed(() => mappingsForEventType(props.mappings, draft.value.eventTypeId));
const typeMappings = computed(() =>
mappingsForEventType(props.mappings, draft.value.eventTypeId),
);
// A mapping belongs to one event type, so changing the type clears a mapping
// that no longer fits it.
watch(
() => draft.value.eventTypeId,
() => {
if (!typeMappings.value.some((m) => m.id === draft.value.mappingId)) draft.value.mappingId = "";
if (!typeMappings.value.some((m) => m.id === draft.value.mappingId))
draft.value.mappingId = "";
},
);
const workflow = computed(() => props.workflows.find((w) => w.id === draft.value.workflow));
const declaredInputs = computed(() => Object.entries(workflow.value?.inputs ?? {}).sort(([a], [b]) => a.localeCompare(b)));
const mappingFields = computed(() => props.mappings.find((m) => m.id === draft.value.mappingId)?.fields ?? []);
const stringParams = computed(() => paramsForType(mappingFields.value, "string"));
const workflow = computed(() =>
props.workflows.find((w) => w.id === draft.value.workflow),
);
const declaredInputs = computed(() =>
Object.entries(workflow.value?.inputs ?? {}).sort(([a], [b]) =>
a.localeCompare(b),
),
);
const mappingFields = computed(
() =>
props.mappings.find((m) => m.id === draft.value.mappingId)?.fields ?? [],
);
const stringParams = computed(() =>
paramsForType(mappingFields.value, "string"),
);
// The constant sentinel stands for "no parameter": Select items cannot carry
// an empty value.
@@ -104,7 +140,8 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
<DialogHeader>
<DialogTitle>{{ title }}</DialogTitle>
<DialogDescription>
A binding is not armed until it is approved, and editing one drops it back to pending approval.
A binding is not armed until it is approved, and editing one drops it
back to pending approval.
</DialogDescription>
</DialogHeader>
@@ -123,7 +160,11 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="type in props.eventTypes" :key="type.id" :value="type.id">
<SelectItem
v-for="type in props.eventTypes"
:key="type.id"
:value="type.id"
>
{{ eventTypeLabel(type.id, props.eventTypes) }}
</SelectItem>
</SelectGroup>
@@ -135,11 +176,21 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
<FieldLabel for="binding-mapping">Field mapping</FieldLabel>
<Select v-model="draft.mappingId" :disabled="!typeMappings.length">
<SelectTrigger id="binding-mapping" class="w-full">
<SelectValue :placeholder="draft.eventTypeId && !typeMappings.length ? 'No mappings for this event type' : 'Pick a mapping'" />
<SelectValue
:placeholder="
draft.eventTypeId && !typeMappings.length
? 'No mappings for this event type'
: 'Pick a mapping'
"
/>
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="mapping in typeMappings" :key="mapping.id" :value="String(mapping.id)">
<SelectItem
v-for="mapping in typeMappings"
:key="mapping.id"
:value="String(mapping.id)"
>
{{ mapping.name }}
</SelectItem>
</SelectGroup>
@@ -149,8 +200,15 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
<Field>
<FieldLabel for="binding-filter">Filter</FieldLabel>
<Input id="binding-filter" v-model="draft.filter" class="font-mono text-xs" placeholder='severity in ["high", "critical"]' />
<FieldDescription>Optional CEL over the mapping's parameters.</FieldDescription>
<Input
id="binding-filter"
v-model="draft.filter"
class="font-mono text-xs"
placeholder='severity in ["high", "critical"]'
/>
<FieldDescription
>Optional CEL over the mapping's parameters.</FieldDescription
>
</Field>
<Field>
@@ -161,7 +219,11 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem v-for="workflow in props.workflows" :key="workflow.id" :value="workflow.id">
<SelectItem
v-for="workflow in props.workflows"
:key="workflow.id"
:value="workflow.id"
>
{{ workflow.name }}
</SelectItem>
</SelectGroup>
@@ -172,23 +234,37 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
<Field v-for="[name, spec] in declaredInputs" :key="name">
<FieldLabel :for="`binding-input-${name}`">
Input <span class="font-mono">{{ name }}</span>
<span class="text-fg-muted">({{ spec.type }}{{ spec.required ? ", required" : "" }})</span>
<span class="text-fg-muted"
>({{ spec.type }}{{ spec.required ? ", required" : "" }})</span
>
</FieldLabel>
<div class="grid grid-cols-2 items-start gap-3">
<Select :model-value="inputSource(name)" @update:model-value="setInputSource(name, $event)">
<Select
:model-value="inputSource(name)"
@update:model-value="setInputSource(name, $event)"
>
<SelectTrigger :id="`binding-input-${name}`" class="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem :value="CONSTANT">Constant</SelectItem>
<SelectItem v-for="field in paramsForType(mappingFields, spec.type)" :key="field.name" :value="field.name">
<SelectItem
v-for="field in paramsForType(mappingFields, spec.type)"
:key="field.name"
:value="field.name"
>
{{ field.name }}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<Input v-if="!inputDraft(name).param" v-model="inputDraft(name).value" class="font-mono text-xs" placeholder="value" />
<Input
v-if="!inputDraft(name).param"
v-model="inputDraft(name).value"
class="font-mono text-xs"
placeholder="value"
/>
</div>
</Field>
@@ -200,14 +276,23 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectItem :value="NO_PARAM">A pinned or configured repo</SelectItem>
<SelectItem v-for="field in stringParams" :key="field.name" :value="field.name">
<SelectItem :value="NO_PARAM"
>A pinned or configured repo</SelectItem
>
<SelectItem
v-for="field in stringParams"
:key="field.name"
:value="field.name"
>
Parameter {{ field.name }}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<FieldDescription>A parameter must hold owner/name and name a configured repo.</FieldDescription>
<FieldDescription
>A parameter must hold owner/name and name a configured
repo.</FieldDescription
>
</Field>
<Field v-if="takesRepository(workflow) && !draft.repoParam">
@@ -222,10 +307,10 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</Field>
</div>
<FieldDescription>
Optional. A pin is both halves or neither, so leave both blank to use the single configured repo.
Optional. A pin is both halves or neither, so leave both blank to
use the single configured repo.
</FieldDescription>
</Field>
</FieldGroup>
<!-- Beside the buttons, not at the top: the dialog scrolls, and Save is
@@ -236,7 +321,9 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</Alert>
<DialogFooter class="mt-4">
<Button type="button" variant="outline" @click="open = false">Cancel</Button>
<Button type="button" variant="outline" @click="open = false"
>Cancel</Button
>
<Button type="submit" :disabled="props.saving">
<Spinner v-if="props.saving" data-icon="inline-start" />
{{ props.saving ? "Saving" : "Save" }}
+39 -8
View File
@@ -6,10 +6,19 @@ import { Button } from "@/components/ui/button";
import { TableCell, TableRow } from "@/components/ui/table";
import BindingStatusBadge from "./BindingStatusBadge.vue";
import { eventTypeLabel, type EventType } from "@/captures/event-types";
import { bindingEventType, repoPin, type Binding, type MappingOption } from "./binding-draft";
import {
bindingEventType,
repoPin,
type Binding,
type MappingOption,
} from "./binding-draft";
/** One saved binding's summary row. */
const props = defineProps<{ binding: Binding; mappings: MappingOption[]; eventTypes: EventType[] }>();
const props = defineProps<{
binding: Binding;
mappings: MappingOption[];
eventTypes: EventType[];
}>();
const emit = defineEmits<{
edit: [binding: Binding];
approve: [binding: Binding];
@@ -22,30 +31,52 @@ const emit = defineEmits<{
<TableCell class="font-medium">{{ props.binding.name }}</TableCell>
<TableCell class="font-mono text-fg-muted">
<div class="flex items-center gap-2">
{{ eventTypeLabel(bindingEventType(props.binding, props.mappings), props.eventTypes) }}
{{
eventTypeLabel(
bindingEventType(props.binding, props.mappings),
props.eventTypes,
)
}}
<Badge v-if="props.binding.unsigned" variant="warn">Unsigned</Badge>
</div>
</TableCell>
<TableCell class="max-w-56 truncate font-mono text-xs text-fg-muted" :title="props.binding.filter">
<TableCell
class="max-w-56 truncate font-mono text-xs text-fg-muted"
:title="props.binding.filter"
>
{{ props.binding.filter || "—" }}
</TableCell>
<TableCell>{{ props.binding.workflow || "—" }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{ repoPin(props.binding) }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{
repoPin(props.binding)
}}</TableCell>
<TableCell><BindingStatusBadge :status="props.binding.status" /></TableCell>
<TableCell>
<div class="flex items-center justify-end gap-1">
<Button variant="outline" size="sm" @click="emit('edit', props.binding)">
<Button
variant="outline"
size="sm"
@click="emit('edit', props.binding)"
>
<Pencil data-icon="inline-start" />
Edit
</Button>
<!-- Only a pending binding can be approved. An armed binding is
already firing, so the button would be a no-op -- or worse, a
misleading one. -->
<Button v-if="props.binding.status === 'pending_approval'" size="sm" @click="emit('approve', props.binding)">
<Button
v-if="props.binding.status === 'pending_approval'"
size="sm"
@click="emit('approve', props.binding)"
>
<Check data-icon="inline-start" />
Approve
</Button>
<Button variant="outline" size="sm" @click="emit('delete', props.binding)">
<Button
variant="outline"
size="sm"
@click="emit('delete', props.binding)"
>
<Trash2 data-icon="inline-start" />
Delete
</Button>
+3 -1
View File
@@ -9,5 +9,7 @@ const props = defineProps<{ status?: string }>();
</script>
<template>
<Badge :variant="statusKind(props.status)">{{ statusLabel(props.status) }}</Badge>
<Badge :variant="statusKind(props.status)">{{
statusLabel(props.status)
}}</Badge>
</template>
+5 -1
View File
@@ -110,6 +110,10 @@ async function handleDelete(binding: Binding): Promise<void> {
@save="handleSave"
/>
<DeleteBindingDialog :binding="deleting" @confirm="handleDelete" @cancel="deleting = null" />
<DeleteBindingDialog
:binding="deleting"
@confirm="handleDelete"
@cancel="deleting = null"
/>
</div>
</template>
+21 -5
View File
@@ -2,9 +2,20 @@
import { computed } from "vue";
import { Card, CardContent } from "@/components/ui/card";
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import {
Empty,
EmptyDescription,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import { Skeleton } from "@/components/ui/skeleton";
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import {
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import BindingRow from "./BindingRow.vue";
import type { EventType } from "@/captures/event-types";
import type { Binding, MappingOption } from "./binding-draft";
@@ -32,7 +43,9 @@ const rows = computed(() => props.bindings ?? []);
// that, where a blanket "cannot reach archied" would be false about a daemon
// that answered.
const failureTitle = computed(() =>
props.failure?.kind === "unconfigured" ? "Bindings are not configured" : "Cannot reach archied",
props.failure?.kind === "unconfigured"
? "Bindings are not configured"
: "Cannot reach archied",
);
</script>
@@ -48,7 +61,8 @@ const failureTitle = computed(() =>
<EmptyHeader>
<EmptyTitle>No bindings yet</EmptyTitle>
<EmptyDescription>
Create one from a saved field mapping to turn a captured webhook into a workflow.
Create one from a saved field mapping to turn a captured webhook into a
workflow.
</EmptyDescription>
</EmptyHeader>
</Empty>
@@ -70,7 +84,9 @@ const failureTitle = computed(() =>
<TableBody>
<template v-if="loading">
<TableRow v-for="row in 3" :key="row">
<TableCell v-for="col in 7" :key="col"><Skeleton class="h-4 w-full" /></TableCell>
<TableCell v-for="col in 7" :key="col"
><Skeleton class="h-4 w-full"
/></TableCell>
</TableRow>
</template>
<template v-else>
+5 -3
View File
@@ -36,13 +36,15 @@ function onOpenChange(open: boolean): void {
<AlertDialogHeader>
<AlertDialogTitle>Delete "{{ props.binding?.name }}"?</AlertDialogTitle>
<AlertDialogDescription>
It stops dispatching immediately and cannot be recovered. Captured events for its source keep
arriving; they just stop starting tasks.
It stops dispatching immediately and cannot be recovered. Captured
events for its source keep arriving; they just stop starting tasks.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction variant="destructive" @click="confirm">Delete</AlertDialogAction>
<AlertDialogAction variant="destructive" @click="confirm"
>Delete</AlertDialogAction
>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
+35 -9
View File
@@ -53,7 +53,10 @@ export interface MappingOption {
/** The mappings that belong to one event type, which are the ones a binding
* on that type can use. */
export function mappingsForEventType(mappings: MappingOption[], eventTypeId: string): MappingOption[] {
export function mappingsForEventType(
mappings: MappingOption[],
eventTypeId: string,
): MappingOption[] {
if (!eventTypeId) return [];
return mappings.filter((m) => m.event_type_id === eventTypeId);
}
@@ -75,8 +78,13 @@ export function takesRepository(workflow?: WorkflowOption): boolean {
}
/** A mapping's parameters a workflow input of this type can read. */
export function paramsForType(fields: MappingField[], type: string): MappingField[] {
return fields.filter((f) => type === "any" || f.type === "any" || f.type === type);
export function paramsForType(
fields: MappingField[],
type: string,
): MappingField[] {
return fields.filter(
(f) => type === "any" || f.type === "any" || f.type === type,
);
}
/** One input's assignment as the editor holds it: a parameter name, or the
@@ -96,7 +104,9 @@ export function constantValue(text: string, type: string): unknown {
case "string":
return text;
case "number":
return text.trim() !== "" && !Number.isNaN(Number(text)) ? Number(text) : text;
return text.trim() !== "" && !Number.isNaN(Number(text))
? Number(text)
: text;
case "bool":
return text === "true" ? true : text === "false" ? false : text;
default:
@@ -164,7 +174,10 @@ export function emptyDraft(): BindingDraft {
};
}
export function draftFromBinding(binding: Binding, mappings: MappingOption[]): BindingDraft {
export function draftFromBinding(
binding: Binding,
mappings: MappingOption[],
): BindingDraft {
const mapping = mappings.find((m) => m.id === binding.mapping_id);
return {
id: binding.id,
@@ -179,7 +192,14 @@ export function draftFromBinding(binding: Binding, mappings: MappingOption[]): B
inputs: Object.fromEntries(
Object.entries(binding.inputs ?? {}).map(([name, src]) => [
name,
{ param: src.param ?? "", value: src.param ? "" : typeof src.value === "string" ? src.value : JSON.stringify(src.value) },
{
param: src.param ?? "",
value: src.param
? ""
: typeof src.value === "string"
? src.value
: JSON.stringify(src.value),
},
]),
),
};
@@ -197,7 +217,8 @@ export function bindingPayload(
for (const [name, spec] of Object.entries(declared)) {
const src = draft.inputs[name];
if (src?.param) inputs[name] = { param: src.param };
else if (src && src.value !== "") inputs[name] = { value: constantValue(src.value, spec.type) };
else if (src && src.value !== "")
inputs[name] = { value: constantValue(src.value, spec.type) };
}
const repository = takesRepository(workflow);
return {
@@ -217,10 +238,15 @@ export function bindingPayload(
* single-configured-repo default. */
export function repoPin(binding: Binding): string {
if (binding.repo_param) return `from ${binding.repo_param}`;
return binding.owner && binding.repo ? `${binding.owner}/${binding.repo}` : "—";
return binding.owner && binding.repo
? `${binding.owner}/${binding.repo}`
: "—";
}
/** The event type a row shows: its mapping's. */
export function bindingEventType(binding: Binding, mappings: MappingOption[]): string | undefined {
export function bindingEventType(
binding: Binding,
mappings: MappingOption[],
): string | undefined {
return mappings.find((m) => m.id === binding.mapping_id)?.event_type_id;
}
+8 -3
View File
@@ -23,9 +23,13 @@ export interface LoadFailure {
}
function failureFor(err: unknown): LoadFailure {
const message = err instanceof Error && err.message ? err.message : String(err);
const message =
err instanceof Error && err.message ? err.message : String(err);
const status = err instanceof ApiError ? err.status : undefined;
return { kind: status === 501 || status === 503 ? "unconfigured" : "failed", message };
return {
kind: status === 501 || status === 503 ? "unconfigured" : "failed",
message,
};
}
/**
@@ -87,7 +91,8 @@ export function useBindings() {
await load();
return true;
} catch (err) {
saveFailure.value = err instanceof Error && err.message ? err.message : String(err);
saveFailure.value =
err instanceof Error && err.message ? err.message : String(err);
return false;
} finally {
saving.value = false;