This repository has no description
1// Fetch real sh.tangled.repo.issue records live from repo-owner PDSes.
2import pg from "pg";
3import { readFileSync } from "node:fs";
4function fromEnv(k){ if(process.env[k])return process.env[k]; for(const p of["../.env",".env"]){try{const m=readFileSync(p,"utf8").match(new RegExp(`^\\s*${k}\\s*=\\s*(.+)$`,"m"));if(m)return m[1].trim();}catch{}} }
5const pool = new pg.Pool({ connectionString: fromEnv("DB_CONNECTION_STRING"), ssl: { rejectUnauthorized: false }, max: 3 });
6
7// Owners of embedded repos, with their PDS host.
8const rows = (await pool.query(`
9 select distinct tr.owner_did, pa.pds_host,
10 (select repo_name from tangled_readmes r where r.repo_did = coalesce(tr.repo_did, tr.record_raw->>'repoDid') and r.embedding is not null limit 1) as a_repo
11 from tangled_repos tr
12 join tangled_pds_accounts pa on pa.did = tr.owner_did
13 where exists (select 1 from tangled_readmes r where r.repo_did = coalesce(tr.repo_did, tr.record_raw->>'repoDid') and r.embedding is not null)
14 limit 80`)).rows;
15await pool.end();
16
17console.log(`probing ${rows.length} owner PDSes for sh.tangled.repo.issue ...`);
18const pdsUrl = (h) => (/^https?:\/\//.test(h) ? h : `https://${h}`);
19
20let found = [];
21async function listIssues(r) {
22 const url = `${pdsUrl(r.pds_host)}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(r.owner_did)}&collection=sh.tangled.repo.issue&limit=30`;
23 try {
24 const ctrl = new AbortController(); const t = setTimeout(() => ctrl.abort(), 10000);
25 const resp = await fetch(url, { signal: ctrl.signal, headers: { accept: "application/json" } });
26 clearTimeout(t);
27 if (!resp.ok) return;
28 const j = await resp.json();
29 for (const rec of j.records ?? []) found.push({ owner: r.owner_did, uri: rec.uri, value: rec.value });
30 } catch {}
31}
32// simple concurrency
33const q = rows.slice();
34await Promise.all(Array.from({ length: 12 }, async () => { while (q.length) await listIssues(q.pop()); }));
35
36console.log(`\nfound ${found.length} issue records`);
37if (found.length) {
38 console.log("\nsample issue record value keys:", Object.keys(found[0].value));
39 console.log("sample record:", JSON.stringify(found[0], null, 2).slice(0, 900));
40 console.log("\nfirst few titles:");
41 for (const f of found.slice(0, 8)) console.log(` - ${f.value.title ?? "(no title)"} [repo ref: ${JSON.stringify(f.value.repo ?? f.value.subject ?? "?")}]`);
42}