feat(daemon): execute and verify organisation repository connections
This commit is contained in:
1 parent
32642af4a9
commit
05987f04e2
45 files changed
+1600
-284
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { Plus } from "@lucide/vue";
|
||||
|
||||
@@ -8,6 +8,8 @@ import { Plus } from "@lucide/vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { api } from "@/lib/api";
|
||||
import { useOrgStore, type Identity } from "@/stores/org";
|
||||
import {
|
||||
NumberField,
|
||||
NumberFieldContent,
|
||||
@@ -40,6 +42,7 @@ import HistoryLink from "./HistoryLink.vue";
|
||||
const KIND = "repository-policies";
|
||||
|
||||
interface Repo {
|
||||
connection: string;
|
||||
owner: string;
|
||||
name: string;
|
||||
base: string;
|
||||
@@ -55,11 +58,22 @@ interface Repo {
|
||||
|
||||
const store = useSettingsStore();
|
||||
const { catalog, catalogError } = storeToRefs(store);
|
||||
onMounted(store.load);
|
||||
const organisation = useOrgStore();
|
||||
const agents=ref<Identity[]>([]);
|
||||
const agentError=ref("");
|
||||
onMounted(async()=>{
|
||||
void store.load();
|
||||
try {
|
||||
await organisation.loadOrg();
|
||||
const response=await api.orgAgents<{agents:Identity[]}>(organisation.homeOrg);
|
||||
agents.value=response.agents.filter((agent)=>agent.lifecycle==="active");
|
||||
} catch(cause) {agentError.value=String((cause as Error).message || cause)}
|
||||
});
|
||||
|
||||
const resources = computed(() => resourcesForPage(catalog.value, "repositories"));
|
||||
const draft = computed(() => store.drafts[KIND]);
|
||||
const repos = computed(() => (draft.value?.value ?? []) as Repo[]);
|
||||
const connections = computed(() => (store.drafts["forge-connections"]?.value ?? []) as { id: string; name: string }[]);
|
||||
const error = computed(() => store.pageErrorFor(KIND));
|
||||
|
||||
const ecosystems = ["go", "python", "node", "rust", "custom"];
|
||||
@@ -72,13 +86,32 @@ function addRepo() {
|
||||
if (!draft.value || !owner || !name) return;
|
||||
draft.value.value ??= [];
|
||||
(draft.value.value as Repo[]).push({
|
||||
owner, name, base: "main", ecosystem: "go", gate: [], preflight: null, protect: null,
|
||||
owner, name, connection: "", base: "main", ecosystem: "go", gate: [], preflight: null, protect: null,
|
||||
test_glob: "", persistent_storage: false, max_retries: 0, allow_concurrent: false,
|
||||
});
|
||||
newRepo.value = "";
|
||||
open.value = String((draft.value.value as Repo[]).length - 1);
|
||||
}
|
||||
const protectOf = (repo: Repo) => repo.protect ?? [];
|
||||
interface AccessCheck { verified?: boolean; account?: string; base_branch?: string; message: string }
|
||||
const checkAgent=ref("");
|
||||
const checking=ref("");
|
||||
const results=ref<Record<string,AccessCheck>>({});
|
||||
watch([checkAgent,()=>JSON.stringify(repos.value)],()=>{results.value={}});
|
||||
async function checkAccess(repo:Repo):Promise<void>{
|
||||
if(unsaved.value || !checkAgent.value || checking.value)return;
|
||||
const key=`${repo.owner}/${repo.name}`;
|
||||
const input=JSON.stringify([repo,checkAgent.value]);
|
||||
checking.value=key;
|
||||
delete results.value[key];
|
||||
try {
|
||||
const result=await api.checkRepository<AccessCheck>({owner:repo.owner,repository:repo.name,identity_id:checkAgent.value});
|
||||
if(input===JSON.stringify([repo,checkAgent.value]))results.value[key]=result;
|
||||
}catch(cause){
|
||||
if(input===JSON.stringify([repo,checkAgent.value]))results.value[key]={message:String((cause as Error).message || cause)};
|
||||
}finally{checking.value=""}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -93,6 +126,30 @@ const protectOf = (repo: Repo) => repo.protect ?? [];
|
||||
<template v-if="draft">
|
||||
<CardAccordion v-model:open="open" :items="repos" :title="(r) => `${r.owner}/${r.name}`" remove-label="Remove" mono @remove="repos.splice($event, 1)">
|
||||
<template #default="{ item: repo, index: i }">
|
||||
<SettingRow label="Connection">
|
||||
<Select v-model="repo.connection">
|
||||
<SelectTrigger class="w-64" :aria-label="`Connection for ${repo.name}`"><SelectValue placeholder="Choose a connection" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="connection in connections" :key="connection.id" :value="connection.id">{{ connection.name || connection.id }}</SelectItem>
|
||||
<SelectItem v-if="repo.connection && !connections.some((connection) => connection.id === repo.connection)" :value="repo.connection" disabled>Unavailable connection</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow label="Check access">
|
||||
<div class="grid gap-2">
|
||||
<Select v-model="checkAgent">
|
||||
<SelectTrigger class="w-64" :aria-label="`Check ${repo.name} access as`"><SelectValue placeholder="Choose an agent" /></SelectTrigger>
|
||||
<SelectContent><SelectItem v-for="agent in agents" :key="agent.id" :value="agent.id">{{ agent.display_name }}</SelectItem></SelectContent>
|
||||
</Select>
|
||||
<Button type="button" variant="outline" class="w-fit" :disabled="!checkAgent || !repo.connection || unsaved || !!checking" @click="checkAccess(repo)">{{checking===`${repo.owner}/${repo.name}` ? "Checking…" : "Check access"}}</Button>
|
||||
<p v-if="unsaved" class="text-xs text-fg-muted">Save changes before checking access.</p>
|
||||
<p v-if="agentError" class="text-xs text-danger" role="alert">{{agentError}}</p>
|
||||
<p v-if="results[`${repo.owner}/${repo.name}`]" role="status" class="text-xs" :class="results[`${repo.owner}/${repo.name}`].verified ? 'text-ok' : 'text-danger'">
|
||||
{{ results[`${repo.owner}/${repo.name}`].message }}
|
||||
<span v-if="results[`${repo.owner}/${repo.name}`].verified">{{ results[`${repo.owner}/${repo.name}`].account }} · {{ results[`${repo.owner}/${repo.name}`].base_branch }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Base branch" :for="`repo-${i}-base`">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`repo-${i}-base`" v-model="repo.base" class="max-w-56 font-mono" />
|
||||
|
||||
Reference in new issue
Block a user