dsh-inbox-bridge 2.16.4 → 2.17.1
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/CHANGELOG.md +103 -92
- package/README.en.md +4 -1
- package/README.md +4 -1
- package/client.js +4 -2
- package/docs/configuration.md +2 -0
- package/docs/how-it-works.md +8 -0
- package/docs/index.json +5 -5
- package/index.js +2 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/scripts/github-inbox.mjs +166 -4
- package/scripts/github-inbox.test.mjs +120 -0
- package/scripts/inbox-bridge.mjs +364 -1
- package/scripts/inbox-bridge.test.mjs +169 -0
package/scripts/github-inbox.mjs
CHANGED
|
@@ -73,8 +73,10 @@ const FAILED_CHECK_STATES = new Set([
|
|
|
73
73
|
const RUN_FIELDS =
|
|
74
74
|
"databaseId,name,displayTitle,conclusion,headSha,headBranch,workflowName,createdAt,url";
|
|
75
75
|
const PR_FIELDS =
|
|
76
|
-
"number,title,headRefName,url,statusCheckRollup,reviewDecision,updatedAt,author,reviewRequests,assignees,isDraft";
|
|
77
|
-
|
|
76
|
+
"number,title,headRefName,url,statusCheckRollup,reviewDecision,updatedAt,author,reviewRequests,assignees,isDraft,mergeStateStatus";
|
|
77
|
+
// Order inside one notice: something to fix first, then what is waiting on a
|
|
78
|
+
// person, then conversation.
|
|
79
|
+
const KIND_ORDER = { recovered: 0, security: 1, ci: 2, pr: 3, comment: 4, issue: 5 };
|
|
78
80
|
/** How a GitHub notification reason maps onto the role vocabulary. */
|
|
79
81
|
const NOTIFICATION_ROLES = {
|
|
80
82
|
review_requested: "reviewer",
|
|
@@ -106,6 +108,10 @@ Usage:
|
|
|
106
108
|
the unread badge, not the inbox history. Only threads from
|
|
107
109
|
the repositories this instance reads are touched.
|
|
108
110
|
|
|
111
|
+
Security: open Dependabot and code-scanning alerts are read as well. A repository
|
|
112
|
+
without either feature answers 403/404, which is reported (in --json)
|
|
113
|
+
instead of skipped, so one missing feature never hides the rest.
|
|
114
|
+
|
|
109
115
|
State: .work/github-inbox/state.json (one slice per repository)
|
|
110
116
|
History: .work/github-inbox/pending.md`;
|
|
111
117
|
|
|
@@ -250,11 +256,29 @@ export function tagEvents(repo, events = []) {
|
|
|
250
256
|
|
|
251
257
|
const IN_PROGRESS_CHECK_STATES = new Set(["QUEUED", "IN_PROGRESS", "PENDING", "WAITING", "REQUESTED"]);
|
|
252
258
|
|
|
259
|
+
// A pull request that cannot be merged is work, even when nothing failed: the
|
|
260
|
+
// branch has to be rebased or the conflict resolved. These two states are the
|
|
261
|
+
// ones a person has to act on; BLOCKED/UNSTABLE are already covered by the
|
|
262
|
+
// review and check digests.
|
|
263
|
+
const BLOCKED_MERGE_STATES = new Set(["DIRTY", "BEHIND"]);
|
|
264
|
+
|
|
265
|
+
export function mergeBlocker(pr) {
|
|
266
|
+
const state = String(pr?.mergeStateStatus ?? "").toUpperCase();
|
|
267
|
+
if (BLOCKED_MERGE_STATES.has(state)) return state;
|
|
268
|
+
// `gh pr list --json mergeable` answers CONFLICTING when the merge is dirty;
|
|
269
|
+
// accept it so the older field shape keeps working.
|
|
270
|
+
return String(pr?.mergeable ?? "").toUpperCase() === "CONFLICTING" ? "DIRTY" : null;
|
|
271
|
+
}
|
|
272
|
+
|
|
253
273
|
export function prStatusDigest(pr) {
|
|
254
274
|
// 摘要只反映“需要你处理的状态”:失败的检查与评审决定。
|
|
255
275
|
// 进行中或成功完成的检查不进 key,否则同一 PR 在检查跑完前会被反复当成新事件。
|
|
256
276
|
const failing = failingCheckNames(pr).sort();
|
|
257
|
-
|
|
277
|
+
const blocker = mergeBlocker(pr);
|
|
278
|
+
// 只在真的冲突/落后时才把合并状态写进 key:合并干净的 PR 保持原来的 key,
|
|
279
|
+
// 已投递的事实不会因为一次格式变化被重新提醒一次。
|
|
280
|
+
const merge = blocker ? `|merge:${blocker}` : "";
|
|
281
|
+
return `failed[${failing.join(",")}]|review:${String(pr?.reviewDecision ?? "").toUpperCase() || "NONE"}${merge}`;
|
|
258
282
|
}
|
|
259
283
|
|
|
260
284
|
export function failingCheckNames(pr) {
|
|
@@ -383,6 +407,7 @@ export function extractPrEvents(prs = [], { me = null } = {}) {
|
|
|
383
407
|
if (role === null) continue;
|
|
384
408
|
const review = String(pr?.reviewDecision ?? "").toUpperCase();
|
|
385
409
|
const failing = failingCheckNames(pr);
|
|
410
|
+
const blocker = mergeBlocker(pr);
|
|
386
411
|
const reasons = [];
|
|
387
412
|
if (role === "reviewer") {
|
|
388
413
|
// Already reviewed: the ball is back with the author.
|
|
@@ -391,6 +416,10 @@ export function extractPrEvents(prs = [], { me = null } = {}) {
|
|
|
391
416
|
} else {
|
|
392
417
|
if (failing.length) reasons.push(`checks failed: ${failing.slice(0, 4).join(", ")}`);
|
|
393
418
|
if (review === "CHANGES_REQUESTED") reasons.push("changes requested");
|
|
419
|
+
// Merging is the author's job, not the reviewer's: a reviewer reading a
|
|
420
|
+
// conflicted PR has nothing to do about the conflict.
|
|
421
|
+
if (blocker === "DIRTY") reasons.push("merge conflict with the base branch");
|
|
422
|
+
if (blocker === "BEHIND") reasons.push("behind the base branch");
|
|
394
423
|
}
|
|
395
424
|
if (reasons.length === 0) continue;
|
|
396
425
|
// A reviewer's key must not move when checks change: it is the same review
|
|
@@ -526,8 +555,83 @@ export function extractIssueEvents(issues = [], state = {}, { me = null } = {})
|
|
|
526
555
|
return events;
|
|
527
556
|
}
|
|
528
557
|
|
|
558
|
+
const SEVERITY_ORDER = ["critical", "high", "medium", "low"];
|
|
559
|
+
|
|
560
|
+
function severityRank(word) {
|
|
561
|
+
const index = SEVERITY_ORDER.indexOf(word);
|
|
562
|
+
return index < 0 ? SEVERITY_ORDER.length : index;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Open advisories for the watched repository, one line per source.
|
|
567
|
+
*
|
|
568
|
+
* A real repository can carry dozens of open alerts at once (a single
|
|
569
|
+
* dependency can account for twenty), so listing them one by one buries the
|
|
570
|
+
* queue and turns one fix into twenty notices. What a maintainer needs to know
|
|
571
|
+
* is that the repository has open advisories, how bad the worst of them are,
|
|
572
|
+
* and what they are about — so each source collapses into one entry with a
|
|
573
|
+
* stable key, and it closes by itself once no open alert of that source is
|
|
574
|
+
* left.
|
|
575
|
+
*/
|
|
576
|
+
export function extractSecurityEvents(alerts = []) {
|
|
577
|
+
const groups = new Map();
|
|
578
|
+
for (const entry of Array.isArray(alerts) ? alerts : []) {
|
|
579
|
+
const alert = entry?.alert;
|
|
580
|
+
if (!alert) continue;
|
|
581
|
+
const source = entry?.source === "code-scanning" ? "code-scanning" : "dependabot";
|
|
582
|
+
const group = groups.get(source) ?? {
|
|
583
|
+
source,
|
|
584
|
+
count: 0,
|
|
585
|
+
severity: new Map(),
|
|
586
|
+
names: [],
|
|
587
|
+
at: null,
|
|
588
|
+
url: `https://github.com/${activeRepo}/security/${source === "code-scanning" ? "code-scanning" : "dependabot"}`,
|
|
589
|
+
};
|
|
590
|
+
group.count += 1;
|
|
591
|
+
const severity =
|
|
592
|
+
source === "dependabot"
|
|
593
|
+
? singleLine(alert?.security_advisory?.severity ?? "unknown").toLowerCase()
|
|
594
|
+
: singleLine(
|
|
595
|
+
alert?.rule?.security_severity_level ?? alert?.rule?.severity ?? "",
|
|
596
|
+
).toLowerCase();
|
|
597
|
+
if (severity) group.severity.set(severity, (group.severity.get(severity) ?? 0) + 1);
|
|
598
|
+
const name =
|
|
599
|
+
source === "dependabot"
|
|
600
|
+
? singleLine(alert?.dependency?.package?.name ?? "")
|
|
601
|
+
: singleLine(alert?.most_recent_instance?.location?.path ?? "");
|
|
602
|
+
if (name && !group.names.includes(name)) group.names.push(name);
|
|
603
|
+
const at = alert?.updated_at ?? alert?.created_at ?? null;
|
|
604
|
+
if (at && (!group.at || String(at).localeCompare(String(group.at)) > 0)) group.at = at;
|
|
605
|
+
groups.set(source, group);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const events = [];
|
|
609
|
+
for (const group of groups.values()) {
|
|
610
|
+
const severities = [...group.severity.entries()]
|
|
611
|
+
.sort((left, right) => severityRank(left[0]) - severityRank(right[0]))
|
|
612
|
+
.map(([word, count]) => `${count} ${word}`);
|
|
613
|
+
const shown = group.names.slice(0, 3).join(", ");
|
|
614
|
+
const names = group.names.length > 3 ? `${shown} …` : shown;
|
|
615
|
+
const count = `${group.count} open ${group.count === 1 ? "advisory" : "advisories"}`;
|
|
616
|
+
const spread = severities.length > 0 ? ` (${severities.join(", ")})` : "";
|
|
617
|
+
const what = names ? `: ${names}` : "";
|
|
618
|
+
events.push({
|
|
619
|
+
key: group.source,
|
|
620
|
+
kind: "security",
|
|
621
|
+
role: "any",
|
|
622
|
+
repo: activeRepo,
|
|
623
|
+
label: group.source === "code-scanning" ? "Code scanning" : "Dependabot",
|
|
624
|
+
ref: "",
|
|
625
|
+
title: `${count}${spread}${what}`,
|
|
626
|
+
url: group.url,
|
|
627
|
+
at: group.at,
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
return events;
|
|
631
|
+
}
|
|
632
|
+
|
|
529
633
|
export function extractEvents(
|
|
530
|
-
{ runs = [], prs = [], notifications = [], comments = [], issues = [] } = {},
|
|
634
|
+
{ runs = [], prs = [], notifications = [], comments = [], issues = [], security = [] } = {},
|
|
531
635
|
state = {},
|
|
532
636
|
{ me = null } = {},
|
|
533
637
|
) {
|
|
@@ -537,6 +641,7 @@ export function extractEvents(
|
|
|
537
641
|
...extractNotificationEvents(notifications),
|
|
538
642
|
...extractCommentEvents(comments, { me }),
|
|
539
643
|
...extractIssueEvents(issues, state, { me }),
|
|
644
|
+
...extractSecurityEvents(security),
|
|
540
645
|
];
|
|
541
646
|
// Every event names the repository it came from and how this identity is
|
|
542
647
|
// involved, so delivery never has to guess either from the session's cwd.
|
|
@@ -621,6 +726,7 @@ export function pollOnce({
|
|
|
621
726
|
fetchPrs,
|
|
622
727
|
fetchFeed = () => ({ ok: true, source: "none", notifications: [], comments: [], issues: [] }),
|
|
623
728
|
fetchIssues,
|
|
729
|
+
fetchSecurity,
|
|
624
730
|
markRead,
|
|
625
731
|
} = {}) {
|
|
626
732
|
const runsResult =
|
|
@@ -649,6 +755,14 @@ export function pollOnce({
|
|
|
649
755
|
if (number != null) issueNumbers.add(number);
|
|
650
756
|
issues.push(issue);
|
|
651
757
|
}
|
|
758
|
+
// Security advisories are optional: a repository without Dependabot, or a
|
|
759
|
+
// token without the security scopes, answers 403/404. That must not skip the
|
|
760
|
+
// poll — it only means this instance cannot see those facts, and the reason
|
|
761
|
+
// is reported instead of swallowed.
|
|
762
|
+
const securityResult =
|
|
763
|
+
typeof fetchSecurity === "function" ? fetchSecurity() : { alerts: [], notes: [] };
|
|
764
|
+
const security = Array.isArray(securityResult?.alerts) ? securityResult.alerts : [];
|
|
765
|
+
const securityNotes = Array.isArray(securityResult?.notes) ? securityResult.notes : [];
|
|
652
766
|
const payload = {
|
|
653
767
|
// The default branch always counts; a feature branch counts only while this
|
|
654
768
|
// identity has an open PR from it.
|
|
@@ -661,6 +775,7 @@ export function pollOnce({
|
|
|
661
775
|
notifications: Array.isArray(feed.notifications) ? feed.notifications : [],
|
|
662
776
|
comments: Array.isArray(feed.comments) ? feed.comments : [],
|
|
663
777
|
issues,
|
|
778
|
+
security,
|
|
664
779
|
};
|
|
665
780
|
const events = extractEvents(payload, state, { me });
|
|
666
781
|
const fresh = sortEvents(repeat ? events : diffEvents(events, state));
|
|
@@ -681,6 +796,7 @@ export function pollOnce({
|
|
|
681
796
|
source: feed.ok === true ? (feed.source ?? null) : null,
|
|
682
797
|
feedSkipped:
|
|
683
798
|
feedResult && feedResult.ok === false ? (feedResult.reason ?? "feed failed") : null,
|
|
799
|
+
securityNotes,
|
|
684
800
|
};
|
|
685
801
|
}
|
|
686
802
|
|
|
@@ -711,6 +827,8 @@ export function formatEvent(event) {
|
|
|
711
827
|
return compact([`[Comment${role}] ${event.ref ?? ""}:`, title, url]);
|
|
712
828
|
case "issue":
|
|
713
829
|
return compact([`[Issue${role}] ${event.ref ?? ""}:`, title, url]);
|
|
830
|
+
case "security":
|
|
831
|
+
return compact([`[${event.label ?? "Security"}]${event.ref ? ` ${event.ref}` : ""}`, title, url]);
|
|
714
832
|
default:
|
|
715
833
|
return compact([`[${event.label ?? event.kind ?? "event"}${role}]`, title, url]);
|
|
716
834
|
}
|
|
@@ -943,6 +1061,43 @@ export function fetchOpenPullRequests(cwd) {
|
|
|
943
1061
|
return ghJson(["pr", "list", "--state", "open", "--json", PR_FIELDS], { cwd });
|
|
944
1062
|
}
|
|
945
1063
|
|
|
1064
|
+
/**
|
|
1065
|
+
* Open security advisories for the watched repository. Never fatal: a private
|
|
1066
|
+
* repository on a free plan, a disabled Dependabot, or a token without the
|
|
1067
|
+
* `security_events` scope all answer 403/404, and the poll continues.
|
|
1068
|
+
*/
|
|
1069
|
+
export function fetchSecurityAlerts(cwd) {
|
|
1070
|
+
const wanted = [
|
|
1071
|
+
{ source: "dependabot", path: "dependabot/alerts" },
|
|
1072
|
+
{ source: "code-scanning", path: "code-scanning/alerts" },
|
|
1073
|
+
];
|
|
1074
|
+
const alerts = [];
|
|
1075
|
+
const notes = [];
|
|
1076
|
+
for (const { source, path } of wanted) {
|
|
1077
|
+
const result = ghJson(["api", `repos/${activeRepo}/${path}?state=open&per_page=20`], { cwd });
|
|
1078
|
+
if (!result.ok) {
|
|
1079
|
+
const reason = String(result.reason ?? "");
|
|
1080
|
+
// gh reports a 404 "no analysis found" as a scope problem and suggests
|
|
1081
|
+
// admin:repo_hook, which cannot read code scanning. Say what actually
|
|
1082
|
+
// helps instead of repeating a hint that leads nowhere.
|
|
1083
|
+
const noAnalysis = reason.includes("no analysis found");
|
|
1084
|
+
const needsScope = !noAnalysis && reason.includes("admin:repo_hook");
|
|
1085
|
+
notes.push(
|
|
1086
|
+
noAnalysis
|
|
1087
|
+
? `${source} is not set up in this repository (no analysis found)`
|
|
1088
|
+
: needsScope
|
|
1089
|
+
? `${source} needs the security_events scope (gh auth refresh -h github.com -s security_events)`
|
|
1090
|
+
: `${source} unavailable (${reason})`,
|
|
1091
|
+
);
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
for (const alert of Array.isArray(result.value) ? result.value : []) {
|
|
1095
|
+
alerts.push({ source, alert });
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
return { alerts, notes };
|
|
1099
|
+
}
|
|
1100
|
+
|
|
946
1101
|
export function notificationsSince(state, cwd) {
|
|
947
1102
|
const since =
|
|
948
1103
|
typeof state?.lastPollAt === "string" && Number.isFinite(Date.parse(state.lastPollAt))
|
|
@@ -1132,6 +1287,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1132
1287
|
const fresh = [];
|
|
1133
1288
|
const skipped = [];
|
|
1134
1289
|
const notices = [];
|
|
1290
|
+
const securityNotes = [];
|
|
1135
1291
|
const cleared = [];
|
|
1136
1292
|
const clearFailed = [];
|
|
1137
1293
|
const nextRepos = { ...normalizeStateFile(state).repos };
|
|
@@ -1151,6 +1307,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1151
1307
|
fetchPrs: () => fetchOpenPullRequests(repoRoot),
|
|
1152
1308
|
fetchIssues: () => fetchOpenIssues(repoRoot),
|
|
1153
1309
|
fetchFeed: (currentState) => fetchFeed(currentState, repoRoot),
|
|
1310
|
+
fetchSecurity: () => fetchSecurityAlerts(repoRoot),
|
|
1154
1311
|
});
|
|
1155
1312
|
if (result.skipped) {
|
|
1156
1313
|
skipped.push({ repo, reason: result.skipped });
|
|
@@ -1163,6 +1320,10 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1163
1320
|
cleared.push(...(result.cleared ?? []));
|
|
1164
1321
|
clearFailed.push(...(result.clearFailed ?? []));
|
|
1165
1322
|
if (result.feedSkipped) notices.push(`${repo}: feed skipped (${result.feedSkipped})`);
|
|
1323
|
+
// A repository without Dependabot / code scanning answers 403 on every poll.
|
|
1324
|
+
// That is a standing fact about the install, not news per minute, so it is
|
|
1325
|
+
// reported in `--json` and by `doctor` instead of the per-poll log line.
|
|
1326
|
+
for (const note of result.securityNotes ?? []) securityNotes.push(`${repo}: ${note}`);
|
|
1166
1327
|
nextRepos[repo] = {
|
|
1167
1328
|
...result.nextState,
|
|
1168
1329
|
lastPoll: {
|
|
@@ -1193,6 +1354,7 @@ function runPoll({ repoRoot, stateFile, pendingFile, state, options, now, me, re
|
|
|
1193
1354
|
fresh,
|
|
1194
1355
|
cleared,
|
|
1195
1356
|
clearFailed,
|
|
1357
|
+
securityNotes,
|
|
1196
1358
|
stateFile,
|
|
1197
1359
|
pendingFile,
|
|
1198
1360
|
state: withMeta,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
extractNotificationEvents,
|
|
18
18
|
extractPrEvents,
|
|
19
19
|
extractRunEvents,
|
|
20
|
+
extractSecurityEvents,
|
|
20
21
|
filterRuns,
|
|
21
22
|
formatEvent,
|
|
22
23
|
mentionsLogin,
|
|
@@ -884,3 +885,122 @@ test("clearing off never touches the threads", () => {
|
|
|
884
885
|
assert.equal(called, false);
|
|
885
886
|
assert.deepEqual(result.cleared, []);
|
|
886
887
|
});
|
|
888
|
+
|
|
889
|
+
// ---------------------------------------------------------------------------
|
|
890
|
+
// Pull requests that cannot merge, and security advisories
|
|
891
|
+
// ---------------------------------------------------------------------------
|
|
892
|
+
|
|
893
|
+
test("a conflicted pull request is work even when nothing failed", () => {
|
|
894
|
+
const author = { login: ME };
|
|
895
|
+
const conflicted = extractPrEvents(
|
|
896
|
+
[
|
|
897
|
+
{
|
|
898
|
+
number: 12,
|
|
899
|
+
title: "feat: land the thing",
|
|
900
|
+
author,
|
|
901
|
+
reviewRequests: [],
|
|
902
|
+
assignees: [],
|
|
903
|
+
reviewDecision: "",
|
|
904
|
+
mergeStateStatus: "DIRTY",
|
|
905
|
+
statusCheckRollup: [{ name: "verify", conclusion: "SUCCESS" }],
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
{ me: ME },
|
|
909
|
+
);
|
|
910
|
+
assert.equal(conflicted.length, 1);
|
|
911
|
+
assert.match(formatEvent(conflicted[0]), /merge conflict with the base branch/u);
|
|
912
|
+
assert.match(conflicted[0].key, /\|merge:DIRTY$/u);
|
|
913
|
+
|
|
914
|
+
const behind = extractPrEvents(
|
|
915
|
+
[{ number: 13, title: "x", author, reviewDecision: "", mergeStateStatus: "BEHIND" }],
|
|
916
|
+
{ me: ME },
|
|
917
|
+
);
|
|
918
|
+
assert.match(formatEvent(behind[0]), /behind the base branch/u);
|
|
919
|
+
assert.match(behind[0].key, /\|merge:BEHIND$/u);
|
|
920
|
+
|
|
921
|
+
// A reviewer reading a conflicted PR has nothing to do about the conflict:
|
|
922
|
+
// the review request is the task, and the merge state must not enter its key.
|
|
923
|
+
const asReviewer = extractPrEvents(
|
|
924
|
+
[
|
|
925
|
+
{
|
|
926
|
+
number: 14,
|
|
927
|
+
title: "x",
|
|
928
|
+
author: { login: "someone-else" },
|
|
929
|
+
reviewRequests: [{ login: ME }],
|
|
930
|
+
mergeStateStatus: "DIRTY",
|
|
931
|
+
},
|
|
932
|
+
],
|
|
933
|
+
{ me: ME },
|
|
934
|
+
);
|
|
935
|
+
assert.equal(asReviewer.length, 1);
|
|
936
|
+
assert.equal(asReviewer[0].key, "pr:14:reviewer:review-requested");
|
|
937
|
+
assert.deepEqual(asReviewer[0].reasons, ["review requested from you"]);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
test("a clean pull request keeps the digest it had before", () => {
|
|
941
|
+
const clean = pullRequest({ mergeStateStatus: "CLEAN" });
|
|
942
|
+
assert.equal(prStatusDigest(clean), prStatusDigest(pullRequest()));
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
test("open advisories collapse into one line per source", () => {
|
|
946
|
+
const alerts = [
|
|
947
|
+
{
|
|
948
|
+
source: "dependabot",
|
|
949
|
+
alert: {
|
|
950
|
+
number: 3,
|
|
951
|
+
html_url: "u3",
|
|
952
|
+
security_advisory: { severity: "high", summary: "Prototype pollution in foo" },
|
|
953
|
+
dependency: { package: { name: "foo" } },
|
|
954
|
+
updated_at: "2026-11-16T09:00:00Z",
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
source: "dependabot",
|
|
959
|
+
alert: {
|
|
960
|
+
number: 4,
|
|
961
|
+
html_url: "u4",
|
|
962
|
+
security_advisory: { severity: "low", summary: "TLS client crash in bar" },
|
|
963
|
+
dependency: { package: { name: "bar" } },
|
|
964
|
+
updated_at: "2026-11-16T10:00:00Z",
|
|
965
|
+
},
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
source: "code-scanning",
|
|
969
|
+
alert: {
|
|
970
|
+
number: 7,
|
|
971
|
+
html_url: "u7",
|
|
972
|
+
rule: { description: "Unvalidated input reaches the shell", security_severity_level: "medium" },
|
|
973
|
+
most_recent_instance: { location: { path: "scripts/run.mjs" } },
|
|
974
|
+
},
|
|
975
|
+
},
|
|
976
|
+
];
|
|
977
|
+
const events = extractSecurityEvents(alerts);
|
|
978
|
+
assert.deepEqual(
|
|
979
|
+
events.map((event) => event.key),
|
|
980
|
+
["dependabot", "code-scanning"],
|
|
981
|
+
);
|
|
982
|
+
assert.equal(events[0].kind, "security");
|
|
983
|
+
assert.equal(events[0].role, "any");
|
|
984
|
+
assert.equal(events[0].at, "2026-11-16T10:00:00Z");
|
|
985
|
+
const dependabot = formatEvent(events[0]);
|
|
986
|
+
assert.match(dependabot, /^\[Dependabot\] 2 open advisories \(1 high, 1 low\): foo, bar https:\/\//u);
|
|
987
|
+
assert.match(dependabot, /security\/dependabot$/u);
|
|
988
|
+
const scanning = formatEvent(events[1]);
|
|
989
|
+
assert.match(scanning, /^\[Code scanning\] 1 open advisory \(1 medium\): scripts\/run\.mjs /u);
|
|
990
|
+
assert.ok(!scanning.includes("#7"), "an aggregated line carries no alert number");
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
test("a repository without Dependabot still polls the rest", () => {
|
|
994
|
+
const result = pollOnce({
|
|
995
|
+
state: normalizeState({}),
|
|
996
|
+
...sources({ runs: [run()] }),
|
|
997
|
+
fetchSecurity: () => ({
|
|
998
|
+
alerts: [],
|
|
999
|
+
notes: ["dependabot unavailable (HTTP 403: Resource not accessible by integration)"],
|
|
1000
|
+
}),
|
|
1001
|
+
now: new Date("2026-11-15T04:00:00Z"),
|
|
1002
|
+
});
|
|
1003
|
+
assert.equal(result.skipped, undefined);
|
|
1004
|
+
assert.equal(result.fresh.length, 1);
|
|
1005
|
+
assert.match(result.securityNotes[0], /dependabot unavailable/u);
|
|
1006
|
+
});
|