@openchamber/web 1.18.4 → 1.19.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/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-D9cV-qR9.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-B9NCadU7.js} +1 -1
- package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
- package/dist/assets/{DiffView-DZIoOnV7.js → DiffView-BWNq-0ov.js} +2 -2
- package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
- package/dist/assets/{GitView-DBFrDDBv.js → GitView-DsWXqWx3.js} +3 -3
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-h4dHASlq.js} +1 -1
- package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
- package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-jPKTJje5.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
- package/dist/assets/PlanView-UvuxIl9-.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
- package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
- package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
- package/dist/assets/{ToolOutputDialog-Za6V4VMJ.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BL-9ixyC.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-Bxun3k66.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
- package/dist/assets/de-DbV6CLxv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-CVDlyzZ4.js +15 -0
- package/dist/assets/fr-Czc-p0g-.js +13 -0
- package/dist/assets/index-1OhiMDBz.css +1 -0
- package/dist/assets/index-BSvmTvZl.js +1 -0
- package/dist/assets/index-DzriVon2.js +7 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-DwHKxDYc.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-Dwq6ILxo.js} +1 -1
- package/dist/assets/ja-dwc9NM_S.js +15 -0
- package/dist/assets/ko-Ds1DZ8FX.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-BF51IOVF.js +921 -0
- package/dist/assets/{main-D7UcL3VQ.js → main-D7UPARut.js} +2 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
- package/dist/assets/{miniChat-O_GVoEbc.js → miniChat-BISXSGOo.js} +2 -2
- package/dist/assets/mobile-BnYxVuvw.js +2 -0
- package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BEDPDypx.js} +2 -2
- package/dist/assets/pl-CLiTO7i-.js +15 -0
- package/dist/assets/pt-BR-GIimJgpK.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
- package/dist/assets/{renderMobileApp-toj9cXoh.js → renderMobileApp-BiMbzPq9.js} +7 -7
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
- package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DXYW46vW.js} +1 -1
- package/dist/assets/uk-DLfgD1ki.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-CbzHzFop.js} +139 -142
- package/dist/assets/{useInlineCommentController-CYPvYJDt.js → useInlineCommentController-CegKdDXi.js} +2 -2
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.js → web-components-DCLjCO9n.js} +1 -1
- package/dist/assets/zh-CN-DkeP5awK.js +15 -0
- package/dist/assets/zh-TW-BocaFm3d.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +116 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +56 -0
- package/server/lib/agent-memory/project-resolution.test.js +85 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +427 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +225 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/service.js +121 -67
- package/server/lib/git/service.test.js +129 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -4
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +11 -0
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/settings-helpers.js +11 -0
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/settings-runtime.js +51 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/project-context/DOCUMENTATION.md +158 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +667 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/quota/DOCUMENTATION.md +16 -1
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +72 -0
- package/server/lib/quota/providers/index.js +22 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/small-model/index.js +8 -0
- package/server/lib/small-model/index.test.js +31 -1
- package/server/lib/small-model/routes.js +3 -1
- package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
- package/dist/assets/FilesView-BKL6YlKG.js +0 -14
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
- package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
- package/dist/assets/SettingsView-5RmswFZe.js +0 -28
- package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-BzIpNlNE.css +0 -1
- package/dist/assets/index-C0yNhuZw.js +0 -1
- package/dist/assets/index-DRpChWux.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/mobile-Br4TtAqc.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
|
@@ -75,8 +75,14 @@
|
|
|
75
75
|
- It resolves those remotes into GitHub repos.
|
|
76
76
|
- It expands each repo through `parent` and `source` so PRs in upstream repos can still be found.
|
|
77
77
|
- It skips PR lookup when the current branch matches that repo's default branch.
|
|
78
|
-
- It first searches for PRs by likely source owner plus exact head branch.
|
|
79
|
-
- If that fails, it falls back to broader GitHub search for the branch name.
|
|
78
|
+
- It first searches for **open** PRs by likely source owner plus exact head branch.
|
|
79
|
+
- If that fails, it falls back to broader GitHub search for open PRs on the branch name.
|
|
80
|
+
- An **open PR from any candidate repo always wins** over a closed/merged one, so a merged fork PR can never hide an open upstream PR for the same head.
|
|
81
|
+
- Only when no target has an open PR does it return the branch's newest closed/merged PR, as history.
|
|
82
|
+
- History is looked up **only for the ranked-first remote and the branch's own name** — the repo it actually pushes to. Live status is worth searching the whole fork network for; history is not, and asking every target for it multiplies serial GitHub calls until the route hits its `12s` resolve timeout and returns no status at all.
|
|
83
|
+
- The history answer is remembered per repo+branch so discovery polls do not re-query it: a found closed/merged record for `6h`, and "no history yet" for `10m`. A found record only changes if a second PR appears on the same head, and while that one is open the open-PR path wins without ever reading this cache.
|
|
84
|
+
- Creating, merging, or closing a PR invalidates both the shared repo pull list and that remembered history.
|
|
85
|
+
- The route skips the checks summary and the merge-permission lookup for a closed/merged PR: neither is actionable, and both cost extra GitHub calls.
|
|
80
86
|
- `403` and `404` during repo lookups are treated as expected gaps, not hard errors.
|
|
81
87
|
|
|
82
88
|
## Shared client state model
|
|
@@ -108,11 +114,16 @@
|
|
|
108
114
|
- Open PR with pending checks -> refresh about every `1m`.
|
|
109
115
|
- Open PR with non-pending checks -> refresh about every `5m`.
|
|
110
116
|
- Open PR without a stable checks signal -> refresh about every `2m`.
|
|
111
|
-
- Closed or merged PR -> stop
|
|
117
|
+
- Closed or merged PR -> discovery refresh every `5m` (do not permanently stop polling).
|
|
112
118
|
- Hidden tab -> skip polling.
|
|
113
119
|
- Non-forced refreshes use a `90s` TTL.
|
|
114
120
|
- Failed non-forced attempts also observe the `90s` TTL so transient server or rate-limit failures cannot retry on every sidebar update. Forced user/action refreshes bypass this guard.
|
|
115
121
|
|
|
122
|
+
## Persistence notes for terminal PRs
|
|
123
|
+
|
|
124
|
+
- Closed/merged branch associations are persisted like open ones, so a reload still shows that the branch's PR was merged.
|
|
125
|
+
- Hydrate resets `lastDiscoveryPollAt` for them, so restored history revalidates on the first watcher tick instead of waiting out a discovery interval.
|
|
126
|
+
|
|
116
127
|
## Background tracking rules
|
|
117
128
|
|
|
118
129
|
- Track up to `50` likely directories.
|
|
@@ -332,6 +332,38 @@ const safeListPulls = async (octokit, options) => {
|
|
|
332
332
|
const REPO_PULLS_CACHE_TTL_MS = 45_000;
|
|
333
333
|
const repoPullsCache = new Map();
|
|
334
334
|
|
|
335
|
+
// Remembered answer to "what is the newest closed/merged PR for this head?",
|
|
336
|
+
// so discovery polls do not re-ask GitHub every few minutes.
|
|
337
|
+
//
|
|
338
|
+
// A found record barely ever changes: it would take a second PR on the same
|
|
339
|
+
// head, and while that one is open the open-PR path wins and never reads this
|
|
340
|
+
// cache at all. "No history yet" is the volatile answer, since closing or
|
|
341
|
+
// merging a PR elsewhere flips it, so it expires far sooner. Either way, doing
|
|
342
|
+
// it from OpenChamber invalidates the entry immediately.
|
|
343
|
+
const HISTORICAL_PR_FOUND_TTL_MS = 6 * 60 * 60 * 1000;
|
|
344
|
+
const HISTORICAL_PR_ABSENT_TTL_MS = 10 * 60 * 1000;
|
|
345
|
+
const HISTORICAL_PR_CACHE_MAX_ENTRIES = 500;
|
|
346
|
+
const _historicalPrCache = new Map();
|
|
347
|
+
|
|
348
|
+
const isHistoricalPrCacheFresh = (entry) => {
|
|
349
|
+
if (!entry) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
const ttl = entry.pr ? HISTORICAL_PR_FOUND_TTL_MS : HISTORICAL_PR_ABSENT_TTL_MS;
|
|
353
|
+
return Date.now() - entry.fetchedAt < ttl;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const rememberHistoricalPr = (key, pr) => {
|
|
357
|
+
_historicalPrCache.delete(key);
|
|
358
|
+
_historicalPrCache.set(key, { pr, fetchedAt: Date.now() });
|
|
359
|
+
if (_historicalPrCache.size > HISTORICAL_PR_CACHE_MAX_ENTRIES) {
|
|
360
|
+
const oldest = _historicalPrCache.keys().next().value;
|
|
361
|
+
if (oldest !== undefined) {
|
|
362
|
+
_historicalPrCache.delete(oldest);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
335
367
|
export const invalidateRepoPullsCache = (owner, repo) => {
|
|
336
368
|
const prefix = `${normalizeText(owner)}/${normalizeText(repo)}::`;
|
|
337
369
|
for (const key of repoPullsCache.keys()) {
|
|
@@ -347,6 +379,13 @@ export const invalidateRepoPullsCache = (owner, repo) => {
|
|
|
347
379
|
_searchMissCache.delete(key);
|
|
348
380
|
}
|
|
349
381
|
}
|
|
382
|
+
// A merge or close changes the branch's PR history, so drop it too.
|
|
383
|
+
const historicalPrefix = `${normalizeRepoKey(owner, repo)}::`;
|
|
384
|
+
for (const key of _historicalPrCache.keys()) {
|
|
385
|
+
if (key.startsWith(historicalPrefix)) {
|
|
386
|
+
_historicalPrCache.delete(key);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
350
389
|
};
|
|
351
390
|
|
|
352
391
|
const getRepoPulls = (octokit, repo, state, { force = false } = {}) => {
|
|
@@ -440,60 +479,61 @@ const searchFallbackPr = async ({ octokit, branch, repoNames }) => {
|
|
|
440
479
|
|
|
441
480
|
const normalizedRepoNames = new Set(repoNames.map((name) => normalizeLower(name)).filter(Boolean));
|
|
442
481
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (error?.status === 404) {
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
throw error;
|
|
482
|
+
// The Search API has a tiny quota, so it is only spent on live branch status.
|
|
483
|
+
// Closed/merged history is resolved by the cheaper per-head repo queries.
|
|
484
|
+
let response;
|
|
485
|
+
try {
|
|
486
|
+
response = await octokit.rest.search.issuesAndPullRequests({
|
|
487
|
+
q: `is:pr state:open head:${branch}`,
|
|
488
|
+
per_page: 20,
|
|
489
|
+
});
|
|
490
|
+
// If we get here, search API works for this repo — clear the disabled flag
|
|
491
|
+
_searchApiDisabledRepos.delete(repoKey);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
noteIfGitHubRateLimit(error);
|
|
494
|
+
if (error?.status === 403) {
|
|
495
|
+
_searchApiDisabledRepos.set(repoKey, Date.now());
|
|
496
|
+
return null;
|
|
462
497
|
}
|
|
498
|
+
if (error?.status === 404) {
|
|
499
|
+
rememberSearchMiss(missKey);
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
throw error;
|
|
503
|
+
}
|
|
463
504
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
505
|
+
const items = Array.isArray(response?.data?.items) ? response.data.items : [];
|
|
506
|
+
for (const item of items) {
|
|
507
|
+
const repo = parseRepoFromApiUrl(item?.repository_url);
|
|
508
|
+
if (!repo) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (normalizedRepoNames.size > 0 && !normalizedRepoNames.has(normalizeLower(repo.repo))) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
const prResponse = await octokit.rest.pulls.get({
|
|
516
|
+
owner: repo.owner,
|
|
517
|
+
repo: repo.repo,
|
|
518
|
+
pull_number: item.number,
|
|
519
|
+
});
|
|
520
|
+
const pr = prResponse?.data;
|
|
521
|
+
if (!pr || normalizeText(pr.head?.ref) !== branch) {
|
|
471
522
|
continue;
|
|
472
523
|
}
|
|
473
|
-
|
|
474
|
-
|
|
524
|
+
return {
|
|
525
|
+
repo: {
|
|
475
526
|
owner: repo.owner,
|
|
476
527
|
repo: repo.repo,
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
repo: {
|
|
485
|
-
owner: repo.owner,
|
|
486
|
-
repo: repo.repo,
|
|
487
|
-
url: `https://github.com/${repo.owner}/${repo.repo}`,
|
|
488
|
-
},
|
|
489
|
-
pr,
|
|
490
|
-
};
|
|
491
|
-
} catch (error) {
|
|
492
|
-
if (error?.status === 403 || error?.status === 404) {
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
throw error;
|
|
528
|
+
url: `https://github.com/${repo.owner}/${repo.repo}`,
|
|
529
|
+
},
|
|
530
|
+
pr,
|
|
531
|
+
};
|
|
532
|
+
} catch (error) {
|
|
533
|
+
if (error?.status === 403 || error?.status === 404) {
|
|
534
|
+
continue;
|
|
496
535
|
}
|
|
536
|
+
throw error;
|
|
497
537
|
}
|
|
498
538
|
}
|
|
499
539
|
|
|
@@ -501,7 +541,22 @@ const searchFallbackPr = async ({ octokit, branch, repoNames }) => {
|
|
|
501
541
|
return null;
|
|
502
542
|
};
|
|
503
543
|
|
|
504
|
-
const
|
|
544
|
+
const isTerminalPr = (pr) => Boolean(pr) && (pr.state === 'closed' || Boolean(pr.merged_at));
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Resolve the PRs a branch is associated with in one repo target.
|
|
548
|
+
*
|
|
549
|
+
* Returns both candidates because they answer different questions:
|
|
550
|
+
* `open` is live branch status, `historical` is the last closed/merged PR for
|
|
551
|
+
* the same head. The caller must prefer an open PR from ANY target over a
|
|
552
|
+
* historical one — otherwise a merged fork PR hides an open upstream PR.
|
|
553
|
+
*
|
|
554
|
+
* `includeHistory` is off by default and must stay that way for secondary
|
|
555
|
+
* targets. Live status is worth searching the whole fork network for; history
|
|
556
|
+
* is not, and doing it per target multiplied the serial GitHub calls until the
|
|
557
|
+
* route hit its resolve timeout and reported no status at all.
|
|
558
|
+
*/
|
|
559
|
+
const findBranchPrCandidates = async ({ octokit, target, branch, sourceCandidates, force = false, coverage = null, includeHistory = false }) => {
|
|
505
560
|
const matcher = buildSourceMatcher(sourceCandidates);
|
|
506
561
|
const sourceOwners = [];
|
|
507
562
|
sourceCandidates.forEach((candidate) => pushUnique(sourceOwners, candidate.repo?.owner));
|
|
@@ -511,46 +566,72 @@ const findFirstMatchingPr = async ({ octokit, target, branch, sourceCandidates,
|
|
|
511
566
|
.filter((pr) => matcher.matches(pr, target.repo.repo))
|
|
512
567
|
.sort((left, right) => matcher.compare(left, right, target.repo.repo))[0] ?? null;
|
|
513
568
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if (fromList) {
|
|
523
|
-
return fromList;
|
|
524
|
-
}
|
|
525
|
-
listWasComplete = listEntry.complete;
|
|
526
|
-
} catch {
|
|
527
|
-
// fall through to the precise per-branch queries
|
|
528
|
-
}
|
|
529
|
-
if (listWasComplete) {
|
|
530
|
-
continue;
|
|
569
|
+
// The shared repo-level open list answers every branch of the repo within the
|
|
570
|
+
// TTL. A miss in a complete list is authoritative: no open PR exists here.
|
|
571
|
+
let openListWasComplete = false;
|
|
572
|
+
try {
|
|
573
|
+
const listEntry = await getRepoPulls(octokit, target.repo, 'open', { force });
|
|
574
|
+
const fromList = pickPreferred(listEntry.prs);
|
|
575
|
+
if (fromList) {
|
|
576
|
+
return { open: fromList, historical: null };
|
|
531
577
|
}
|
|
532
|
-
|
|
533
|
-
|
|
578
|
+
openListWasComplete = listEntry.complete;
|
|
579
|
+
} catch {
|
|
580
|
+
// fall through to the precise per-head queries
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (!openListWasComplete && coverage) {
|
|
584
|
+
coverage.authoritative = false;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// A complete open list already proved there is no open PR in this repo. With
|
|
588
|
+
// no history to look up there is nothing left to ask GitHub.
|
|
589
|
+
if (openListWasComplete && !includeHistory) {
|
|
590
|
+
return { open: null, historical: null };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const historicalKey = `${normalizeRepoKey(target.repo?.owner, target.repo?.repo)}::${branch}`;
|
|
594
|
+
if (includeHistory && !force && openListWasComplete) {
|
|
595
|
+
const cached = _historicalPrCache.get(historicalKey);
|
|
596
|
+
if (isHistoricalPrCacheFresh(cached)) {
|
|
597
|
+
return { open: null, historical: cached.pr };
|
|
534
598
|
}
|
|
599
|
+
}
|
|
535
600
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
601
|
+
// One query per source owner. With history enabled `state: 'all'` answers
|
|
602
|
+
// both questions at once, so asking for history never costs an extra call.
|
|
603
|
+
let historical = null;
|
|
604
|
+
for (const owner of sourceOwners) {
|
|
605
|
+
const directCandidates = await safeListPulls(octokit, {
|
|
606
|
+
owner: target.repo.owner,
|
|
607
|
+
repo: target.repo.repo,
|
|
608
|
+
state: includeHistory ? 'all' : 'open',
|
|
609
|
+
head: `${owner}:${branch}`,
|
|
610
|
+
per_page: 100,
|
|
611
|
+
});
|
|
612
|
+
const openMatch = pickPreferred(directCandidates.filter((pr) => !isTerminalPr(pr)));
|
|
613
|
+
if (openMatch) {
|
|
614
|
+
return { open: openMatch, historical: null };
|
|
615
|
+
}
|
|
616
|
+
if (includeHistory && !historical) {
|
|
617
|
+
// Among past PRs for the same head the newest one is the relevant record.
|
|
618
|
+
historical = directCandidates
|
|
619
|
+
.filter((pr) => normalizeText(pr?.head?.ref) === branch)
|
|
620
|
+
.filter((pr) => matcher.matches(pr, target.repo.repo))
|
|
621
|
+
.filter(isTerminalPr)
|
|
622
|
+
.sort((left, right) => (right?.number ?? 0) - (left?.number ?? 0))[0] ?? null;
|
|
548
623
|
}
|
|
549
624
|
}
|
|
550
625
|
|
|
551
|
-
|
|
626
|
+
if (includeHistory) {
|
|
627
|
+
rememberHistoricalPr(historicalKey, historical);
|
|
628
|
+
}
|
|
629
|
+
return { open: null, historical };
|
|
552
630
|
};
|
|
553
631
|
|
|
632
|
+
// Exported for focused unit tests of open-versus-historical branch matching.
|
|
633
|
+
export { findBranchPrCandidates };
|
|
634
|
+
|
|
554
635
|
export async function resolveGitHubPrStatus({ octokit, directory, branch, remoteName, force = false }) {
|
|
555
636
|
// A deleted worktree can still have a session in the sidebar that keeps
|
|
556
637
|
// requesting its PR status. Bail before touching git or GitHub for a
|
|
@@ -602,6 +683,11 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
|
|
|
602
683
|
let fallbackRemoteName = resolvedTargets[0].remoteName;
|
|
603
684
|
let fallbackDefaultBranch = await getRepoDefaultBranch(octokit, fallbackRepo);
|
|
604
685
|
|
|
686
|
+
// The first closed/merged PR found, in target priority order. It is only
|
|
687
|
+
// returned once every target has been checked for an open PR, so an open
|
|
688
|
+
// upstream PR always wins over a merged fork PR for the same head.
|
|
689
|
+
let historicalMatch = null;
|
|
690
|
+
|
|
605
691
|
for (const target of resolvedTargets) {
|
|
606
692
|
const defaultBranch = await getRepoDefaultBranch(octokit, target.repo);
|
|
607
693
|
if (!fallbackRepo) {
|
|
@@ -616,18 +702,33 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
|
|
|
616
702
|
continue;
|
|
617
703
|
}
|
|
618
704
|
|
|
619
|
-
|
|
705
|
+
// History is only asked of the branch's own repo and its own name: the
|
|
706
|
+
// ranked-first target is the remote this branch actually pushes to.
|
|
707
|
+
// Searching the rest of the fork network for history would multiply
|
|
708
|
+
// serial GitHub calls for no additional user-visible information.
|
|
709
|
+
const isPrimaryAssociation = target === resolvedTargets[0] && candidateBranch === branchCandidates[0];
|
|
710
|
+
|
|
711
|
+
const { open, historical } = await findBranchPrCandidates({
|
|
620
712
|
octokit,
|
|
621
713
|
target,
|
|
622
714
|
branch: candidateBranch,
|
|
623
715
|
sourceCandidates,
|
|
624
716
|
force,
|
|
625
717
|
coverage,
|
|
718
|
+
includeHistory: isPrimaryAssociation,
|
|
626
719
|
});
|
|
627
|
-
if (
|
|
720
|
+
if (open) {
|
|
628
721
|
return {
|
|
629
722
|
repo: target.repo,
|
|
630
|
-
pr,
|
|
723
|
+
pr: open,
|
|
724
|
+
defaultBranch,
|
|
725
|
+
resolvedRemoteName: target.remoteName,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
if (historical && !historicalMatch) {
|
|
729
|
+
historicalMatch = {
|
|
730
|
+
repo: target.repo,
|
|
731
|
+
pr: historical,
|
|
631
732
|
defaultBranch,
|
|
632
733
|
resolvedRemoteName: target.remoteName,
|
|
633
734
|
};
|
|
@@ -654,6 +755,10 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
|
|
|
654
755
|
}
|
|
655
756
|
}
|
|
656
757
|
|
|
758
|
+
if (historicalMatch) {
|
|
759
|
+
return historicalMatch;
|
|
760
|
+
}
|
|
761
|
+
|
|
657
762
|
return {
|
|
658
763
|
repo: fallbackRepo,
|
|
659
764
|
pr: null,
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test, vi } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
const listMock = mock(async () => ({ data: [] }));
|
|
4
|
+
|
|
5
|
+
mock.module('../git/index.js', () => ({
|
|
6
|
+
getRemotes: async () => [],
|
|
7
|
+
getStatus: async () => null,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
mock.module('./repo/index.js', () => ({
|
|
11
|
+
resolveGitHubRepoFromDirectory: async () => null,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
mock.module('./rate-limit.js', () => ({
|
|
15
|
+
noteIfGitHubRateLimit: () => {},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const { findBranchPrCandidates, invalidateRepoPullsCache } = await import('./pr-status.js');
|
|
19
|
+
|
|
20
|
+
const openPr = {
|
|
21
|
+
number: 15,
|
|
22
|
+
state: 'open',
|
|
23
|
+
head: {
|
|
24
|
+
ref: 'feature',
|
|
25
|
+
label: 'acme:feature',
|
|
26
|
+
user: { login: 'acme' },
|
|
27
|
+
repo: { owner: { login: 'acme' }, name: 'app' },
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const mergedPr = {
|
|
32
|
+
number: 12,
|
|
33
|
+
state: 'closed',
|
|
34
|
+
merged_at: '2026-01-01T00:00:00Z',
|
|
35
|
+
head: {
|
|
36
|
+
ref: 'feature',
|
|
37
|
+
label: 'acme:feature',
|
|
38
|
+
user: { login: 'acme' },
|
|
39
|
+
repo: { owner: { login: 'acme' }, name: 'app' },
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const olderMergedPr = {
|
|
44
|
+
...mergedPr,
|
|
45
|
+
number: 7,
|
|
46
|
+
merged_at: '2025-11-01T00:00:00Z',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const call = (overrides = {}) => findBranchPrCandidates({
|
|
50
|
+
octokit: { rest: { pulls: { list: listMock } } },
|
|
51
|
+
target: { repo: { owner: 'acme', repo: 'app' }, remoteName: 'origin' },
|
|
52
|
+
branch: 'feature',
|
|
53
|
+
sourceCandidates: [{ repo: { owner: 'acme', repo: 'app' } }],
|
|
54
|
+
force: true,
|
|
55
|
+
includeHistory: true,
|
|
56
|
+
...overrides,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('findBranchPrCandidates', () => {
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
listMock.mockReset();
|
|
62
|
+
invalidateRepoPullsCache('acme', 'app');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
vi.useRealTimers();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('an open PR wins and no history lookup is spent', async () => {
|
|
70
|
+
listMock.mockImplementation(async ({ state }) => (
|
|
71
|
+
state === 'open' ? { data: [openPr] } : { data: [mergedPr] }
|
|
72
|
+
));
|
|
73
|
+
|
|
74
|
+
const { open, historical } = await call();
|
|
75
|
+
|
|
76
|
+
expect(open?.number).toBe(15);
|
|
77
|
+
expect(historical).toBeNull();
|
|
78
|
+
expect(listMock.mock.calls.every((entry) => entry[0]?.state === 'open')).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('an open PR still wins when the shared open list missed it', async () => {
|
|
82
|
+
// A repo with more than one page of open PRs: the shared list is incomplete,
|
|
83
|
+
// so the per-head query is the one that must find the open PR.
|
|
84
|
+
listMock.mockImplementation(async ({ head }) => (
|
|
85
|
+
head ? { data: [mergedPr, openPr] } : { data: new Array(100).fill(null).map((_, index) => ({ number: index, state: 'open', head: { ref: 'other' } })) }
|
|
86
|
+
));
|
|
87
|
+
|
|
88
|
+
const { open, historical } = await call();
|
|
89
|
+
|
|
90
|
+
expect(open?.number).toBe(15);
|
|
91
|
+
expect(historical).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('returns the branch history when no open PR exists', async () => {
|
|
95
|
+
listMock.mockImplementation(async ({ head }) => (
|
|
96
|
+
head ? { data: [olderMergedPr, mergedPr] } : { data: [] }
|
|
97
|
+
));
|
|
98
|
+
|
|
99
|
+
const { open, historical } = await call();
|
|
100
|
+
|
|
101
|
+
expect(open).toBeNull();
|
|
102
|
+
// The newest past PR for the head is the relevant record.
|
|
103
|
+
expect(historical?.number).toBe(12);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('returns no history for a branch that never had a PR', async () => {
|
|
107
|
+
listMock.mockImplementation(async () => ({ data: [] }));
|
|
108
|
+
|
|
109
|
+
const { open, historical } = await call();
|
|
110
|
+
|
|
111
|
+
expect(open).toBeNull();
|
|
112
|
+
expect(historical).toBeNull();
|
|
113
|
+
expect(listMock.mock.calls.some((entry) => entry[0]?.state === 'all')).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('spends no call on history for a secondary target', async () => {
|
|
117
|
+
listMock.mockImplementation(async ({ head }) => (
|
|
118
|
+
head ? { data: [mergedPr] } : { data: [] }
|
|
119
|
+
));
|
|
120
|
+
|
|
121
|
+
const { open, historical } = await call({ includeHistory: false });
|
|
122
|
+
|
|
123
|
+
expect(open).toBeNull();
|
|
124
|
+
expect(historical).toBeNull();
|
|
125
|
+
// The complete open list already answered the only question that matters
|
|
126
|
+
// for a secondary repo in the fork network.
|
|
127
|
+
expect(listMock.mock.calls).toHaveLength(1);
|
|
128
|
+
expect(listMock.mock.calls[0]?.[0]?.state).toBe('open');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('reuses the cached history instead of re-querying every poll', async () => {
|
|
132
|
+
listMock.mockImplementation(async ({ head }) => (
|
|
133
|
+
head ? { data: [mergedPr] } : { data: [] }
|
|
134
|
+
));
|
|
135
|
+
|
|
136
|
+
await call();
|
|
137
|
+
const callsAfterFirst = listMock.mock.calls.length;
|
|
138
|
+
|
|
139
|
+
// A non-forced poll is answered entirely from the shared open list cache
|
|
140
|
+
// plus the remembered history — no extra GitHub call.
|
|
141
|
+
const { open, historical } = await call({ force: false });
|
|
142
|
+
|
|
143
|
+
expect(open).toBeNull();
|
|
144
|
+
expect(historical?.number).toBe(12);
|
|
145
|
+
expect(listMock.mock.calls.length).toBe(callsAfterFirst);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('a found record outlives the shorter "no history" window', async () => {
|
|
149
|
+
const startedAt = Date.now();
|
|
150
|
+
listMock.mockImplementation(async ({ head }) => (
|
|
151
|
+
head ? { data: [mergedPr] } : { data: [] }
|
|
152
|
+
));
|
|
153
|
+
|
|
154
|
+
await call();
|
|
155
|
+
const callsAfterFirst = listMock.mock.calls.length;
|
|
156
|
+
|
|
157
|
+
// Past the "no history" expiry, but far short of the found-record one. The
|
|
158
|
+
// shared open list is re-fetched; the history answer is not re-queried.
|
|
159
|
+
vi.useFakeTimers();
|
|
160
|
+
vi.setSystemTime(new Date(startedAt + 30 * 60 * 1000));
|
|
161
|
+
const { historical } = await call({ force: false });
|
|
162
|
+
|
|
163
|
+
expect(historical?.number).toBe(12);
|
|
164
|
+
expect(listMock.mock.calls.length).toBe(callsAfterFirst + 1);
|
|
165
|
+
expect(listMock.mock.calls.at(-1)?.[0]?.state).toBe('open');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('re-queries a branch with no history once its shorter window passes', async () => {
|
|
169
|
+
const startedAt = Date.now();
|
|
170
|
+
listMock.mockImplementation(async () => ({ data: [] }));
|
|
171
|
+
|
|
172
|
+
await call();
|
|
173
|
+
const callsAfterFirst = listMock.mock.calls.length;
|
|
174
|
+
|
|
175
|
+
vi.useFakeTimers();
|
|
176
|
+
vi.setSystemTime(new Date(startedAt + 30 * 60 * 1000));
|
|
177
|
+
await call({ force: false });
|
|
178
|
+
|
|
179
|
+
expect(listMock.mock.calls.some((entry) => entry[0]?.state === 'all')).toBe(true);
|
|
180
|
+
expect(listMock.mock.calls.length).toBeGreaterThan(callsAfterFirst + 1);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -574,10 +574,17 @@ export function registerGitHubRoutes(app) {
|
|
|
574
574
|
return res.json({ connected: true, repo: searchRepo, branch, pr: null, checks: null, canMerge: false });
|
|
575
575
|
}
|
|
576
576
|
|
|
577
|
+
const isMerged = Boolean(prData.merged || prData.merged_at);
|
|
578
|
+
const prState = isMerged ? 'merged' : (prData.state === 'closed' ? 'closed' : 'open');
|
|
579
|
+
// A closed/merged PR is a historical record for this branch: its checks
|
|
580
|
+
// are no longer actionable and it can never be merged from here, so skip
|
|
581
|
+
// the extra GitHub calls those two fields would cost.
|
|
582
|
+
const isHistorical = prState !== 'open';
|
|
583
|
+
|
|
577
584
|
// Checks summary: prefer check-runs (Actions), fallback to classic statuses.
|
|
578
585
|
let checks = null;
|
|
579
586
|
const sha = prData.head?.sha;
|
|
580
|
-
if (sha) {
|
|
587
|
+
if (sha && !isHistorical) {
|
|
581
588
|
try {
|
|
582
589
|
const runs = await octokit.rest.checks.listForRef({
|
|
583
590
|
owner: searchRepo.owner,
|
|
@@ -610,38 +617,37 @@ export function registerGitHubRoutes(app) {
|
|
|
610
617
|
|
|
611
618
|
// Permission check (best-effort)
|
|
612
619
|
let canMerge = false;
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
if (!
|
|
620
|
-
|
|
621
|
-
.
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
620
|
+
if (!isHistorical) {
|
|
621
|
+
try {
|
|
622
|
+
const auth = getGitHubAuth();
|
|
623
|
+
// gh-CLI tokens have no persisted user record; resolve the login from
|
|
624
|
+
// the API once (memoized) so permissions still resolve for them.
|
|
625
|
+
let username = auth?.user?.login;
|
|
626
|
+
if (!username) {
|
|
627
|
+
if (!resolvedAuthLoginPromise) {
|
|
628
|
+
resolvedAuthLoginPromise = octokit.rest.users.getAuthenticated()
|
|
629
|
+
.then((resp) => resp?.data?.login || null)
|
|
630
|
+
.catch(() => {
|
|
631
|
+
resolvedAuthLoginPromise = null;
|
|
632
|
+
return null;
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
username = await resolvedAuthLoginPromise;
|
|
626
636
|
}
|
|
627
|
-
username
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
+
if (username) {
|
|
638
|
+
const perm = await octokit.rest.repos.getCollaboratorPermissionLevel({
|
|
639
|
+
owner: searchRepo.owner,
|
|
640
|
+
repo: searchRepo.repo,
|
|
641
|
+
username,
|
|
642
|
+
});
|
|
643
|
+
const level = perm?.data?.permission;
|
|
644
|
+
canMerge = level === 'admin' || level === 'maintain' || level === 'write';
|
|
645
|
+
}
|
|
646
|
+
} catch {
|
|
647
|
+
canMerge = false;
|
|
637
648
|
}
|
|
638
|
-
} catch {
|
|
639
|
-
canMerge = false;
|
|
640
649
|
}
|
|
641
650
|
|
|
642
|
-
const isMerged = Boolean(prData.merged || prData.merged_at);
|
|
643
|
-
const mergedState = isMerged ? 'merged' : (prData.state === 'closed' ? 'closed' : 'open');
|
|
644
|
-
|
|
645
651
|
return res.json({
|
|
646
652
|
connected: true,
|
|
647
653
|
repo: searchRepo,
|
|
@@ -651,7 +657,7 @@ export function registerGitHubRoutes(app) {
|
|
|
651
657
|
title: prData.title,
|
|
652
658
|
body: prData.body || '',
|
|
653
659
|
url: prData.html_url,
|
|
654
|
-
state:
|
|
660
|
+
state: prState,
|
|
655
661
|
draft: Boolean(prData.draft),
|
|
656
662
|
base: prData.base?.ref,
|
|
657
663
|
head: prData.head?.ref,
|
|
@@ -27,9 +27,8 @@ export const createNotificationTemplateRuntime = (deps) => {
|
|
|
27
27
|
|
|
28
28
|
const formatProjectLabel = (label) => {
|
|
29
29
|
if (!label || typeof label !== 'string') return '';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
30
|
+
// Folder names are shown exactly as they are on disk — no title-casing.
|
|
31
|
+
return label.trim();
|
|
33
32
|
};
|
|
34
33
|
|
|
35
34
|
const resolveNotificationTemplate = (template, variables) => {
|