lastlight-core 0.25.7 → 0.25.9
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/config/default.yaml +11 -5
- package/dist/admin/routes.js +24 -27
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +6 -2
- package/dist/config/config.js +5 -0
- package/dist/config/config.js.map +1 -1
- package/dist/connectors/slack/connector.d.ts +14 -1
- package/dist/connectors/slack/connector.js +9 -1
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/connectors/slack/mrkdwn.d.ts +4 -0
- package/dist/connectors/slack/mrkdwn.js +2 -2
- package/dist/connectors/slack/mrkdwn.js.map +1 -1
- package/dist/cron/handlers.d.ts +16 -8
- package/dist/cron/handlers.js +49 -31
- package/dist/cron/handlers.js.map +1 -1
- package/dist/cron/jobs.js +3 -0
- package/dist/cron/jobs.js.map +1 -1
- package/dist/cron/repo-digest.d.ts +54 -7
- package/dist/cron/repo-digest.js +232 -19
- package/dist/cron/repo-digest.js.map +1 -1
- package/dist/cron/runner.d.ts +59 -0
- package/dist/cron/runner.js +224 -0
- package/dist/cron/runner.js.map +1 -0
- package/dist/cron/scheduler.js +19 -9
- package/dist/cron/scheduler.js.map +1 -1
- package/dist/engine/github/github.d.ts +79 -0
- package/dist/engine/github/github.js +111 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/index.js +25 -90
- package/dist/index.js.map +1 -1
- package/dist/logging/phase-log.d.ts +34 -0
- package/dist/logging/phase-log.js +45 -0
- package/dist/logging/phase-log.js.map +1 -0
- package/dist/notify/digest-blocks.d.ts +61 -0
- package/dist/notify/digest-blocks.js +150 -22
- package/dist/notify/digest-blocks.js.map +1 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.js +7 -1
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
- package/dist/sandbox/k8s/pod-lifecycle.d.ts +24 -9
- package/dist/sandbox/k8s/pod-lifecycle.js +48 -0
- package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -1
- package/dist/state/cron-run-store.d.ts +88 -0
- package/dist/state/cron-run-store.js +107 -0
- package/dist/state/cron-run-store.js.map +1 -0
- package/dist/state/db.d.ts +9 -0
- package/dist/state/db.js +9 -0
- package/dist/state/db.js.map +1 -1
- package/dist/state/migrate.js +25 -0
- package/dist/state/migrate.js.map +1 -1
- package/dist/telemetry/index.d.ts +8 -0
- package/dist/telemetry/index.js +11 -0
- package/dist/telemetry/index.js.map +1 -1
- package/dist/workflows/resume.js +5 -4
- package/dist/workflows/resume.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { fanOutContexts, dispatchCronWorkflow } from "./fanout.js";
|
|
2
|
+
import { CRON_GLOBALLY_ENABLED_KEY, CRON_NAME_KEY, resolveCronRepos } from "./repo-crons.js";
|
|
3
|
+
import { logger } from "../logging/logger.js";
|
|
4
|
+
import { recordCronFire, withSpan } from "../telemetry/index.js";
|
|
5
|
+
const log = logger("cron");
|
|
6
|
+
/** Context keys the fire path consumes and strips before dispatching. */
|
|
7
|
+
const CRON_SOURCE_KEY = "_cronSource";
|
|
8
|
+
const CRON_ACTOR_KEY = "_cronActor";
|
|
9
|
+
/**
|
|
10
|
+
* The counts, rendered into the completion line's MESSAGE rather than left only
|
|
11
|
+
* in its fields.
|
|
12
|
+
*
|
|
13
|
+
* A collapsed log view shows the message and nothing else — `kubectl logs`, and
|
|
14
|
+
* any Grafana Logs panel whose `line_format` renders `msg`. Without this, the
|
|
15
|
+
* one line the fire emits reads "Cron fire complete" and carries no outcome,
|
|
16
|
+
* which is most of what issue #341 was complaining about. The fields are still
|
|
17
|
+
* emitted, so the line stays queryable; this only makes it readable.
|
|
18
|
+
*
|
|
19
|
+
* Cost: the message is no longer a fixed string, so an exact `msg="Cron fire
|
|
20
|
+
* complete"` match becomes a `|~ "Cron fire complete"` prefix match. Loki
|
|
21
|
+
* indexes only stream labels, so there is no ingest-cardinality penalty.
|
|
22
|
+
*/
|
|
23
|
+
export function completionMessage(cronName, counts) {
|
|
24
|
+
const parts = [];
|
|
25
|
+
if (counts.reposScanned !== null) {
|
|
26
|
+
const narrowed = counts.reposEligible !== null && counts.reposEligible !== counts.reposScanned;
|
|
27
|
+
parts.push(narrowed ? `scanned ${counts.reposScanned} of ${counts.reposEligible}` : `scanned ${counts.reposScanned}`);
|
|
28
|
+
}
|
|
29
|
+
if (counts.discovered !== null)
|
|
30
|
+
parts.push(`found ${counts.discovered}`);
|
|
31
|
+
if (counts.dispatched !== null)
|
|
32
|
+
parts.push(`dispatched ${counts.dispatched}`);
|
|
33
|
+
if (counts.failures)
|
|
34
|
+
parts.push(`${counts.failures} failed`);
|
|
35
|
+
// The CRON NAME leads, because a collapsed view shows the message and nothing
|
|
36
|
+
// else — and with seven crons registered, "Cron fire complete: scanned 16"
|
|
37
|
+
// identifies nothing. The stable `Cron fire complete:` prefix stays first so
|
|
38
|
+
// `|~ "Cron fire complete"` still finds every fire of every cron.
|
|
39
|
+
return parts.length
|
|
40
|
+
? `Cron fire complete: ${cronName} — ${parts.join(", ")}`
|
|
41
|
+
: `Cron fire complete: ${cronName}`;
|
|
42
|
+
}
|
|
43
|
+
export function makeCronRunner(deps) {
|
|
44
|
+
const { db, github, discoverers, dispatch } = deps;
|
|
45
|
+
const resolveRepos = deps.resolveRepos ?? resolveCronRepos;
|
|
46
|
+
return async (workflowName, rawContext) => {
|
|
47
|
+
const cronName = typeof rawContext[CRON_NAME_KEY] === "string" ? rawContext[CRON_NAME_KEY] : "";
|
|
48
|
+
// Read the two markers here, then drop them: `dispatchCronWorkflow` strips
|
|
49
|
+
// `repos` + the two #180 control keys but knows nothing about these, so
|
|
50
|
+
// without this they ride into every dispatched run's context. A dispatched
|
|
51
|
+
// context must stay byte-for-byte what it was before this ledger existed
|
|
52
|
+
// (`fanout.ts` makes the same promise about its own keys).
|
|
53
|
+
const { [CRON_SOURCE_KEY]: rawSource, [CRON_ACTOR_KEY]: rawActor, ...context } = rawContext;
|
|
54
|
+
// No cron name means a caller that built its own context (an eval driver,
|
|
55
|
+
// a direct API call). `resolveCronRepos` already treats that as "use the
|
|
56
|
+
// list verbatim"; there is likewise no cron to key a ledger row on, so the
|
|
57
|
+
// fire dispatches normally and records nothing.
|
|
58
|
+
if (!cronName) {
|
|
59
|
+
log.debug("Cron fire without a cron name — dispatching unrecorded", { workflowName });
|
|
60
|
+
await fire(workflowName, context, { db, github, discoverers, dispatch, resolveRepos });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const source = rawSource === "manual" ? "manual" : "schedule";
|
|
64
|
+
const actor = typeof rawActor === "string" ? rawActor : null;
|
|
65
|
+
const id = db.cronRuns.start({ cronName, workflow: workflowName, source, actor });
|
|
66
|
+
let counts = {
|
|
67
|
+
reposEligible: null,
|
|
68
|
+
reposScanned: null,
|
|
69
|
+
discovered: null,
|
|
70
|
+
dispatched: null,
|
|
71
|
+
failures: null,
|
|
72
|
+
};
|
|
73
|
+
// Diagnostic only — which discoverer ran. Carried on the LOG line, never
|
|
74
|
+
// into `cron_runs`: it is not a column, and the ledger write below spreads
|
|
75
|
+
// `counts` straight into the store.
|
|
76
|
+
let discoverKey;
|
|
77
|
+
// On an object rather than two `let`s: TypeScript's control-flow analysis
|
|
78
|
+
// does not carry the catch block's assignment into `finally`, so a narrowed
|
|
79
|
+
// local reads as `"ok" | "partial"` there and the `"failed"` branch below
|
|
80
|
+
// is flagged unreachable.
|
|
81
|
+
const outcome = { status: "ok" };
|
|
82
|
+
try {
|
|
83
|
+
await withSpan("lastlight.cron.fire", { "cron.name": cronName, "cron.workflow": workflowName, "cron.source": source }, async (span) => {
|
|
84
|
+
const result = await fire(workflowName, context, {
|
|
85
|
+
db,
|
|
86
|
+
github,
|
|
87
|
+
discoverers,
|
|
88
|
+
dispatch,
|
|
89
|
+
resolveRepos,
|
|
90
|
+
});
|
|
91
|
+
({ discoverKey, ...counts } = result);
|
|
92
|
+
outcome.status = counts.failures && counts.failures > 0 ? "partial" : "ok";
|
|
93
|
+
span?.setAttributes({
|
|
94
|
+
"cron.repos_eligible": counts.reposEligible ?? 0,
|
|
95
|
+
"cron.repos_scanned": counts.reposScanned ?? 0,
|
|
96
|
+
"cron.discovered": counts.discovered ?? -1,
|
|
97
|
+
"cron.dispatched": counts.dispatched ?? 0,
|
|
98
|
+
"cron.failures": counts.failures ?? 0,
|
|
99
|
+
"cron.status": outcome.status,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
outcome.status = "failed";
|
|
105
|
+
outcome.error = err instanceof Error ? err.message : String(err);
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
// In a `finally` so a crash mid-fire leaves a terminal row rather than a
|
|
110
|
+
// stranded `running` one — silence is the thing this ledger exists to
|
|
111
|
+
// remove.
|
|
112
|
+
db.cronRuns.finish(id, { status: outcome.status, ...counts, error: outcome.error });
|
|
113
|
+
recordCronFire({ "cron.name": cronName, "cron.status": outcome.status });
|
|
114
|
+
const fields = {
|
|
115
|
+
cron: cronName,
|
|
116
|
+
workflow: workflowName,
|
|
117
|
+
source,
|
|
118
|
+
status: outcome.status,
|
|
119
|
+
...counts,
|
|
120
|
+
...(discoverKey ? { discoverKey } : {}),
|
|
121
|
+
};
|
|
122
|
+
const msg = completionMessage(cronName, counts);
|
|
123
|
+
if (outcome.status === "failed")
|
|
124
|
+
log.error(msg, { ...fields, err: outcome.error });
|
|
125
|
+
else if (outcome.status === "partial")
|
|
126
|
+
log.warn(msg, fields);
|
|
127
|
+
// Logged on SUCCESS too, not only on failure: a fully successful weekly
|
|
128
|
+
// fan-out over 19 repos used to emit one "Running" line and nothing else
|
|
129
|
+
// (issue #341). This is the COMMON path — nearly every fire is `ok` — so
|
|
130
|
+
// it is the one that most needs the cron name and counts in the message.
|
|
131
|
+
else
|
|
132
|
+
log.info(msg, fields);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The fire itself — discovery + fan-out, or a plain per-repo fan-out.
|
|
138
|
+
*
|
|
139
|
+
* Lifted verbatim from the closure that lived in `src/index.ts`, including the
|
|
140
|
+
* per-repo narrowing a discovery cron has to do for itself (it bypasses
|
|
141
|
+
* `dispatchCronWorkflow`, which does its own).
|
|
142
|
+
*/
|
|
143
|
+
async function fire(workflowName, context, deps) {
|
|
144
|
+
const { github, discoverers, dispatch, resolveRepos } = deps;
|
|
145
|
+
const discoverKey = typeof context.discover === "string" ? context.discover : undefined;
|
|
146
|
+
const discoverer = discoverKey ? discoverers[discoverKey] : undefined;
|
|
147
|
+
if (!discoverer) {
|
|
148
|
+
// `dispatchCronWorkflow` narrows the repo list itself and dispatches one
|
|
149
|
+
// run per surviving repo, so its `dispatched` IS the participating-repo
|
|
150
|
+
// count (`fanout.ts` returns `results.length`). `repos` absent → a single
|
|
151
|
+
// dispatch with no repo list at all, hence the null counts.
|
|
152
|
+
const eligible = Array.isArray(context.repos)
|
|
153
|
+
? context.repos.filter((r) => typeof r === "string" && r.length > 0).length
|
|
154
|
+
: null;
|
|
155
|
+
const { dispatched, failures } = await dispatchCronWorkflow(workflowName, context, dispatch);
|
|
156
|
+
return {
|
|
157
|
+
reposEligible: eligible,
|
|
158
|
+
reposScanned: eligible === null ? null : dispatched,
|
|
159
|
+
discovered: null,
|
|
160
|
+
dispatched,
|
|
161
|
+
failures,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const candidates = Array.isArray(context.repos)
|
|
165
|
+
? context.repos.filter((r) => typeof r === "string")
|
|
166
|
+
: [];
|
|
167
|
+
// Narrow to the repos that actually participate in THIS cron before
|
|
168
|
+
// discovering anything (issue #180). A discovery cron fans out per discovered
|
|
169
|
+
// PR rather than per repo, so it bypasses `dispatchCronWorkflow` and must
|
|
170
|
+
// resolve participation itself — otherwise a repo that opted out of e.g.
|
|
171
|
+
// `dependabot-merge` would still get runs.
|
|
172
|
+
// A missing name means a caller that built its own context, and the list is
|
|
173
|
+
// then used VERBATIM — resolving with no cron would apply participation rules
|
|
174
|
+
// that this fire never asked for.
|
|
175
|
+
const cronName = typeof context[CRON_NAME_KEY] === "string" ? context[CRON_NAME_KEY] : "";
|
|
176
|
+
const repos = cronName
|
|
177
|
+
? (await resolveRepos({
|
|
178
|
+
cron: cronName,
|
|
179
|
+
repos: candidates,
|
|
180
|
+
// Absent means "on" — only jobs.ts marks a cron globally off.
|
|
181
|
+
globallyEnabled: context[CRON_GLOBALLY_ENABLED_KEY] !== false,
|
|
182
|
+
})).repos
|
|
183
|
+
: candidates;
|
|
184
|
+
if (repos.length !== candidates.length) {
|
|
185
|
+
log.info("Repo(s) participate in this cron", {
|
|
186
|
+
cronName,
|
|
187
|
+
participating: repos.length,
|
|
188
|
+
candidates: candidates.length,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// Every repo opted out (or a globally-off cron nobody opted into) — no
|
|
192
|
+
// discovery calls, no dispatches, no failure. A cheap no-op tick. The
|
|
193
|
+
// discoverer's `log` callback carries per-repo diagnostics that can fire once
|
|
194
|
+
// per managed repo per tick, so it stays `.debug`.
|
|
195
|
+
const prs = github && repos.length ? await discoverer(repos, github, { log: (m) => log.debug(m) }) : [];
|
|
196
|
+
const contexts = prs.map((pr) => ({
|
|
197
|
+
_triggerType: "cron",
|
|
198
|
+
repo: pr.repo,
|
|
199
|
+
prNumber: pr.prNumber,
|
|
200
|
+
title: pr.title,
|
|
201
|
+
// Present only for the red sweep — `dispatchWorkflow` pre-clones this head
|
|
202
|
+
// ref for dependabot-ci-fix's checkout (a PR_FIX_SHAPED_WORKFLOWS).
|
|
203
|
+
...(pr.branch ? { branch: pr.branch } : {}),
|
|
204
|
+
// Also red-sweep only — why it was summoned (checks-failing | behind |
|
|
205
|
+
// dirty | blocked), threaded into the ci-fix prompt as `{{reason}}`.
|
|
206
|
+
...(pr.reason ? { reason: pr.reason } : {}),
|
|
207
|
+
// The review sweep announces itself, because `resolveReviewTrigger` treats
|
|
208
|
+
// it differently from a PR-attention event: `after-checks` will not fire on
|
|
209
|
+
// attention, and the sweep is the RELEASE MECHANISM for every PR whose fix
|
|
210
|
+
// chain ended without pushing — no new commit exists, so no further
|
|
211
|
+
// `check_suite` will ever fire for it (09 → S2).
|
|
212
|
+
...(discoverKey === "prs-awaiting-review" ? { _reviewRoute: "sweep" } : {}),
|
|
213
|
+
}));
|
|
214
|
+
const { dispatched, failures } = await fanOutContexts(workflowName, contexts, dispatch);
|
|
215
|
+
return {
|
|
216
|
+
reposEligible: candidates.length,
|
|
217
|
+
reposScanned: repos.length,
|
|
218
|
+
discovered: prs.length,
|
|
219
|
+
dispatched,
|
|
220
|
+
failures,
|
|
221
|
+
discoverKey,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/cron/runner.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AAExF,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjE,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAE3B,yEAAyE;AACzE,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,cAAc,GAAG,YAAY,CAAC;AA6BpC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,MAAkB;IACpE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QACjC,MAAM,QAAQ,G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,qEAAqE;QACrE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,2EAA2E;QAC3E,4EAA4E;QAC5E,2EAA2E;QAC3E,oEAAoE;QACpE,iDAAiD;QACjD,GAAG,CAAC,WAAW,KAAK,qBAAqB,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5E,CAAC,CAAC,CAAC;IAEJ,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,cAAc,CAAC,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACxF,OAAO;QACL,aAAa,EAAE,UAAU,CAAC,MAAM;QAChC,YAAY,EAAE,KAAK,CAAC,MAAM;QAC1B,UAAU,EAAE,GAAG,CAAC,MAAM;QACtB,UAAU;QACV,QAAQ;QACR,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/cron/scheduler.js
CHANGED
|
@@ -45,15 +45,25 @@ export class CronScheduler {
|
|
|
45
45
|
}
|
|
46
46
|
catch (err) {
|
|
47
47
|
log.error("Job failed", { job: job.name, err });
|
|
48
|
-
// Consecutive failures, counted off
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
// Consecutive failures at FIRE grain, counted off `cron_runs` and keyed
|
|
49
|
+
// on the cron itself (issue #327). Three things that buys:
|
|
50
|
+
//
|
|
51
|
+
// 1. The branch is REACHABLE. It read `executions.consecutiveFailures`,
|
|
52
|
+
// which matches `skill` exactly while every phase row is written as
|
|
53
|
+
// `"<workflow>:<phase>"` — so for a workflow cron the predicate could
|
|
54
|
+
// never match and this alert has never once fired. Measured on a live
|
|
55
|
+
// instance: 1,622 rows, zero with a bare skill.
|
|
56
|
+
// 2. `MAX_CONSECUTIVE_FAILURES` means the same thing for every cron. At
|
|
57
|
+
// phase grain one failed 5-phase run could read as 5 consecutive
|
|
58
|
+
// failures and a 1-phase run as 1.
|
|
59
|
+
// 3. Only THIS cron's fires count. Keyed on the workflow, a run
|
|
60
|
+
// dispatched by `/api/run` or a GitHub comment moved the cron's
|
|
61
|
+
// health, and vice versa.
|
|
62
|
+
//
|
|
63
|
+
// It also sidesteps the population problem #327 measured: quota
|
|
64
|
+
// deferrals and DAG-cascade skips are `success = 0` on purpose (251 in
|
|
65
|
+
// one day against zero real failures) and cannot appear here at all.
|
|
66
|
+
const failures = this.db.cronRuns.recentFailures(job.name);
|
|
57
67
|
if (failures >= MAX_CONSECUTIVE_FAILURES) {
|
|
58
68
|
log.error("ALERT: job has failed consecutively", { job: job.name, failures });
|
|
59
69
|
// TODO: send alert (Slack webhook, email, etc.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/cron/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AAoBlD;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAWnC;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,IAAI,GAAsB,IAAI,GAAG,EAAE,CAAC;IACpC,OAAO,GAAgB,IAAI,GAAG,EAAE,CAAC;IACjC,EAAE,CAAU;IACZ,MAAM,CAAiB;IAE/B,YAAY,EAAW,EAAE,MAAsB;QAC7C,IAAI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AU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,+EAA+E;IAC/E,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/D,IAAI;YACJ,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE;YACpC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;SAC3B,CAAC,CAAC,CAAC;IACN,CAAC;IAED,yBAAyB;IACzB,OAAO;QACL,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACpC,GAAG,CAAC,IAAI,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -145,6 +145,52 @@ export interface RepoActivityItem {
|
|
|
145
145
|
labels: string[];
|
|
146
146
|
htmlUrl: string;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* One issue or pull request with its text — the unit
|
|
150
|
+
* {@link GitHubClient.listRepoDigestDetail} lists.
|
|
151
|
+
*
|
|
152
|
+
* `body` is GitHub's `bodyText`: the markdown already flattened to prose, so an
|
|
153
|
+
* excerpt of it is readable rather than a slice of `<details>` scaffolding.
|
|
154
|
+
* It is returned in full; how much of it to keep is the reader's budget to set.
|
|
155
|
+
*/
|
|
156
|
+
export interface DigestItemDetail {
|
|
157
|
+
number: number;
|
|
158
|
+
title: string;
|
|
159
|
+
/** GitHub's own URL for the item — never reconstructed from the number. */
|
|
160
|
+
url: string;
|
|
161
|
+
authorLogin: string;
|
|
162
|
+
/** The author is a Bot (Dependabot, Renovate, us) rather than a person. */
|
|
163
|
+
authorIsBot: boolean;
|
|
164
|
+
labels: string[];
|
|
165
|
+
body: string;
|
|
166
|
+
}
|
|
167
|
+
/** An issue a merged pull request is LINKED to. Whether the merge closed it is the caller's call. */
|
|
168
|
+
export interface ClosingIssueRef {
|
|
169
|
+
number: number;
|
|
170
|
+
title: string;
|
|
171
|
+
url: string;
|
|
172
|
+
closedAt: string | null;
|
|
173
|
+
/** `owner/repo` — a closing reference may point at another repository. */
|
|
174
|
+
repo: string;
|
|
175
|
+
}
|
|
176
|
+
export interface MergedPrDetail extends DigestItemDetail {
|
|
177
|
+
mergedAt: string;
|
|
178
|
+
closes: ClosingIssueRef[];
|
|
179
|
+
}
|
|
180
|
+
export interface OpenedIssueDetail extends DigestItemDetail {
|
|
181
|
+
createdAt: string;
|
|
182
|
+
}
|
|
183
|
+
export interface ClosedIssueDetail extends DigestItemDetail {
|
|
184
|
+
closedAt: string;
|
|
185
|
+
/** `COMPLETED` | `NOT_PLANNED` | `DUPLICATE` | `REOPENED` | null. */
|
|
186
|
+
stateReason: string | null;
|
|
187
|
+
}
|
|
188
|
+
/** What {@link GitHubClient.listRepoDigestDetail} returns — the week's content, in one request. */
|
|
189
|
+
export interface RepoDigestDetail {
|
|
190
|
+
merged: MergedPrDetail[];
|
|
191
|
+
opened: OpenedIssueDetail[];
|
|
192
|
+
closed: ClosedIssueDetail[];
|
|
193
|
+
}
|
|
148
194
|
/** Options shared by the three settle-aware check queries. */
|
|
149
195
|
export interface ChecksQueryOptions {
|
|
150
196
|
/**
|
|
@@ -1486,6 +1532,39 @@ export declare class GitHubClient {
|
|
|
1486
1532
|
listRepoActivitySince(owner: string, repo: string, sinceIso: string, opts?: {
|
|
1487
1533
|
maxPages?: number;
|
|
1488
1534
|
}): Promise<RepoActivityItem[]>;
|
|
1535
|
+
/**
|
|
1536
|
+
* The week's actual CONTENT — the merged pull requests, the issues opened and
|
|
1537
|
+
* the issues closed, each with its text — in ONE GraphQL request.
|
|
1538
|
+
*
|
|
1539
|
+
* This is the companion to {@link listRepoActivitySince}, not a replacement:
|
|
1540
|
+
* that method answers "how many", this one answers "which, and about what".
|
|
1541
|
+
* They stay separate because the counts are load-bearing and long-tested,
|
|
1542
|
+
* while everything here is enrichment that must be free to fail (see
|
|
1543
|
+
* `cron/repo-digest.ts`).
|
|
1544
|
+
*
|
|
1545
|
+
* **Why `search` rather than the REST list.** `listRepoActivitySince` filters
|
|
1546
|
+
* on `updated_at` and pages by it, so a pull request merged on Monday and
|
|
1547
|
+
* untouched since ranks below any three-month-old issue somebody commented on
|
|
1548
|
+
* Friday. For a *count* that doesn't matter (the caller re-tests each item's
|
|
1549
|
+
* own timestamps); for a *list* it is the difference between reporting the
|
|
1550
|
+
* week and reporting a sample of it. `search` filters on the field that
|
|
1551
|
+
* actually defines each list — `merged:`, `created:`, `closed:` — so the first
|
|
1552
|
+
* N results are the right N.
|
|
1553
|
+
*
|
|
1554
|
+
* Three aliased searches ride in one query and cost one rate-limit point
|
|
1555
|
+
* between them. `bodyText` is GitHub's own markdown-flattened rendering, so
|
|
1556
|
+
* the caller excerpts prose instead of `<details>` blocks and HTML comments.
|
|
1557
|
+
*
|
|
1558
|
+
* **`closes` is a list of CANDIDATES, not of facts.** GitHub reports every
|
|
1559
|
+
* issue linked to the pull request, by keyword or through the Development
|
|
1560
|
+
* sidebar, whether or not the merge is what closed it — an issue closed by
|
|
1561
|
+
* hand days earlier still appears. Deciding which of them the merge actually
|
|
1562
|
+
* closed needs the timestamps, so they are returned unjudged and
|
|
1563
|
+
* `attributeClosures()` (`cron/repo-digest.ts`) makes the call.
|
|
1564
|
+
*/
|
|
1565
|
+
listRepoDigestDetail(owner: string, repo: string, sinceIso: string, opts?: {
|
|
1566
|
+
first?: number;
|
|
1567
|
+
}): Promise<RepoDigestDetail>;
|
|
1489
1568
|
/**
|
|
1490
1569
|
* The repo's default branch (e.g. `main`, `master`, `develop`). Used to
|
|
1491
1570
|
* scope build runs to the real base branch instead of assuming `main` — a
|
|
@@ -640,6 +640,105 @@ export class GitHubClient {
|
|
|
640
640
|
}
|
|
641
641
|
return items;
|
|
642
642
|
}
|
|
643
|
+
/**
|
|
644
|
+
* The week's actual CONTENT — the merged pull requests, the issues opened and
|
|
645
|
+
* the issues closed, each with its text — in ONE GraphQL request.
|
|
646
|
+
*
|
|
647
|
+
* This is the companion to {@link listRepoActivitySince}, not a replacement:
|
|
648
|
+
* that method answers "how many", this one answers "which, and about what".
|
|
649
|
+
* They stay separate because the counts are load-bearing and long-tested,
|
|
650
|
+
* while everything here is enrichment that must be free to fail (see
|
|
651
|
+
* `cron/repo-digest.ts`).
|
|
652
|
+
*
|
|
653
|
+
* **Why `search` rather than the REST list.** `listRepoActivitySince` filters
|
|
654
|
+
* on `updated_at` and pages by it, so a pull request merged on Monday and
|
|
655
|
+
* untouched since ranks below any three-month-old issue somebody commented on
|
|
656
|
+
* Friday. For a *count* that doesn't matter (the caller re-tests each item's
|
|
657
|
+
* own timestamps); for a *list* it is the difference between reporting the
|
|
658
|
+
* week and reporting a sample of it. `search` filters on the field that
|
|
659
|
+
* actually defines each list — `merged:`, `created:`, `closed:` — so the first
|
|
660
|
+
* N results are the right N.
|
|
661
|
+
*
|
|
662
|
+
* Three aliased searches ride in one query and cost one rate-limit point
|
|
663
|
+
* between them. `bodyText` is GitHub's own markdown-flattened rendering, so
|
|
664
|
+
* the caller excerpts prose instead of `<details>` blocks and HTML comments.
|
|
665
|
+
*
|
|
666
|
+
* **`closes` is a list of CANDIDATES, not of facts.** GitHub reports every
|
|
667
|
+
* issue linked to the pull request, by keyword or through the Development
|
|
668
|
+
* sidebar, whether or not the merge is what closed it — an issue closed by
|
|
669
|
+
* hand days earlier still appears. Deciding which of them the merge actually
|
|
670
|
+
* closed needs the timestamps, so they are returned unjudged and
|
|
671
|
+
* `attributeClosures()` (`cron/repo-digest.ts`) makes the call.
|
|
672
|
+
*/
|
|
673
|
+
async listRepoDigestDetail(owner, repo, sinceIso, opts = {}) {
|
|
674
|
+
const kit = await this.kit(owner);
|
|
675
|
+
// Search caps a page at 100; the caller wants far fewer than that.
|
|
676
|
+
const first = Math.min(Math.max(opts.first ?? 30, 1), 100);
|
|
677
|
+
const scope = `repo:${owner}/${repo}`;
|
|
678
|
+
const res = await kit.graphql(`query($merged: String!, $opened: String!, $closed: String!, $first: Int!) {
|
|
679
|
+
merged: search(query: $merged, type: ISSUE, first: $first) {
|
|
680
|
+
nodes {
|
|
681
|
+
... on PullRequest {
|
|
682
|
+
number title url mergedAt bodyText
|
|
683
|
+
author { login __typename }
|
|
684
|
+
labels(first: 10) { nodes { name } }
|
|
685
|
+
closingIssuesReferences(first: 10) {
|
|
686
|
+
nodes { number title url closedAt state repository { nameWithOwner } }
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
opened: search(query: $opened, type: ISSUE, first: $first) {
|
|
692
|
+
nodes {
|
|
693
|
+
... on Issue {
|
|
694
|
+
number title url createdAt bodyText
|
|
695
|
+
author { login __typename }
|
|
696
|
+
labels(first: 10) { nodes { name } }
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
closed: search(query: $closed, type: ISSUE, first: $first) {
|
|
701
|
+
nodes {
|
|
702
|
+
... on Issue {
|
|
703
|
+
number title url closedAt stateReason bodyText
|
|
704
|
+
author { login __typename }
|
|
705
|
+
labels(first: 10) { nodes { name } }
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}`, {
|
|
710
|
+
merged: `${scope} is:pr is:merged merged:>=${sinceIso}`,
|
|
711
|
+
opened: `${scope} is:issue created:>=${sinceIso}`,
|
|
712
|
+
closed: `${scope} is:issue closed:>=${sinceIso}`,
|
|
713
|
+
first,
|
|
714
|
+
});
|
|
715
|
+
const merged = (res.merged?.nodes ?? [])
|
|
716
|
+
.filter((n) => !!n?.mergedAt)
|
|
717
|
+
.map((n) => ({
|
|
718
|
+
...baseDetail(n),
|
|
719
|
+
mergedAt: n.mergedAt,
|
|
720
|
+
closes: (n.closingIssuesReferences?.nodes ?? [])
|
|
721
|
+
.filter((c) => !!c?.number)
|
|
722
|
+
.map((c) => ({
|
|
723
|
+
number: c.number,
|
|
724
|
+
title: c.title ?? "",
|
|
725
|
+
url: c.url ?? "",
|
|
726
|
+
closedAt: c.closedAt ?? null,
|
|
727
|
+
repo: c.repository?.nameWithOwner ?? "",
|
|
728
|
+
})),
|
|
729
|
+
}));
|
|
730
|
+
const opened = (res.opened?.nodes ?? [])
|
|
731
|
+
.filter((n) => !!n?.number)
|
|
732
|
+
.map((n) => ({ ...baseDetail(n), createdAt: n.createdAt ?? "" }));
|
|
733
|
+
const closed = (res.closed?.nodes ?? [])
|
|
734
|
+
.filter((n) => !!n?.number && !!n.closedAt)
|
|
735
|
+
.map((n) => ({
|
|
736
|
+
...baseDetail(n),
|
|
737
|
+
closedAt: n.closedAt,
|
|
738
|
+
stateReason: n.stateReason ?? null,
|
|
739
|
+
}));
|
|
740
|
+
return { merged, opened, closed };
|
|
741
|
+
}
|
|
643
742
|
/**
|
|
644
743
|
* The repo's default branch (e.g. `main`, `master`, `develop`). Used to
|
|
645
744
|
* scope build runs to the real base branch instead of assuming `main` — a
|
|
@@ -1342,6 +1441,18 @@ export class GitHubClient {
|
|
|
1342
1441
|
}
|
|
1343
1442
|
/** GitHub's own cap on `nodes(ids:)`, and the unit our poll budget is counted in. */
|
|
1344
1443
|
export const REACTION_BATCH_SIZE = 100;
|
|
1444
|
+
/** The fields shared by every digest item, mapped once so the three lists can't drift. */
|
|
1445
|
+
function baseDetail(node) {
|
|
1446
|
+
return {
|
|
1447
|
+
number: node.number ?? 0,
|
|
1448
|
+
title: node.title ?? "",
|
|
1449
|
+
url: node.url ?? "",
|
|
1450
|
+
authorLogin: node.author?.login ?? "",
|
|
1451
|
+
authorIsBot: node.author?.__typename === "Bot",
|
|
1452
|
+
labels: (node.labels?.nodes ?? []).map((l) => l?.name ?? "").filter(Boolean),
|
|
1453
|
+
body: node.bodyText ?? "",
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1345
1456
|
// ---------------------------------------------------------------------------
|
|
1346
1457
|
// Module-private helpers (exported for unit tests)
|
|
1347
1458
|
// ---------------------------------------------------------------------------
|