@mastra/github-signals 0.0.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/LICENSE.md +30 -0
- package/dist/index.cjs +1135 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1122 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1122 @@
|
|
|
1
|
+
import { randomUUID, createHash } from 'crypto';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { SignalProvider } from '@mastra/core/signals';
|
|
7
|
+
import { createTool } from '@mastra/core/tools';
|
|
8
|
+
import z from 'zod';
|
|
9
|
+
|
|
10
|
+
// src/index.ts
|
|
11
|
+
var _execFileAsync;
|
|
12
|
+
async function execFileAsync(file, args, options) {
|
|
13
|
+
if (!_execFileAsync) {
|
|
14
|
+
const cp = await import('child_process');
|
|
15
|
+
_execFileAsync = promisify(cp.execFile);
|
|
16
|
+
}
|
|
17
|
+
return _execFileAsync(file, args, options);
|
|
18
|
+
}
|
|
19
|
+
var GITHUB_SUBSCRIBE_PR_TAG = "github-subscribe-pr";
|
|
20
|
+
var GITHUB_UNSUBSCRIBE_PR_TAG = "github-unsubscribe-pr";
|
|
21
|
+
var GITHUB_SYNC_STATUS_TAG = "github-sync-status";
|
|
22
|
+
var GITHUB_SIGNALS_METADATA_KEY = "githubSignals";
|
|
23
|
+
var createGithubTool = createTool;
|
|
24
|
+
function isPlainObject(value) {
|
|
25
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
function readString(value) {
|
|
28
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
29
|
+
}
|
|
30
|
+
function readNumber(value) {
|
|
31
|
+
if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
|
|
32
|
+
if (typeof value === "string" && /^\d+$/.test(value)) return Number(value);
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
function stableJson(value) {
|
|
36
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
37
|
+
if (isPlainObject(value)) {
|
|
38
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
39
|
+
}
|
|
40
|
+
return JSON.stringify(value);
|
|
41
|
+
}
|
|
42
|
+
function snapshotHash(value) {
|
|
43
|
+
return createHash("sha256").update(stableJson(value)).digest("hex");
|
|
44
|
+
}
|
|
45
|
+
function resolveHomePath(path) {
|
|
46
|
+
return path.startsWith("~/") ? join(homedir(), path.slice(2)) : path;
|
|
47
|
+
}
|
|
48
|
+
async function getGitcrawlDbPath() {
|
|
49
|
+
if (process.env.GITCRAWL_DB_PATH) return resolveHomePath(process.env.GITCRAWL_DB_PATH);
|
|
50
|
+
const configPath = process.env.GITCRAWL_CONFIG_PATH ?? join(homedir(), ".config", "gitcrawl", "config.toml");
|
|
51
|
+
try {
|
|
52
|
+
const config = await readFile(resolveHomePath(configPath), "utf8");
|
|
53
|
+
const match = /^\s*db_path\s*=\s*['\"]([^'\"]+)['\"]/m.exec(config);
|
|
54
|
+
if (match?.[1]) return resolveHomePath(match[1]);
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
return join(homedir(), ".config", "gitcrawl", "gitcrawl.db");
|
|
58
|
+
}
|
|
59
|
+
async function queryGitcrawlDb(sql) {
|
|
60
|
+
const dbPath = await getGitcrawlDbPath();
|
|
61
|
+
const { stdout } = await execFileAsync("sqlite3", ["-json", dbPath, sql], { maxBuffer: 10 * 1024 * 1024 });
|
|
62
|
+
return JSON.parse(stdout || "[]");
|
|
63
|
+
}
|
|
64
|
+
function sqlString(value) {
|
|
65
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
66
|
+
}
|
|
67
|
+
function getSignalMetadata(message) {
|
|
68
|
+
if (message.role !== "signal") return void 0;
|
|
69
|
+
const signal = message.content.metadata?.signal;
|
|
70
|
+
return isPlainObject(signal) ? signal : void 0;
|
|
71
|
+
}
|
|
72
|
+
function getGithubMetadata(threadMetadata) {
|
|
73
|
+
const mastra = isPlainObject(threadMetadata?.mastra) ? threadMetadata.mastra : {};
|
|
74
|
+
const githubSignals = isPlainObject(mastra[GITHUB_SIGNALS_METADATA_KEY]) ? mastra[GITHUB_SIGNALS_METADATA_KEY] : {};
|
|
75
|
+
const rawSubscriptions = Array.isArray(githubSignals.subscriptions) ? githubSignals.subscriptions : [];
|
|
76
|
+
const subscriptions = [];
|
|
77
|
+
for (const rawSubscription of rawSubscriptions) {
|
|
78
|
+
if (!isPlainObject(rawSubscription)) continue;
|
|
79
|
+
const owner = readString(rawSubscription.owner);
|
|
80
|
+
const repo = readString(rawSubscription.repo);
|
|
81
|
+
const number = readNumber(rawSubscription.number);
|
|
82
|
+
const subscribedAt = readString(rawSubscription.subscribedAt);
|
|
83
|
+
const updatedAt = readString(rawSubscription.updatedAt);
|
|
84
|
+
const lastSubscribeSignalId = readString(rawSubscription.lastSubscribeSignalId);
|
|
85
|
+
if (!owner || !repo || !number || !subscribedAt || !updatedAt || !lastSubscribeSignalId) continue;
|
|
86
|
+
subscriptions.push({
|
|
87
|
+
owner,
|
|
88
|
+
repo,
|
|
89
|
+
number,
|
|
90
|
+
subscribedAt,
|
|
91
|
+
updatedAt,
|
|
92
|
+
lastSubscribeSignalId,
|
|
93
|
+
...readString(rawSubscription.lastSyncAt) ? { lastSyncAt: readString(rawSubscription.lastSyncAt) } : {},
|
|
94
|
+
...rawSubscription.lastSyncStatus === "success" || rawSubscription.lastSyncStatus === "error" || rawSubscription.lastSyncStatus === "skipped" ? { lastSyncStatus: rawSubscription.lastSyncStatus } : {},
|
|
95
|
+
...readString(rawSubscription.lastSyncError) ? { lastSyncError: readString(rawSubscription.lastSyncError) } : {},
|
|
96
|
+
...readString(rawSubscription.lastObservedGithubUpdatedAt) ? { lastObservedGithubUpdatedAt: readString(rawSubscription.lastObservedGithubUpdatedAt) } : {},
|
|
97
|
+
...readString(rawSubscription.lastObservedContentHash) ? { lastObservedContentHash: readString(rawSubscription.lastObservedContentHash) } : {},
|
|
98
|
+
...readString(rawSubscription.lastObservedThreadContentHash) ? { lastObservedThreadContentHash: readString(rawSubscription.lastObservedThreadContentHash) } : {},
|
|
99
|
+
...readString(rawSubscription.lastObservedHeadSha) ? { lastObservedHeadSha: readString(rawSubscription.lastObservedHeadSha) } : {},
|
|
100
|
+
...readString(rawSubscription.lastObservedState) ? { lastObservedState: readString(rawSubscription.lastObservedState) } : {},
|
|
101
|
+
...readString(rawSubscription.lastObservedMergeableState) ? { lastObservedMergeableState: readString(rawSubscription.lastObservedMergeableState) } : {},
|
|
102
|
+
...readString(rawSubscription.lastObservedCiState) ? { lastObservedCiState: readString(rawSubscription.lastObservedCiState) } : {},
|
|
103
|
+
...readString(rawSubscription.lastObservedReviewStateHash) ? { lastObservedReviewStateHash: readString(rawSubscription.lastObservedReviewStateHash) } : {},
|
|
104
|
+
...readString(rawSubscription.lastNotificationAt) ? { lastNotificationAt: readString(rawSubscription.lastNotificationAt) } : {},
|
|
105
|
+
...readString(rawSubscription.lastNotificationKind) ? { lastNotificationKind: readString(rawSubscription.lastNotificationKind) } : {},
|
|
106
|
+
...rawSubscription.lastNotificationPriority === "medium" || rawSubscription.lastNotificationPriority === "high" ? { lastNotificationPriority: rawSubscription.lastNotificationPriority } : {},
|
|
107
|
+
...readString(rawSubscription.lastNotificationSummary) ? { lastNotificationSummary: readString(rawSubscription.lastNotificationSummary) } : {}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
subscriptions,
|
|
112
|
+
...githubSignals.subscriptionHintShown === true ? { subscriptionHintShown: true } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function setGithubMetadata(threadMetadata, githubSignals) {
|
|
116
|
+
const existing = threadMetadata ?? {};
|
|
117
|
+
const mastra = isPlainObject(existing.mastra) ? existing.mastra : {};
|
|
118
|
+
const existingGithubSignals = isPlainObject(mastra[GITHUB_SIGNALS_METADATA_KEY]) ? mastra[GITHUB_SIGNALS_METADATA_KEY] : {};
|
|
119
|
+
return {
|
|
120
|
+
...existing,
|
|
121
|
+
mastra: {
|
|
122
|
+
...mastra,
|
|
123
|
+
[GITHUB_SIGNALS_METADATA_KEY]: {
|
|
124
|
+
...existingGithubSignals,
|
|
125
|
+
...githubSignals
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function getFailingChecks(snapshot) {
|
|
131
|
+
return (snapshot.checks ?? []).filter((check) => check.conclusion === "failure" || check.conclusion === "timed_out");
|
|
132
|
+
}
|
|
133
|
+
function getPendingChecks(snapshot) {
|
|
134
|
+
return (snapshot.checks ?? []).filter((check) => check.status && check.status !== "completed");
|
|
135
|
+
}
|
|
136
|
+
function getPrLabel(subscription, snapshot) {
|
|
137
|
+
const pr = `${subscription.owner}/${subscription.repo}#${subscription.number}`;
|
|
138
|
+
return snapshot?.title ? `${pr}: ${snapshot.title}` : pr;
|
|
139
|
+
}
|
|
140
|
+
function getMergedNotificationSummary(label) {
|
|
141
|
+
return `${label} was merged. This thread has been automatically unsubscribed from this PR. Resubscribe if you still need updates.`;
|
|
142
|
+
}
|
|
143
|
+
function getCheckUpdatedTime(check) {
|
|
144
|
+
const value = check.updatedAt ? Date.parse(check.updatedAt) : Number.NaN;
|
|
145
|
+
return Number.isFinite(value) ? value : 0;
|
|
146
|
+
}
|
|
147
|
+
function getCheckKey(check) {
|
|
148
|
+
return `${check.name || "check"}:${check.detailsUrl || check.workflowName || ""}`;
|
|
149
|
+
}
|
|
150
|
+
function normalizeGithubChecksForSnapshot(input) {
|
|
151
|
+
const latestCheckUpdatedAt = input.checkRows.reduce(
|
|
152
|
+
(latest, check) => Math.max(latest, getCheckUpdatedTime(check)),
|
|
153
|
+
0
|
|
154
|
+
);
|
|
155
|
+
const rows = [
|
|
156
|
+
...input.checkRows,
|
|
157
|
+
...input.workflowRows.filter(
|
|
158
|
+
(workflow) => input.checkRows.length === 0 || getCheckUpdatedTime(workflow) >= latestCheckUpdatedAt
|
|
159
|
+
)
|
|
160
|
+
];
|
|
161
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
const key = getCheckKey(row);
|
|
164
|
+
const existing = byKey.get(key);
|
|
165
|
+
if (!existing) {
|
|
166
|
+
byKey.set(key, row);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const rowTime = getCheckUpdatedTime(row);
|
|
170
|
+
const existingTime = getCheckUpdatedTime(existing);
|
|
171
|
+
if (rowTime > existingTime || rowTime === existingTime && existing.source === "workflow" && row.source === "check") {
|
|
172
|
+
byKey.set(key, row);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return [...byKey.values()].map(({ source: _source, ...check }) => check).sort((a, b) => `${a.name}:${a.detailsUrl ?? ""}`.localeCompare(`${b.name}:${b.detailsUrl ?? ""}`));
|
|
176
|
+
}
|
|
177
|
+
function isBotOnlyActivity(snapshot) {
|
|
178
|
+
return snapshot.latestCommentIsBot === true && (!snapshot.ciState || snapshot.ciState === "unknown");
|
|
179
|
+
}
|
|
180
|
+
function stringifyEvidence(value) {
|
|
181
|
+
if (typeof value === "string") return value;
|
|
182
|
+
try {
|
|
183
|
+
return JSON.stringify(value);
|
|
184
|
+
} catch {
|
|
185
|
+
return "";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function detectPrWorkEvidence(input) {
|
|
189
|
+
const evidence = [
|
|
190
|
+
input.text ?? "",
|
|
191
|
+
...(input.toolCalls ?? []).map((toolCall) => `${toolCall.toolName} ${stringifyEvidence(toolCall.args)}`)
|
|
192
|
+
].join("\n");
|
|
193
|
+
if (!evidence.trim()) return void 0;
|
|
194
|
+
const url = /github\.com\/([^\s/#]+)\/([^\s/#]+)\/pull\/(\d+)/i.exec(evidence);
|
|
195
|
+
if (url?.[1] && url[2] && url[3]) return { owner: url[1], repo: url[2], number: Number(url[3]) };
|
|
196
|
+
const repoRef = /\b([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)\b/.exec(evidence);
|
|
197
|
+
if (repoRef?.[1] && repoRef[2] && repoRef[3])
|
|
198
|
+
return { owner: repoRef[1], repo: repoRef[2], number: Number(repoRef[3]) };
|
|
199
|
+
const ghCommand = /\bgh\s+(?:pr\s+(?:view|checks|status|comment|diff|checkout)|run\s+(?:rerun|view))\b/i.test(
|
|
200
|
+
evidence
|
|
201
|
+
);
|
|
202
|
+
if (!ghCommand) return void 0;
|
|
203
|
+
const numberMatch = /(?:^|\s)#?(\d{2,})(?:\s|$)/.exec(evidence);
|
|
204
|
+
return numberMatch?.[1] ? { number: Number(numberMatch[1]) } : void 0;
|
|
205
|
+
}
|
|
206
|
+
function classifyGithubActivityNotification(input) {
|
|
207
|
+
const pr = `${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}`;
|
|
208
|
+
const label = getPrLabel(input.subscription, input.snapshot);
|
|
209
|
+
if (input.snapshot.state && input.subscription.lastObservedState !== input.snapshot.state) {
|
|
210
|
+
if (input.snapshot.state === "merged")
|
|
211
|
+
return {
|
|
212
|
+
kind: "pull-request-merged",
|
|
213
|
+
priority: "high",
|
|
214
|
+
summary: getMergedNotificationSummary(label)
|
|
215
|
+
};
|
|
216
|
+
if (input.snapshot.state === "closed")
|
|
217
|
+
return { kind: "pull-request-closed", priority: "high", summary: `${label} was closed` };
|
|
218
|
+
if (input.subscription.lastObservedState && input.snapshot.state === "open")
|
|
219
|
+
return { kind: "pull-request-reopened", priority: "medium", summary: `${label} was reopened` };
|
|
220
|
+
}
|
|
221
|
+
const failingChecks = getFailingChecks(input.snapshot);
|
|
222
|
+
if (input.snapshot.ciState === "failure" && input.subscription.lastObservedCiState !== "failure") {
|
|
223
|
+
const names = failingChecks.slice(0, 3).map((check) => check.name).join(", ");
|
|
224
|
+
return {
|
|
225
|
+
kind: "pull-request-ci-failure",
|
|
226
|
+
priority: "high",
|
|
227
|
+
summary: `${pr} has failing CI${names ? `: ${names}` : ""}`
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (input.snapshot.mergeableState === "dirty" && input.subscription.lastObservedMergeableState !== "dirty") {
|
|
231
|
+
return {
|
|
232
|
+
kind: "pull-request-conflict",
|
|
233
|
+
priority: "high",
|
|
234
|
+
summary: `${pr} has merge conflicts${input.snapshot.title ? `: ${input.snapshot.title}` : ""}`
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (input.snapshot.mergeableState && input.subscription.lastObservedMergeableState === "dirty" && input.snapshot.mergeableState !== "dirty") {
|
|
238
|
+
return {
|
|
239
|
+
kind: "pull-request-conflict-resolved",
|
|
240
|
+
priority: "medium",
|
|
241
|
+
summary: `${pr} merge conflicts were resolved`
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (input.snapshot.mergeableState === "dirty") return void 0;
|
|
245
|
+
if (input.snapshot.ciState === "success" && input.subscription.lastObservedCiState && input.subscription.lastObservedCiState !== "success") {
|
|
246
|
+
return { kind: "pull-request-ci-recovered", priority: "medium", summary: `${pr} CI recovered` };
|
|
247
|
+
}
|
|
248
|
+
if (input.snapshot.reviewStateHash && input.subscription.lastObservedReviewStateHash && input.snapshot.reviewStateHash !== input.subscription.lastObservedReviewStateHash && (input.snapshot.unresolvedReviewThreads ?? 0) > 0) {
|
|
249
|
+
return {
|
|
250
|
+
kind: "pull-request-review-activity",
|
|
251
|
+
priority: "medium",
|
|
252
|
+
summary: `${pr} has ${input.snapshot.unresolvedReviewThreads} unresolved review thread${input.snapshot.unresolvedReviewThreads === 1 ? "" : "s"}`
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const pendingChecks = getPendingChecks(input.snapshot);
|
|
256
|
+
if (input.snapshot.ciState === "pending" && input.subscription.lastObservedCiState !== "pending" && pendingChecks.length > 0) {
|
|
257
|
+
const names = pendingChecks.slice(0, 3).map((check) => check.name).join(", ");
|
|
258
|
+
return {
|
|
259
|
+
kind: "pull-request-ci-pending",
|
|
260
|
+
priority: "medium",
|
|
261
|
+
summary: `${pr} has CI still running${names ? `: ${names}` : ""}`
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
if (input.snapshot.ciState === "pending" && input.subscription.lastObservedCiState === "pending") return void 0;
|
|
265
|
+
if (isBotOnlyActivity(input.snapshot)) return void 0;
|
|
266
|
+
return {
|
|
267
|
+
kind: "pull-request-activity",
|
|
268
|
+
priority: "medium",
|
|
269
|
+
summary: `${pr} has new activity${input.snapshot.title ? `: ${input.snapshot.title}` : ""}`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function classifyGithubBaselineNotification(input) {
|
|
273
|
+
const pr = `${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}`;
|
|
274
|
+
const failingChecks = getFailingChecks(input.snapshot);
|
|
275
|
+
const reviewCount = input.snapshot.unresolvedReviewThreads ?? 0;
|
|
276
|
+
const high = input.snapshot.ciState === "failure" || input.snapshot.mergeableState === "dirty";
|
|
277
|
+
const details = [
|
|
278
|
+
input.snapshot.state ? `state: ${input.snapshot.state}` : void 0,
|
|
279
|
+
input.snapshot.ciState && input.snapshot.ciState !== "unknown" ? `CI: ${input.snapshot.ciState}` : void 0,
|
|
280
|
+
input.snapshot.mergeableState ? `mergeability: ${input.snapshot.mergeableState}` : void 0,
|
|
281
|
+
reviewCount > 0 ? `${reviewCount} unresolved review thread${reviewCount === 1 ? "" : "s"}` : void 0,
|
|
282
|
+
failingChecks.length > 0 ? `failing: ${failingChecks.slice(0, 3).map((check) => check.name).join(", ")}` : void 0
|
|
283
|
+
].filter(Boolean);
|
|
284
|
+
return {
|
|
285
|
+
kind: "pull-request-baseline",
|
|
286
|
+
priority: high ? "high" : "medium",
|
|
287
|
+
summary: `${pr} subscribed${input.snapshot.title ? `: ${input.snapshot.title}` : ""}${details.length ? ` (${details.join("; ")})` : ""}`
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function applySnapshotCursor(subscription, snapshot) {
|
|
291
|
+
if (snapshot.githubUpdatedAt) subscription.lastObservedGithubUpdatedAt = snapshot.githubUpdatedAt;
|
|
292
|
+
if (snapshot.contentHash) subscription.lastObservedContentHash = snapshot.contentHash;
|
|
293
|
+
if (snapshot.threadContentHash) subscription.lastObservedThreadContentHash = snapshot.threadContentHash;
|
|
294
|
+
if (snapshot.headSha) subscription.lastObservedHeadSha = snapshot.headSha;
|
|
295
|
+
if (snapshot.state) subscription.lastObservedState = snapshot.state;
|
|
296
|
+
if (snapshot.mergeableState) subscription.lastObservedMergeableState = snapshot.mergeableState;
|
|
297
|
+
if (snapshot.ciState) subscription.lastObservedCiState = snapshot.ciState;
|
|
298
|
+
if (snapshot.reviewStateHash) subscription.lastObservedReviewStateHash = snapshot.reviewStateHash;
|
|
299
|
+
}
|
|
300
|
+
function parseGitHubRemoteUrl(remoteUrl) {
|
|
301
|
+
const trimmed = remoteUrl.trim().replace(/\.git$/, "");
|
|
302
|
+
const httpsMatch = /^https:\/\/github\.com\/([^/]+)\/([^/]+)$/.exec(trimmed);
|
|
303
|
+
if (httpsMatch?.[1] && httpsMatch[2]) return { owner: httpsMatch[1], repo: httpsMatch[2] };
|
|
304
|
+
const sshMatch = /^git@github\.com:([^/]+)\/([^/]+)$/.exec(trimmed);
|
|
305
|
+
if (sshMatch?.[1] && sshMatch[2]) return { owner: sshMatch[1], repo: sshMatch[2] };
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
var GitRemoteRepositoryResolver = class {
|
|
309
|
+
async resolveRepository(input) {
|
|
310
|
+
try {
|
|
311
|
+
const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
|
|
312
|
+
cwd: input.cwd,
|
|
313
|
+
signal: input.abortSignal
|
|
314
|
+
});
|
|
315
|
+
return parseGitHubRemoteUrl(stdout);
|
|
316
|
+
} catch {
|
|
317
|
+
return void 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var GitcrawlSyncClient = class {
|
|
322
|
+
#command;
|
|
323
|
+
constructor(options = {}) {
|
|
324
|
+
this.#command = options.command ?? "gitcrawl";
|
|
325
|
+
}
|
|
326
|
+
async syncPullRequest(input) {
|
|
327
|
+
try {
|
|
328
|
+
const args = [
|
|
329
|
+
"sync",
|
|
330
|
+
`${input.owner}/${input.repo}`,
|
|
331
|
+
"--numbers",
|
|
332
|
+
String(input.number),
|
|
333
|
+
...input.includeComments === false ? [] : ["--include-comments"],
|
|
334
|
+
"--with",
|
|
335
|
+
"pr-details",
|
|
336
|
+
"--json"
|
|
337
|
+
];
|
|
338
|
+
const { stdout, stderr } = await execFileAsync(this.#command, args, {
|
|
339
|
+
cwd: input.cwd,
|
|
340
|
+
signal: input.abortSignal,
|
|
341
|
+
maxBuffer: 10 * 1024 * 1024
|
|
342
|
+
});
|
|
343
|
+
return { ok: true, stdout, stderr };
|
|
344
|
+
} catch (error) {
|
|
345
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async getPullRequestSnapshot(input) {
|
|
349
|
+
try {
|
|
350
|
+
const { stdout } = await execFileAsync(
|
|
351
|
+
this.#command,
|
|
352
|
+
["threads", `${input.owner}/${input.repo}`, "--numbers", String(input.number), "--json"],
|
|
353
|
+
{
|
|
354
|
+
cwd: input.cwd,
|
|
355
|
+
signal: input.abortSignal,
|
|
356
|
+
maxBuffer: 10 * 1024 * 1024
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
const parsed = JSON.parse(stdout);
|
|
360
|
+
const thread = parsed.threads?.find((item) => readNumber(item.number) === input.number);
|
|
361
|
+
if (!thread) return void 0;
|
|
362
|
+
const owner = sqlString(input.owner);
|
|
363
|
+
const repo = sqlString(input.repo);
|
|
364
|
+
const number = input.number;
|
|
365
|
+
const [threadDetails] = await queryGitcrawlDb(`select t.state, t.closed_at_gh, t.merged_at_gh
|
|
366
|
+
from threads t
|
|
367
|
+
join repositories r on r.id=t.repo_id
|
|
368
|
+
where r.owner=${owner} and r.name=${repo} and t.number=${number}
|
|
369
|
+
limit 1`);
|
|
370
|
+
const [details] = await queryGitcrawlDb(`select d.head_sha, d.head_ref, d.mergeable_state,
|
|
371
|
+
json_extract(d.raw_json, '$.merged_at') as merged_at
|
|
372
|
+
from pull_request_details d
|
|
373
|
+
join threads t on t.id=d.thread_id
|
|
374
|
+
join repositories r on r.id=t.repo_id
|
|
375
|
+
where r.owner=${owner} and r.name=${repo} and t.number=${number}
|
|
376
|
+
limit 1`);
|
|
377
|
+
const headSha = readString(details?.head_sha);
|
|
378
|
+
const checkRows = await queryGitcrawlDb(`select c.name, c.status, c.conclusion, c.workflow_name, c.details_url,
|
|
379
|
+
coalesce(c.completed_at, c.started_at, c.fetched_at) as updated_at
|
|
380
|
+
from pull_request_checks c
|
|
381
|
+
join threads t on t.id=c.thread_id
|
|
382
|
+
join repositories r on r.id=t.repo_id
|
|
383
|
+
where r.owner=${owner} and r.name=${repo} and t.number=${number}${headSha ? ` and json_extract(c.raw_json, '$.head_sha')=${sqlString(headSha)}` : ""}`);
|
|
384
|
+
const workflowRows = details?.head_sha ? await queryGitcrawlDb(`select workflow_name, status, conclusion, html_url, updated_at_gh
|
|
385
|
+
from github_workflow_runs w
|
|
386
|
+
join repositories r on r.id=w.repo_id
|
|
387
|
+
where r.owner=${owner} and r.name=${repo} and w.head_sha=${sqlString(details.head_sha)}`) : [];
|
|
388
|
+
const [reviewState] = await queryGitcrawlDb(`select count(*) as unresolved_count,
|
|
389
|
+
max(coalesce(first_comment_updated_at, first_comment_created_at, fetched_at)) as latest_review_thread_at
|
|
390
|
+
from pull_request_review_threads rt
|
|
391
|
+
join threads t on t.id=rt.thread_id
|
|
392
|
+
join repositories r on r.id=t.repo_id
|
|
393
|
+
where r.owner=${owner} and r.name=${repo} and t.number=${number} and rt.is_resolved=0`);
|
|
394
|
+
const [latestComment] = await queryGitcrawlDb(`select c.author_login, c.author_type, c.is_bot
|
|
395
|
+
from comments c
|
|
396
|
+
join threads t on t.id=c.thread_id
|
|
397
|
+
join repositories r on r.id=t.repo_id
|
|
398
|
+
where r.owner=${owner} and r.name=${repo} and t.number=${number}
|
|
399
|
+
order by coalesce(c.updated_at_gh, c.created_at_gh) desc
|
|
400
|
+
limit 1`);
|
|
401
|
+
const checks = normalizeGithubChecksForSnapshot({
|
|
402
|
+
checkRows: checkRows.map((row) => ({
|
|
403
|
+
source: "check",
|
|
404
|
+
name: readString(row.name) ?? "check",
|
|
405
|
+
status: readString(row.status),
|
|
406
|
+
conclusion: readString(row.conclusion),
|
|
407
|
+
workflowName: readString(row.workflow_name),
|
|
408
|
+
detailsUrl: readString(row.details_url),
|
|
409
|
+
updatedAt: readString(row.updated_at)
|
|
410
|
+
})),
|
|
411
|
+
workflowRows: workflowRows.map((row) => ({
|
|
412
|
+
source: "workflow",
|
|
413
|
+
name: readString(row.workflow_name) ?? "workflow",
|
|
414
|
+
status: readString(row.status),
|
|
415
|
+
conclusion: readString(row.conclusion),
|
|
416
|
+
workflowName: readString(row.workflow_name),
|
|
417
|
+
detailsUrl: readString(row.html_url),
|
|
418
|
+
updatedAt: readString(row.updated_at_gh)
|
|
419
|
+
}))
|
|
420
|
+
});
|
|
421
|
+
const ciState = checks.some((check) => check.conclusion === "failure" || check.conclusion === "timed_out") ? "failure" : checks.some((check) => check.status && check.status !== "completed") ? "pending" : checks.length > 0 ? "success" : "unknown";
|
|
422
|
+
const threadContentHash = readString(thread.content_hash);
|
|
423
|
+
const unresolvedReviewThreads = Number(reviewState?.unresolved_count ?? 0);
|
|
424
|
+
const reviewStateHash = snapshotHash({
|
|
425
|
+
unresolvedReviewThreads,
|
|
426
|
+
latestReviewThreadAt: reviewState?.latest_review_thread_at
|
|
427
|
+
});
|
|
428
|
+
const contentHash = snapshotHash({
|
|
429
|
+
threadContentHash,
|
|
430
|
+
state: thread.state,
|
|
431
|
+
headSha: details?.head_sha,
|
|
432
|
+
mergeableState: details?.mergeable_state,
|
|
433
|
+
ciState,
|
|
434
|
+
reviewStateHash,
|
|
435
|
+
checks: checks.map((check) => ({
|
|
436
|
+
name: check.name,
|
|
437
|
+
status: check.status,
|
|
438
|
+
conclusion: check.conclusion,
|
|
439
|
+
detailsUrl: check.detailsUrl,
|
|
440
|
+
updatedAt: check.updatedAt
|
|
441
|
+
}))
|
|
442
|
+
});
|
|
443
|
+
return {
|
|
444
|
+
title: readString(thread.title),
|
|
445
|
+
state: readString(details?.merged_at) || readString(threadDetails?.merged_at_gh) ? "merged" : readString(threadDetails?.state) ?? readString(thread.state),
|
|
446
|
+
htmlUrl: readString(thread.html_url),
|
|
447
|
+
githubUpdatedAt: readString(thread.updated_at_gh),
|
|
448
|
+
closedAt: readString(threadDetails?.closed_at_gh),
|
|
449
|
+
mergedAt: readString(details?.merged_at) ?? readString(threadDetails?.merged_at_gh),
|
|
450
|
+
threadContentHash,
|
|
451
|
+
contentHash,
|
|
452
|
+
headSha: readString(details?.head_sha),
|
|
453
|
+
headRef: readString(details?.head_ref),
|
|
454
|
+
mergeableState: readString(details?.mergeable_state),
|
|
455
|
+
checks,
|
|
456
|
+
ciState,
|
|
457
|
+
unresolvedReviewThreads,
|
|
458
|
+
reviewStateHash,
|
|
459
|
+
latestReviewThreadAt: readString(reviewState?.latest_review_thread_at),
|
|
460
|
+
latestCommentAuthor: readString(latestComment?.author_login),
|
|
461
|
+
latestCommentAuthorType: readString(latestComment?.author_type),
|
|
462
|
+
latestCommentIsBot: latestComment?.is_bot === 1
|
|
463
|
+
};
|
|
464
|
+
} catch {
|
|
465
|
+
return void 0;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
var GithubSignals = class extends SignalProvider {
|
|
470
|
+
id = "github-signals";
|
|
471
|
+
name = "GitHub Signals";
|
|
472
|
+
#ghMastra;
|
|
473
|
+
static signals = {
|
|
474
|
+
subscribeToPR(input) {
|
|
475
|
+
const normalized = typeof input === "number" ? { number: input } : input;
|
|
476
|
+
return {
|
|
477
|
+
type: "reactive",
|
|
478
|
+
tagName: GITHUB_SUBSCRIBE_PR_TAG,
|
|
479
|
+
contents: `Subscribe to GitHub PR #${normalized.number}`,
|
|
480
|
+
attributes: {
|
|
481
|
+
...normalized.owner ? { owner: normalized.owner } : {},
|
|
482
|
+
...normalized.repo ? { repo: normalized.repo } : {},
|
|
483
|
+
number: normalized.number
|
|
484
|
+
},
|
|
485
|
+
metadata: {
|
|
486
|
+
github: {
|
|
487
|
+
action: "subscribeToPR",
|
|
488
|
+
...normalized
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
},
|
|
493
|
+
unsubscribeFromPR(input) {
|
|
494
|
+
const normalized = typeof input === "number" ? { number: input } : input;
|
|
495
|
+
return {
|
|
496
|
+
type: "reactive",
|
|
497
|
+
tagName: GITHUB_UNSUBSCRIBE_PR_TAG,
|
|
498
|
+
contents: `Unsubscribe from GitHub PR #${normalized.number}`,
|
|
499
|
+
attributes: {
|
|
500
|
+
...normalized.owner ? { owner: normalized.owner } : {},
|
|
501
|
+
...normalized.repo ? { repo: normalized.repo } : {},
|
|
502
|
+
number: normalized.number
|
|
503
|
+
},
|
|
504
|
+
metadata: {
|
|
505
|
+
github: {
|
|
506
|
+
action: "unsubscribeFromPR",
|
|
507
|
+
...normalized
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
#options;
|
|
514
|
+
#syncClient;
|
|
515
|
+
#repositoryResolver;
|
|
516
|
+
#polling = /* @__PURE__ */ new Map();
|
|
517
|
+
#agent;
|
|
518
|
+
#agentOptions = {};
|
|
519
|
+
#subscriptionsChangedHandler;
|
|
520
|
+
constructor(options = {}) {
|
|
521
|
+
super();
|
|
522
|
+
this.#options = options;
|
|
523
|
+
this.#syncClient = options.syncClient ?? new GitcrawlSyncClient({ command: options.gitcrawlCommand });
|
|
524
|
+
this.#repositoryResolver = options.repositoryResolver ?? new GitRemoteRepositoryResolver();
|
|
525
|
+
if (options.getNotificationStreamOptions) {
|
|
526
|
+
this.#agentOptions = { getNotificationStreamOptions: options.getNotificationStreamOptions };
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* @deprecated Use `Agent({ signals: [githubSignals] })` instead.
|
|
531
|
+
* Kept for backward compatibility.
|
|
532
|
+
*/
|
|
533
|
+
addAgent(agent, options = {}) {
|
|
534
|
+
this.#agent = agent;
|
|
535
|
+
this.#agentOptions = options;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Called by the Agent constructor when this provider is passed via `signals: [...]`.
|
|
539
|
+
* Sets the bidirectional link so the provider can send signals back to the agent.
|
|
540
|
+
*/
|
|
541
|
+
connect(agent) {
|
|
542
|
+
super.connect(agent);
|
|
543
|
+
this.#agent = agent;
|
|
544
|
+
}
|
|
545
|
+
getInputProcessors() {
|
|
546
|
+
return [this];
|
|
547
|
+
}
|
|
548
|
+
getOutputProcessors() {
|
|
549
|
+
return [this];
|
|
550
|
+
}
|
|
551
|
+
onSubscriptionsChanged(handler) {
|
|
552
|
+
this.#subscriptionsChangedHandler = handler;
|
|
553
|
+
}
|
|
554
|
+
__registerMastra(mastra) {
|
|
555
|
+
super.__registerMastra(mastra);
|
|
556
|
+
this.#ghMastra = mastra;
|
|
557
|
+
}
|
|
558
|
+
async syncThreadNow(input) {
|
|
559
|
+
return this.#pollThread(input, { includeComments: true });
|
|
560
|
+
}
|
|
561
|
+
async subscribeThreadToPR(input) {
|
|
562
|
+
const pr = typeof input.pr === "number" ? { number: input.pr } : input.pr;
|
|
563
|
+
return this.#subscribe({
|
|
564
|
+
id: `github-command-subscribe-${randomUUID()}`,
|
|
565
|
+
...pr,
|
|
566
|
+
threadId: input.threadId,
|
|
567
|
+
resourceId: input.resourceId
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
async unsubscribeThreadFromPR(input) {
|
|
571
|
+
const pr = typeof input.pr === "number" ? { number: input.pr } : input.pr;
|
|
572
|
+
return this.#unsubscribe({
|
|
573
|
+
id: `github-command-unsubscribe-${randomUUID()}`,
|
|
574
|
+
...pr,
|
|
575
|
+
threadId: input.threadId,
|
|
576
|
+
resourceId: input.resourceId
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
async startPollingForThread(input, options = {}) {
|
|
580
|
+
const subscriptions = await this.#getThreadSubscriptions(input);
|
|
581
|
+
if (subscriptions.length === 0) {
|
|
582
|
+
this.stopPollingForThread(input);
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
const key = this.#pollingKey(input);
|
|
586
|
+
for (const [pollingKey, state] of this.#polling.entries()) {
|
|
587
|
+
if (pollingKey === key) continue;
|
|
588
|
+
clearInterval(state.timer);
|
|
589
|
+
this.#polling.delete(pollingKey);
|
|
590
|
+
}
|
|
591
|
+
if (this.#polling.has(key)) return true;
|
|
592
|
+
let scheduledPollCount = options.pollImmediately ? 1 : 0;
|
|
593
|
+
const runPoll = (pollOptions = {}) => {
|
|
594
|
+
void this.#pollThread(input, pollOptions).catch((error) => {
|
|
595
|
+
console.warn("GitHub PR polling failed:", error);
|
|
596
|
+
});
|
|
597
|
+
};
|
|
598
|
+
const timer = setInterval(() => {
|
|
599
|
+
scheduledPollCount += 1;
|
|
600
|
+
runPoll({ includeComments: scheduledPollCount % 2 === 1 });
|
|
601
|
+
}, this.#options.pollIntervalMs ?? 3e5);
|
|
602
|
+
if (options.pollImmediately) runPoll({ includeComments: true });
|
|
603
|
+
timer.unref?.();
|
|
604
|
+
this.#polling.set(key, { ...input, timer, running: false });
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
stopPollingForThread(input) {
|
|
608
|
+
const key = this.#pollingKey(input);
|
|
609
|
+
const state = this.#polling.get(key);
|
|
610
|
+
if (!state) return;
|
|
611
|
+
clearInterval(state.timer);
|
|
612
|
+
this.#polling.delete(key);
|
|
613
|
+
}
|
|
614
|
+
isPollingThread(input) {
|
|
615
|
+
return this.#polling.has(this.#pollingKey(input));
|
|
616
|
+
}
|
|
617
|
+
getPollIntervalMs() {
|
|
618
|
+
return this.#options.pollIntervalMs ?? 3e5;
|
|
619
|
+
}
|
|
620
|
+
stopAllPolling() {
|
|
621
|
+
for (const state of this.#polling.values()) clearInterval(state.timer);
|
|
622
|
+
this.#polling.clear();
|
|
623
|
+
}
|
|
624
|
+
async pollThreadNow(input) {
|
|
625
|
+
return this.#pollThread(input, { includeComments: true });
|
|
626
|
+
}
|
|
627
|
+
async processInputStep(args) {
|
|
628
|
+
const tools = this.#createTools(args);
|
|
629
|
+
if (args.stepNumber !== 0) return { tools };
|
|
630
|
+
const signal = this.#findLatestGithubSignal(args.messages);
|
|
631
|
+
if (!signal) return { tools };
|
|
632
|
+
const threadContext = this.#getThreadContext(args);
|
|
633
|
+
if (signal.tagName === GITHUB_UNSUBSCRIBE_PR_TAG) {
|
|
634
|
+
const result2 = await this.#unsubscribe({ ...signal, ...threadContext, abortSignal: args.abortSignal });
|
|
635
|
+
await this.#sendStatus(args, result2, {
|
|
636
|
+
status: result2.removed ? "unsubscribed" : "not_subscribed",
|
|
637
|
+
action: "unsubscribeFromPR",
|
|
638
|
+
message: result2.removed ? `Unsubscribed from ${result2.owner}/${result2.repo}#${result2.number}.` : `No GitHub subscription found for ${result2.owner}/${result2.repo}#${result2.number}.`
|
|
639
|
+
});
|
|
640
|
+
return { tools };
|
|
641
|
+
}
|
|
642
|
+
const result = await this.#subscribe({ ...signal, ...threadContext, abortSignal: args.abortSignal });
|
|
643
|
+
if (result.alreadyProcessed) return { tools };
|
|
644
|
+
await this.#sendStatus(args, result, {
|
|
645
|
+
status: result.syncResult?.ok === false ? "sync_error" : "subscribed",
|
|
646
|
+
action: "subscribeToPR",
|
|
647
|
+
message: result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number}, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number}.`
|
|
648
|
+
});
|
|
649
|
+
return { tools };
|
|
650
|
+
}
|
|
651
|
+
async processOutputStep(args) {
|
|
652
|
+
const evidence = detectPrWorkEvidence({ text: args.text, toolCalls: args.toolCalls });
|
|
653
|
+
if (!evidence) return args.messages;
|
|
654
|
+
const threadContext = this.#getThreadContext(args);
|
|
655
|
+
if (!threadContext.threadId || !threadContext.resourceId) return args.messages;
|
|
656
|
+
const { threadStore, loadedThread } = await this.#loadThread(threadContext);
|
|
657
|
+
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
658
|
+
if (githubMetadata.subscriptionHintShown || githubMetadata.subscriptions.length > 0) return args.messages;
|
|
659
|
+
let repository;
|
|
660
|
+
try {
|
|
661
|
+
repository = await this.#resolveRepository({
|
|
662
|
+
id: "github-subscription-hint",
|
|
663
|
+
owner: evidence.owner,
|
|
664
|
+
repo: evidence.repo,
|
|
665
|
+
number: evidence.number
|
|
666
|
+
});
|
|
667
|
+
} catch {
|
|
668
|
+
return args.messages;
|
|
669
|
+
}
|
|
670
|
+
await threadStore.saveThread({
|
|
671
|
+
thread: {
|
|
672
|
+
...loadedThread,
|
|
673
|
+
id: threadContext.threadId,
|
|
674
|
+
resourceId: threadContext.resourceId,
|
|
675
|
+
createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
|
|
676
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
677
|
+
metadata: setGithubMetadata(loadedThread.metadata, { ...githubMetadata, subscriptionHintShown: true })
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
await args.sendSignal?.({
|
|
681
|
+
type: "reactive",
|
|
682
|
+
tagName: "system-reminder",
|
|
683
|
+
contents: `Looks like you're working with ${repository.owner}/${repository.repo}#${evidence.number}. Use /github subscribe ${evidence.number} or the github_subscribe_pr tool to follow updates.`,
|
|
684
|
+
attributes: { type: "github-subscription-hint" },
|
|
685
|
+
metadata: {
|
|
686
|
+
github: {
|
|
687
|
+
action: "subscriptionHint",
|
|
688
|
+
owner: repository.owner,
|
|
689
|
+
repo: repository.repo,
|
|
690
|
+
number: evidence.number
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
return args.messages;
|
|
695
|
+
}
|
|
696
|
+
async #resolveThreadStore() {
|
|
697
|
+
if (this.#options.threadStore) return this.#options.threadStore;
|
|
698
|
+
const storage = this.#ghMastra?.getStorage?.();
|
|
699
|
+
const memoryStore = storage?.getStore ? await storage.getStore("memory") : void 0;
|
|
700
|
+
return memoryStore;
|
|
701
|
+
}
|
|
702
|
+
#getThreadContext(args) {
|
|
703
|
+
const memoryContext = args.requestContext?.get("MastraMemory");
|
|
704
|
+
return { threadId: memoryContext?.thread?.id, resourceId: memoryContext?.resourceId };
|
|
705
|
+
}
|
|
706
|
+
#createTools(args) {
|
|
707
|
+
const threadContext = this.#getThreadContext(args);
|
|
708
|
+
return {
|
|
709
|
+
...args.tools,
|
|
710
|
+
github_subscribe_pr: createGithubTool({
|
|
711
|
+
id: "github_subscribe_pr",
|
|
712
|
+
description: "Subscribe this thread to a GitHub pull request. Syncs only the requested PR with gitcrawl and stores the subscription on the thread.",
|
|
713
|
+
inputSchema: z.object({
|
|
714
|
+
number: z.number().int().positive(),
|
|
715
|
+
owner: z.string().optional(),
|
|
716
|
+
repo: z.string().optional()
|
|
717
|
+
}),
|
|
718
|
+
execute: async (input) => {
|
|
719
|
+
const result = await this.#subscribe({
|
|
720
|
+
id: `github-tool-subscribe-${randomUUID()}`,
|
|
721
|
+
owner: input.owner,
|
|
722
|
+
repo: input.repo,
|
|
723
|
+
number: input.number,
|
|
724
|
+
threadId: threadContext.threadId,
|
|
725
|
+
resourceId: threadContext.resourceId
|
|
726
|
+
});
|
|
727
|
+
return {
|
|
728
|
+
subscribed: true,
|
|
729
|
+
owner: result.owner,
|
|
730
|
+
repo: result.repo,
|
|
731
|
+
number: result.number,
|
|
732
|
+
syncStatus: result.syncResult?.ok === false ? "error" : result.syncResult ? "success" : void 0,
|
|
733
|
+
message: result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number}, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number}.`
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
}),
|
|
737
|
+
github_unsubscribe_pr: createGithubTool({
|
|
738
|
+
id: "github_unsubscribe_pr",
|
|
739
|
+
description: "Unsubscribe this thread from a GitHub pull request.",
|
|
740
|
+
inputSchema: z.object({
|
|
741
|
+
number: z.number().int().positive(),
|
|
742
|
+
owner: z.string().optional(),
|
|
743
|
+
repo: z.string().optional()
|
|
744
|
+
}),
|
|
745
|
+
execute: async (input) => {
|
|
746
|
+
const result = await this.#unsubscribe({
|
|
747
|
+
id: `github-tool-unsubscribe-${randomUUID()}`,
|
|
748
|
+
owner: input.owner,
|
|
749
|
+
repo: input.repo,
|
|
750
|
+
number: input.number,
|
|
751
|
+
threadId: threadContext.threadId,
|
|
752
|
+
resourceId: threadContext.resourceId
|
|
753
|
+
});
|
|
754
|
+
return {
|
|
755
|
+
unsubscribed: result.removed ?? false,
|
|
756
|
+
owner: result.owner,
|
|
757
|
+
repo: result.repo,
|
|
758
|
+
number: result.number,
|
|
759
|
+
remainingSubscriptions: result.remainingSubscriptions,
|
|
760
|
+
message: result.removed ? `Unsubscribed from ${result.owner}/${result.repo}#${result.number}.` : `No GitHub subscription found for ${result.owner}/${result.repo}#${result.number}.`
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
})
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
async #resolveRepository(input) {
|
|
767
|
+
const resolvedRepository = input.owner && input.repo ? { owner: input.owner, repo: input.repo } : this.#options.owner && this.#options.repo ? { owner: this.#options.owner, repo: this.#options.repo } : await this.#repositoryResolver.resolveRepository({
|
|
768
|
+
cwd: this.#options.cwd,
|
|
769
|
+
abortSignal: input.abortSignal
|
|
770
|
+
});
|
|
771
|
+
if (!resolvedRepository?.owner || !resolvedRepository.repo) {
|
|
772
|
+
throw new Error(
|
|
773
|
+
"GitHub PR subscription requires owner and repo. Run inside a GitHub repo or pass owner and repo."
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
return resolvedRepository;
|
|
777
|
+
}
|
|
778
|
+
async #loadThread(input) {
|
|
779
|
+
const threadStore = await this.#resolveThreadStore();
|
|
780
|
+
if (!threadStore) throw new Error("GitHub PR subscription requires memory-backed thread storage.");
|
|
781
|
+
if (!input.threadId || !input.resourceId)
|
|
782
|
+
throw new Error("GitHub PR subscription requires threadId and resourceId.");
|
|
783
|
+
const loadedThread = await threadStore.getThreadById({ threadId: input.threadId, resourceId: input.resourceId }) ?? void 0;
|
|
784
|
+
if (!loadedThread) throw new Error(`Could not load thread ${input.threadId}.`);
|
|
785
|
+
return { threadStore, loadedThread };
|
|
786
|
+
}
|
|
787
|
+
#pollingKey(input) {
|
|
788
|
+
return `${input.resourceId}:${input.threadId}`;
|
|
789
|
+
}
|
|
790
|
+
#getNotificationAgent(_input) {
|
|
791
|
+
if (this.#agent) return this.#agent;
|
|
792
|
+
const agentId = _input?.agentId ?? this.#options.agentId;
|
|
793
|
+
return agentId ? this.#ghMastra?.getAgentById?.(agentId) : void 0;
|
|
794
|
+
}
|
|
795
|
+
async #getThreadSubscriptions(input) {
|
|
796
|
+
const { loadedThread } = await this.#loadThread(input);
|
|
797
|
+
return getGithubMetadata(loadedThread.metadata).subscriptions;
|
|
798
|
+
}
|
|
799
|
+
#notifySubscriptionsChanged(input) {
|
|
800
|
+
this.#subscriptionsChangedHandler?.(input);
|
|
801
|
+
}
|
|
802
|
+
async #pollThread(input, options = {}) {
|
|
803
|
+
const key = this.#pollingKey(input);
|
|
804
|
+
const state = this.#polling.get(key);
|
|
805
|
+
if (state?.running) {
|
|
806
|
+
return 0;
|
|
807
|
+
}
|
|
808
|
+
if (state) state.running = true;
|
|
809
|
+
try {
|
|
810
|
+
const { threadStore, loadedThread } = await this.#loadThread(input);
|
|
811
|
+
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
812
|
+
if (githubMetadata.subscriptions.length === 0) {
|
|
813
|
+
this.stopPollingForThread(input);
|
|
814
|
+
return 0;
|
|
815
|
+
}
|
|
816
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
817
|
+
const subscriptions = [];
|
|
818
|
+
for (const subscription of githubMetadata.subscriptions) {
|
|
819
|
+
const syncInput = {
|
|
820
|
+
owner: subscription.owner,
|
|
821
|
+
repo: subscription.repo,
|
|
822
|
+
number: subscription.number,
|
|
823
|
+
cwd: this.#options.cwd,
|
|
824
|
+
includeComments: options.includeComments
|
|
825
|
+
};
|
|
826
|
+
const syncResult = await this.#syncClient.syncPullRequest(syncInput);
|
|
827
|
+
const snapshot = syncResult.ok ? await this.#syncClient.getPullRequestSnapshot?.(syncInput) : void 0;
|
|
828
|
+
const nextSubscription = {
|
|
829
|
+
...subscription,
|
|
830
|
+
updatedAt: now,
|
|
831
|
+
lastSyncAt: now,
|
|
832
|
+
lastSyncStatus: syncResult.ok ? "success" : "error"
|
|
833
|
+
};
|
|
834
|
+
if (syncResult.error) nextSubscription.lastSyncError = syncResult.error;
|
|
835
|
+
else delete nextSubscription.lastSyncError;
|
|
836
|
+
const previousGithubUpdatedAt = subscription.lastObservedGithubUpdatedAt;
|
|
837
|
+
const previousContentHash = subscription.lastObservedContentHash;
|
|
838
|
+
const previousThreadContentHash = subscription.lastObservedThreadContentHash;
|
|
839
|
+
const previousHeadSha = subscription.lastObservedHeadSha;
|
|
840
|
+
if (snapshot) applySnapshotCursor(nextSubscription, snapshot);
|
|
841
|
+
const isFirstObservation = syncResult.ok && snapshot && !previousGithubUpdatedAt && !previousContentHash;
|
|
842
|
+
const legacyAggregateChanged = previousContentHash && snapshot?.contentHash && previousContentHash !== snapshot.contentHash && !previousThreadContentHash && !previousHeadSha;
|
|
843
|
+
const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash || previousHeadSha && snapshot.headSha && previousHeadSha !== snapshot.headSha || subscription.lastObservedState && snapshot.state && subscription.lastObservedState !== snapshot.state || subscription.lastObservedMergeableState && snapshot.mergeableState && subscription.lastObservedMergeableState !== snapshot.mergeableState || subscription.lastObservedCiState && snapshot.ciState && subscription.lastObservedCiState !== snapshot.ciState || subscription.lastObservedReviewStateHash && snapshot.reviewStateHash && subscription.lastObservedReviewStateHash !== snapshot.reviewStateHash);
|
|
844
|
+
let shouldKeepSubscription = true;
|
|
845
|
+
if (changed) {
|
|
846
|
+
const notification = await this.#sendActivityNotification({
|
|
847
|
+
polling: input,
|
|
848
|
+
subscription,
|
|
849
|
+
snapshot,
|
|
850
|
+
previousGithubUpdatedAt,
|
|
851
|
+
previousContentHash
|
|
852
|
+
});
|
|
853
|
+
if (notification) {
|
|
854
|
+
nextSubscription.lastNotificationAt = now;
|
|
855
|
+
nextSubscription.lastNotificationKind = notification.kind;
|
|
856
|
+
nextSubscription.lastNotificationPriority = notification.priority;
|
|
857
|
+
nextSubscription.lastNotificationSummary = notification.summary;
|
|
858
|
+
shouldKeepSubscription = notification.kind !== "pull-request-merged";
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (shouldKeepSubscription) subscriptions.push(nextSubscription);
|
|
862
|
+
}
|
|
863
|
+
await threadStore.saveThread({
|
|
864
|
+
thread: {
|
|
865
|
+
...loadedThread,
|
|
866
|
+
id: input.threadId,
|
|
867
|
+
resourceId: input.resourceId,
|
|
868
|
+
createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
|
|
869
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
870
|
+
metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
|
|
874
|
+
if (subscriptions.length === 0) this.stopPollingForThread(input);
|
|
875
|
+
return subscriptions.length;
|
|
876
|
+
} catch (error) {
|
|
877
|
+
throw error;
|
|
878
|
+
} finally {
|
|
879
|
+
const latestState = this.#polling.get(key);
|
|
880
|
+
if (latestState) latestState.running = false;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
async #sendGithubNotification(input) {
|
|
884
|
+
const failingChecks = getFailingChecks(input.snapshot);
|
|
885
|
+
const pendingChecks = getPendingChecks(input.snapshot);
|
|
886
|
+
const notificationInput = {
|
|
887
|
+
source: "github",
|
|
888
|
+
kind: input.notification.kind,
|
|
889
|
+
priority: input.notification.priority,
|
|
890
|
+
summary: input.notification.summary,
|
|
891
|
+
dedupeKey: `github:${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}:${input.dedupeSuffix}`,
|
|
892
|
+
coalesceKey: `github:${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}:${input.notification.kind}`,
|
|
893
|
+
attributes: {
|
|
894
|
+
owner: input.subscription.owner,
|
|
895
|
+
repo: input.subscription.repo,
|
|
896
|
+
number: input.subscription.number,
|
|
897
|
+
...input.snapshot.title ? { title: input.snapshot.title } : {},
|
|
898
|
+
...input.snapshot.state ? { state: input.snapshot.state } : {},
|
|
899
|
+
...input.snapshot.htmlUrl ? { url: input.snapshot.htmlUrl } : {},
|
|
900
|
+
...input.snapshot.githubUpdatedAt ? { githubUpdatedAt: input.snapshot.githubUpdatedAt } : {},
|
|
901
|
+
...input.previousGithubUpdatedAt ? { previousGithubUpdatedAt: input.previousGithubUpdatedAt } : {},
|
|
902
|
+
...input.snapshot.mergeableState ? { mergeableState: input.snapshot.mergeableState } : {},
|
|
903
|
+
...input.snapshot.ciState ? { ciState: input.snapshot.ciState } : {},
|
|
904
|
+
...input.snapshot.unresolvedReviewThreads !== void 0 ? { unresolvedReviewThreads: input.snapshot.unresolvedReviewThreads } : {},
|
|
905
|
+
...failingChecks.length > 0 ? { failingChecks: failingChecks.map((check) => check.name).join(", ") } : {},
|
|
906
|
+
...pendingChecks.length > 0 ? { pendingChecks: pendingChecks.map((check) => check.name).join(", ") } : {}
|
|
907
|
+
},
|
|
908
|
+
metadata: {
|
|
909
|
+
github: {
|
|
910
|
+
owner: input.subscription.owner,
|
|
911
|
+
repo: input.subscription.repo,
|
|
912
|
+
number: input.subscription.number,
|
|
913
|
+
title: input.snapshot.title,
|
|
914
|
+
state: input.snapshot.state,
|
|
915
|
+
htmlUrl: input.snapshot.htmlUrl,
|
|
916
|
+
githubUpdatedAt: input.snapshot.githubUpdatedAt,
|
|
917
|
+
previousGithubUpdatedAt: input.previousGithubUpdatedAt,
|
|
918
|
+
contentHash: input.snapshot.contentHash,
|
|
919
|
+
previousContentHash: input.previousContentHash,
|
|
920
|
+
threadContentHash: input.snapshot.threadContentHash,
|
|
921
|
+
headSha: input.snapshot.headSha,
|
|
922
|
+
headRef: input.snapshot.headRef,
|
|
923
|
+
mergeableState: input.snapshot.mergeableState,
|
|
924
|
+
ciState: input.snapshot.ciState,
|
|
925
|
+
closedAt: input.snapshot.closedAt,
|
|
926
|
+
mergedAt: input.snapshot.mergedAt,
|
|
927
|
+
unresolvedReviewThreads: input.snapshot.unresolvedReviewThreads,
|
|
928
|
+
reviewStateHash: input.snapshot.reviewStateHash,
|
|
929
|
+
latestReviewThreadAt: input.snapshot.latestReviewThreadAt,
|
|
930
|
+
latestCommentAuthor: input.snapshot.latestCommentAuthor,
|
|
931
|
+
latestCommentAuthorType: input.snapshot.latestCommentAuthorType,
|
|
932
|
+
latestCommentIsBot: input.snapshot.latestCommentIsBot,
|
|
933
|
+
failingChecks,
|
|
934
|
+
pendingChecks
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
const streamOptions = await this.#agentOptions.getNotificationStreamOptions?.(input.target);
|
|
939
|
+
await input.agent?.sendNotificationSignal?.(
|
|
940
|
+
notificationInput,
|
|
941
|
+
streamOptions ? { ...input.target, ifIdle: { streamOptions } } : input.target
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
async #sendBaselineNotification(input) {
|
|
945
|
+
const agent = this.#getNotificationAgent({});
|
|
946
|
+
if (!agent?.sendNotificationSignal) return;
|
|
947
|
+
await this.#sendGithubNotification({
|
|
948
|
+
agent,
|
|
949
|
+
subscription: input.subscription,
|
|
950
|
+
snapshot: input.snapshot,
|
|
951
|
+
notification: classifyGithubBaselineNotification({ subscription: input.subscription, snapshot: input.snapshot }),
|
|
952
|
+
target: { resourceId: input.resourceId, threadId: input.threadId },
|
|
953
|
+
dedupeSuffix: `baseline:${input.subscription.lastSubscribeSignalId}`
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
async #sendActivityNotification(input) {
|
|
957
|
+
const agent = this.#getNotificationAgent(input.polling);
|
|
958
|
+
if (!agent?.sendNotificationSignal) return void 0;
|
|
959
|
+
const notification = classifyGithubActivityNotification({
|
|
960
|
+
subscription: input.subscription,
|
|
961
|
+
snapshot: input.snapshot
|
|
962
|
+
});
|
|
963
|
+
if (!notification) return void 0;
|
|
964
|
+
await this.#sendGithubNotification({
|
|
965
|
+
agent,
|
|
966
|
+
subscription: input.subscription,
|
|
967
|
+
snapshot: input.snapshot,
|
|
968
|
+
notification,
|
|
969
|
+
target: { resourceId: input.polling.resourceId, threadId: input.polling.threadId },
|
|
970
|
+
dedupeSuffix: input.snapshot.contentHash ?? input.snapshot.githubUpdatedAt ?? String(Date.now()),
|
|
971
|
+
previousGithubUpdatedAt: input.previousGithubUpdatedAt,
|
|
972
|
+
previousContentHash: input.previousContentHash
|
|
973
|
+
});
|
|
974
|
+
return notification;
|
|
975
|
+
}
|
|
976
|
+
async #subscribe(input) {
|
|
977
|
+
const { owner, repo } = await this.#resolveRepository(input);
|
|
978
|
+
const { threadStore, loadedThread } = await this.#loadThread(input);
|
|
979
|
+
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
980
|
+
const existingIndex = githubMetadata.subscriptions.findIndex(
|
|
981
|
+
(subscription2) => subscription2.owner === owner && subscription2.repo === repo && subscription2.number === input.number
|
|
982
|
+
);
|
|
983
|
+
const existing = existingIndex >= 0 ? githubMetadata.subscriptions[existingIndex] : void 0;
|
|
984
|
+
if (existing?.lastSubscribeSignalId === input.id) {
|
|
985
|
+
return { owner, repo, number: input.number, subscription: existing, alreadyProcessed: true };
|
|
986
|
+
}
|
|
987
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
988
|
+
const subscription = {
|
|
989
|
+
owner,
|
|
990
|
+
repo,
|
|
991
|
+
number: input.number,
|
|
992
|
+
subscribedAt: existing?.subscribedAt ?? now,
|
|
993
|
+
updatedAt: now,
|
|
994
|
+
lastSubscribeSignalId: input.id,
|
|
995
|
+
...existing?.lastSyncAt ? { lastSyncAt: existing.lastSyncAt } : {},
|
|
996
|
+
...existing?.lastSyncStatus ? { lastSyncStatus: existing.lastSyncStatus } : {},
|
|
997
|
+
...existing?.lastSyncError ? { lastSyncError: existing.lastSyncError } : {},
|
|
998
|
+
...existing?.lastObservedGithubUpdatedAt ? { lastObservedGithubUpdatedAt: existing.lastObservedGithubUpdatedAt } : {},
|
|
999
|
+
...existing?.lastObservedContentHash ? { lastObservedContentHash: existing.lastObservedContentHash } : {},
|
|
1000
|
+
...existing?.lastObservedThreadContentHash ? { lastObservedThreadContentHash: existing.lastObservedThreadContentHash } : {},
|
|
1001
|
+
...existing?.lastObservedHeadSha ? { lastObservedHeadSha: existing.lastObservedHeadSha } : {},
|
|
1002
|
+
...existing?.lastObservedState ? { lastObservedState: existing.lastObservedState } : {},
|
|
1003
|
+
...existing?.lastObservedMergeableState ? { lastObservedMergeableState: existing.lastObservedMergeableState } : {},
|
|
1004
|
+
...existing?.lastObservedCiState ? { lastObservedCiState: existing.lastObservedCiState } : {},
|
|
1005
|
+
...existing?.lastObservedReviewStateHash ? { lastObservedReviewStateHash: existing.lastObservedReviewStateHash } : {}
|
|
1006
|
+
};
|
|
1007
|
+
let syncResult;
|
|
1008
|
+
let baselineSnapshot;
|
|
1009
|
+
if (this.#options.syncOnSubscribe !== false) {
|
|
1010
|
+
const syncInput = {
|
|
1011
|
+
owner,
|
|
1012
|
+
repo,
|
|
1013
|
+
number: input.number,
|
|
1014
|
+
cwd: this.#options.cwd,
|
|
1015
|
+
abortSignal: input.abortSignal
|
|
1016
|
+
};
|
|
1017
|
+
syncResult = await this.#syncClient.syncPullRequest(syncInput);
|
|
1018
|
+
subscription.lastSyncAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1019
|
+
subscription.lastSyncStatus = syncResult.ok ? "success" : "error";
|
|
1020
|
+
if (syncResult.error) subscription.lastSyncError = syncResult.error;
|
|
1021
|
+
else delete subscription.lastSyncError;
|
|
1022
|
+
const snapshot = syncResult.ok ? await this.#syncClient.getPullRequestSnapshot?.(syncInput) : void 0;
|
|
1023
|
+
baselineSnapshot = snapshot;
|
|
1024
|
+
if (snapshot) applySnapshotCursor(subscription, snapshot);
|
|
1025
|
+
} else {
|
|
1026
|
+
subscription.lastSyncStatus = "skipped";
|
|
1027
|
+
}
|
|
1028
|
+
const subscriptions = [subscription];
|
|
1029
|
+
await threadStore.saveThread({
|
|
1030
|
+
thread: {
|
|
1031
|
+
...loadedThread,
|
|
1032
|
+
id: input.threadId,
|
|
1033
|
+
resourceId: input.resourceId,
|
|
1034
|
+
createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
|
|
1035
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1036
|
+
metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
|
|
1040
|
+
if (baselineSnapshot) {
|
|
1041
|
+
await this.#sendBaselineNotification({
|
|
1042
|
+
threadId: input.threadId,
|
|
1043
|
+
resourceId: input.resourceId,
|
|
1044
|
+
subscription,
|
|
1045
|
+
snapshot: baselineSnapshot
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
await this.startPollingForThread({ threadId: input.threadId, resourceId: input.resourceId });
|
|
1049
|
+
return { owner, repo, number: input.number, subscription, syncResult };
|
|
1050
|
+
}
|
|
1051
|
+
async #unsubscribe(input) {
|
|
1052
|
+
const { owner, repo } = await this.#resolveRepository(input);
|
|
1053
|
+
const { threadStore, loadedThread } = await this.#loadThread(input);
|
|
1054
|
+
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
1055
|
+
const subscriptions = githubMetadata.subscriptions.filter(
|
|
1056
|
+
(subscription) => !(subscription.owner === owner && subscription.repo === repo && subscription.number === input.number)
|
|
1057
|
+
);
|
|
1058
|
+
const removed = subscriptions.length !== githubMetadata.subscriptions.length;
|
|
1059
|
+
if (removed) {
|
|
1060
|
+
await threadStore.saveThread({
|
|
1061
|
+
thread: {
|
|
1062
|
+
...loadedThread,
|
|
1063
|
+
id: input.threadId,
|
|
1064
|
+
resourceId: input.resourceId,
|
|
1065
|
+
createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
|
|
1066
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1067
|
+
metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
|
|
1071
|
+
if (subscriptions.length === 0)
|
|
1072
|
+
this.stopPollingForThread({ threadId: input.threadId, resourceId: input.resourceId });
|
|
1073
|
+
}
|
|
1074
|
+
return { owner, repo, number: input.number, removed, remainingSubscriptions: subscriptions.length };
|
|
1075
|
+
}
|
|
1076
|
+
#findLatestGithubSignal(messages) {
|
|
1077
|
+
const message = messages.at(-1);
|
|
1078
|
+
if (!message) return void 0;
|
|
1079
|
+
const signal = getSignalMetadata(message);
|
|
1080
|
+
if (!signal || signal.tagName !== GITHUB_SUBSCRIBE_PR_TAG && signal.tagName !== GITHUB_UNSUBSCRIBE_PR_TAG) {
|
|
1081
|
+
return void 0;
|
|
1082
|
+
}
|
|
1083
|
+
const attributes = isPlainObject(signal.attributes) ? signal.attributes : {};
|
|
1084
|
+
const metadata = isPlainObject(signal.metadata) ? signal.metadata : {};
|
|
1085
|
+
const github = isPlainObject(metadata.github) ? metadata.github : {};
|
|
1086
|
+
const number = readNumber(attributes.number) ?? readNumber(github.number);
|
|
1087
|
+
if (!number) return void 0;
|
|
1088
|
+
return {
|
|
1089
|
+
tagName: String(signal.tagName),
|
|
1090
|
+
id: readString(signal.id) ?? message.id,
|
|
1091
|
+
owner: readString(attributes.owner) ?? readString(github.owner),
|
|
1092
|
+
repo: readString(attributes.repo) ?? readString(github.repo),
|
|
1093
|
+
number
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
async #sendStatus(args, signal, status) {
|
|
1097
|
+
await args.sendSignal?.({
|
|
1098
|
+
type: "reactive",
|
|
1099
|
+
tagName: GITHUB_SYNC_STATUS_TAG,
|
|
1100
|
+
contents: status.message,
|
|
1101
|
+
attributes: {
|
|
1102
|
+
status: status.status,
|
|
1103
|
+
owner: signal.owner,
|
|
1104
|
+
repo: signal.repo,
|
|
1105
|
+
number: signal.number
|
|
1106
|
+
},
|
|
1107
|
+
metadata: {
|
|
1108
|
+
github: {
|
|
1109
|
+
action: status.action,
|
|
1110
|
+
status: status.status,
|
|
1111
|
+
owner: signal.owner,
|
|
1112
|
+
repo: signal.repo,
|
|
1113
|
+
number: signal.number
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
export { GITHUB_SIGNALS_METADATA_KEY, GITHUB_SUBSCRIBE_PR_TAG, GITHUB_SYNC_STATUS_TAG, GITHUB_UNSUBSCRIBE_PR_TAG, GitRemoteRepositoryResolver, GitcrawlSyncClient, GithubSignals, normalizeGithubChecksForSnapshot };
|
|
1121
|
+
//# sourceMappingURL=index.js.map
|
|
1122
|
+
//# sourceMappingURL=index.js.map
|