@gaud_erp/paperclip-github-manager 1.3.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/manifest.js +14 -1
- package/dist/manifest.js.map +2 -2
- package/dist/ui/index.js +74 -9
- package/dist/ui/index.js.map +2 -2
- package/dist/worker.js +95 -0
- package/dist/worker.js.map +3 -3
- package/package.json +1 -1
- package/src/db/migrations/002_repo_graph_cache.sql +3 -0
package/dist/worker.js
CHANGED
|
@@ -18,9 +18,11 @@ __export(queries_exports, {
|
|
|
18
18
|
getLinksForPR: () => getLinksForPR,
|
|
19
19
|
getPRByRepoAndNumber: () => getPRByRepoAndNumber,
|
|
20
20
|
getRepoByFullName: () => getRepoByFullName,
|
|
21
|
+
getRepoGraph: () => getRepoGraph,
|
|
21
22
|
linkPRToCard: () => linkPRToCard,
|
|
22
23
|
listPRs: () => listPRs,
|
|
23
24
|
listRepos: () => listRepos,
|
|
25
|
+
saveRepoGraph: () => saveRepoGraph,
|
|
24
26
|
upsertIssue: () => upsertIssue,
|
|
25
27
|
upsertPR: () => upsertPR,
|
|
26
28
|
upsertRepo: () => upsertRepo
|
|
@@ -251,6 +253,23 @@ async function getLastSyncTime(db) {
|
|
|
251
253
|
);
|
|
252
254
|
return rows.length > 0 ? rows[0].finished_at : null;
|
|
253
255
|
}
|
|
256
|
+
async function saveRepoGraph(db, repoId, graphJson) {
|
|
257
|
+
await db.execute(
|
|
258
|
+
`UPDATE ${S}.gh_repositories SET graph_json=$1, graph_generated_at=$2 WHERE id=$3`,
|
|
259
|
+
[graphJson, (/* @__PURE__ */ new Date()).toISOString(), repoId]
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
async function getRepoGraph(db, fullName) {
|
|
263
|
+
const rows = await db.query(
|
|
264
|
+
`SELECT graph_json, graph_generated_at FROM ${S}.gh_repositories WHERE full_name = $1 AND graph_json IS NOT NULL`,
|
|
265
|
+
[fullName]
|
|
266
|
+
);
|
|
267
|
+
if (rows.length === 0) return null;
|
|
268
|
+
return {
|
|
269
|
+
graphJson: rows[0].graph_json,
|
|
270
|
+
generatedAt: rows[0].graph_generated_at
|
|
271
|
+
};
|
|
272
|
+
}
|
|
254
273
|
var S;
|
|
255
274
|
var init_queries = __esm({
|
|
256
275
|
"src/db/queries.ts"() {
|
|
@@ -9244,6 +9263,7 @@ function isRateLimitSafe(rateLimit, threshold = 100) {
|
|
|
9244
9263
|
}
|
|
9245
9264
|
|
|
9246
9265
|
// src/review/review-tools.ts
|
|
9266
|
+
init_queries();
|
|
9247
9267
|
var MAX_DIFF_CHARS = 12e4;
|
|
9248
9268
|
var MAX_FILE_CHARS = 128e3;
|
|
9249
9269
|
function registerReviewTools(ctx) {
|
|
@@ -9442,6 +9462,62 @@ ${diff}`,
|
|
|
9442
9462
|
return { content: items.map((i) => `#${i.number} ${i.title} [${i.state}]`).join("\n"), data: { items } };
|
|
9443
9463
|
}
|
|
9444
9464
|
);
|
|
9465
|
+
ctx.tools.register(
|
|
9466
|
+
"github_get_repo_structure",
|
|
9467
|
+
{
|
|
9468
|
+
displayName: "Get Repo Structure",
|
|
9469
|
+
description: "Get the cached directory and file structure of a repository. Call this FIRST before reading files to understand codebase layout.",
|
|
9470
|
+
parametersSchema: {
|
|
9471
|
+
type: "object",
|
|
9472
|
+
properties: {
|
|
9473
|
+
repo_full_name: { type: "string", description: "Repository in owner/repo format" }
|
|
9474
|
+
},
|
|
9475
|
+
required: ["repo_full_name"]
|
|
9476
|
+
}
|
|
9477
|
+
},
|
|
9478
|
+
async (params, runCtx) => {
|
|
9479
|
+
const { repo_full_name, refresh } = params;
|
|
9480
|
+
const companyId = runCtx.companyId;
|
|
9481
|
+
if (refresh && companyId) {
|
|
9482
|
+
const repo = await getRepoByFullName(ctx.db, repo_full_name);
|
|
9483
|
+
if (repo) {
|
|
9484
|
+
const { data: treeData } = await githubFetch(
|
|
9485
|
+
ctx,
|
|
9486
|
+
companyId,
|
|
9487
|
+
`/repos/${repo_full_name}/git/trees/${repo.defaultBranch}?recursive=1`
|
|
9488
|
+
);
|
|
9489
|
+
const tree = treeData.tree;
|
|
9490
|
+
const dirs = [];
|
|
9491
|
+
const files = [];
|
|
9492
|
+
for (const entry of tree) {
|
|
9493
|
+
const p = entry.path;
|
|
9494
|
+
if (entry.type === "tree" && p.split("/").length <= 3) dirs.push(p);
|
|
9495
|
+
else if (entry.type === "blob" && (p.split("/").length <= 2 || /\.(ts|js|py|go|rs|java|json|ya?ml|toml|md)$/.test(p))) files.push(p);
|
|
9496
|
+
}
|
|
9497
|
+
const graph2 = { dirs, files, defaultBranch: repo.defaultBranch, language: repo.language };
|
|
9498
|
+
await saveRepoGraph(ctx.db, repo.id, JSON.stringify(graph2));
|
|
9499
|
+
}
|
|
9500
|
+
}
|
|
9501
|
+
const cached = await getRepoGraph(ctx.db, repo_full_name);
|
|
9502
|
+
if (!cached) {
|
|
9503
|
+
return { content: `No cached structure for ${repo_full_name}. Run a full sync first or call with refresh=true.` };
|
|
9504
|
+
}
|
|
9505
|
+
const graph = JSON.parse(cached.graphJson);
|
|
9506
|
+
const summary = [
|
|
9507
|
+
`Repository: ${repo_full_name}`,
|
|
9508
|
+
`Language: ${graph.language ?? "unknown"}`,
|
|
9509
|
+
`Default branch: ${graph.defaultBranch}`,
|
|
9510
|
+
`Generated: ${cached.generatedAt}`,
|
|
9511
|
+
``,
|
|
9512
|
+
`Directories (${graph.dirs.length}):`,
|
|
9513
|
+
...graph.dirs.map((d) => ` ${d}/`),
|
|
9514
|
+
``,
|
|
9515
|
+
`Key files (${graph.files.length}):`,
|
|
9516
|
+
...graph.files.map((f) => ` ${f}`)
|
|
9517
|
+
].join("\n");
|
|
9518
|
+
return { content: summary, data: graph };
|
|
9519
|
+
}
|
|
9520
|
+
);
|
|
9445
9521
|
}
|
|
9446
9522
|
|
|
9447
9523
|
// src/sync/webhook-handler.ts
|
|
@@ -9782,6 +9858,25 @@ async function runFullSync(ctx, companyId) {
|
|
|
9782
9858
|
await upsertIssue(ctx.db, issue);
|
|
9783
9859
|
issuesSynced++;
|
|
9784
9860
|
}
|
|
9861
|
+
try {
|
|
9862
|
+
const { data: treeData } = await githubFetch(
|
|
9863
|
+
ctx,
|
|
9864
|
+
companyId,
|
|
9865
|
+
`/repos/${repo.fullName}/git/trees/${repo.defaultBranch}?recursive=1`
|
|
9866
|
+
);
|
|
9867
|
+
const tree = treeData.tree;
|
|
9868
|
+
const dirs = [];
|
|
9869
|
+
const files = [];
|
|
9870
|
+
for (const entry of tree) {
|
|
9871
|
+
const p = entry.path;
|
|
9872
|
+
if (entry.type === "tree" && p.split("/").length <= 3) dirs.push(p);
|
|
9873
|
+
else if (entry.type === "blob" && (p.split("/").length <= 2 || /\.(ts|js|py|go|rs|java|json|ya?ml|toml|md)$/.test(p))) files.push(p);
|
|
9874
|
+
}
|
|
9875
|
+
const graph = { dirs, files, defaultBranch: repo.defaultBranch, language: repo.language };
|
|
9876
|
+
await saveRepoGraph(ctx.db, repo.id, JSON.stringify(graph));
|
|
9877
|
+
} catch (graphErr) {
|
|
9878
|
+
ctx.logger.warn(`Graph generation failed for ${repo.fullName}: ${graphErr}`);
|
|
9879
|
+
}
|
|
9785
9880
|
reposSynced++;
|
|
9786
9881
|
} catch (err) {
|
|
9787
9882
|
errors.push(`${repo.fullName}: ${err instanceof Error ? err.message : String(err)}`);
|