@kabmo-labs/kabmo 0.11.1 → 0.12.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 +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Turning one filter into each host's own spelling.
|
|
8
|
+
*
|
|
9
|
+
* Four hosts, four grammars for the same three questions, and every one of them
|
|
10
|
+
* has a quoting rule that fails silently when it is wrong:
|
|
11
|
+
*
|
|
12
|
+
* - **GitHub** answers a search endpoint whose `q` is a space-separated
|
|
13
|
+
* qualifier list. A value containing a space MUST be quoted (`label:"good
|
|
14
|
+
* first issue"`), or the search reads the second word as another qualifier and
|
|
15
|
+
* returns nothing — a filter that looks applied and matches zero rows.
|
|
16
|
+
* - **GitLab** takes real parameters (`scope=assigned_to_me`, `labels`, `search`)
|
|
17
|
+
* and its own state word (`opened`), which `remote.ts`'s adapter already
|
|
18
|
+
* translates.
|
|
19
|
+
* - **Gitea** also takes parameters, but spells the collection split as
|
|
20
|
+
* `type=issues|pulls` on ONE endpoint rather than two.
|
|
21
|
+
* - **Bitbucket** has a query language (BBQL) and no parameter for labels.
|
|
22
|
+
*
|
|
23
|
+
* So the functions here are pure and per host: the adapter asks for its own
|
|
24
|
+
* spelling, and the quoting rule lives beside the test that pins it rather than
|
|
25
|
+
* inside a template string in the middle of a fetch.
|
|
26
|
+
*
|
|
27
|
+
* Everything is escaped for its grammar, including the free-text field, which is
|
|
28
|
+
* the user's own typing: a `"` in it would otherwise close a quoted qualifier
|
|
29
|
+
* and turn the rest of the line into search syntax.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type { ForgeFilter, ForgeSection } from '../protocol';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A value for a quoted qualifier: inner quotes and backslashes escaped.
|
|
36
|
+
*
|
|
37
|
+
* GitHub's search does not document an escape, so the safe transformation is to
|
|
38
|
+
* drop the quote character rather than emit `\"` (which it does not honour).
|
|
39
|
+
* A label containing a quote is pathological; a filter that returns everything
|
|
40
|
+
* is not an acceptable answer to it.
|
|
41
|
+
*/
|
|
42
|
+
export function quoted(value: string): string {
|
|
43
|
+
return `"${value.replace(/["\\]/g, '')}"`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A bare qualifier value: whitespace collapsed, so one field cannot add another qualifier. */
|
|
47
|
+
export function bare(value: string): string {
|
|
48
|
+
return value.trim().replace(/\s+/g, ' ');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The `q` for a GitHub search read. */
|
|
52
|
+
export function githubSearch(slug: string, section: ForgeSection, filter: ForgeFilter): string {
|
|
53
|
+
const parts = [`repo:${slug}`, section === 'pulls' ? 'is:pr' : 'is:issue'];
|
|
54
|
+
if (filter.state !== 'all') parts.push(`state:${filter.state}`);
|
|
55
|
+
if (filter.mine) parts.push('assignee:@me');
|
|
56
|
+
const label = bare(filter.label);
|
|
57
|
+
// A space needs quoting or the second word becomes another qualifier; a QUOTE
|
|
58
|
+
// needs it too, or the stripped character leaves an unbalanced value that the
|
|
59
|
+
// host reads as an unterminated string and answers with nothing.
|
|
60
|
+
if (label) parts.push(`label:${/[\s"]/.test(label) ? quoted(label) : label}`);
|
|
61
|
+
const query = bare(filter.query);
|
|
62
|
+
if (query) parts.push(query);
|
|
63
|
+
return parts.join(' ');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The parameters for a GitLab collection read.
|
|
68
|
+
*
|
|
69
|
+
* `scope=assigned_to_me` is the only spelling of "mine" GitLab accepts, and it is
|
|
70
|
+
* mutually exclusive with `assignee_username` — sending both is a 400 rather
|
|
71
|
+
* than a filter, which is why this returns one or the other.
|
|
72
|
+
*/
|
|
73
|
+
export function gitlabParams(section: ForgeSection, filter: ForgeFilter): Record<string, string> {
|
|
74
|
+
const params: Record<string, string> = {};
|
|
75
|
+
if (section !== 'releases') {
|
|
76
|
+
if (filter.state === 'open') params.state = 'opened';
|
|
77
|
+
else if (filter.state === 'closed') params.state = 'closed';
|
|
78
|
+
if (filter.mine) params.scope = 'assigned_to_me';
|
|
79
|
+
const label = bare(filter.label);
|
|
80
|
+
if (label) params.labels = label;
|
|
81
|
+
const query = bare(filter.query);
|
|
82
|
+
if (query) params.search = query;
|
|
83
|
+
}
|
|
84
|
+
return params;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The parameters for a Gitea collection read.
|
|
89
|
+
*
|
|
90
|
+
* Gitea puts issues and pull requests on ONE endpoint and splits them with
|
|
91
|
+
* `type`, so the section decides a parameter rather than a path. `assigned=true`
|
|
92
|
+
* is its spelling of "mine".
|
|
93
|
+
*/
|
|
94
|
+
export function giteaParams(section: ForgeSection, filter: ForgeFilter): Record<string, string> {
|
|
95
|
+
const params: Record<string, string> = {};
|
|
96
|
+
if (section === 'issues' || section === 'pulls') {
|
|
97
|
+
params.type = section === 'pulls' ? 'pulls' : 'issues';
|
|
98
|
+
params.state = filter.state;
|
|
99
|
+
if (filter.mine) params.assigned = 'true';
|
|
100
|
+
const label = bare(filter.label);
|
|
101
|
+
if (label) params.labels = label;
|
|
102
|
+
const query = bare(filter.query);
|
|
103
|
+
if (query) params.q = query;
|
|
104
|
+
}
|
|
105
|
+
return params;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The BBQL expression for a Bitbucket read.
|
|
110
|
+
*
|
|
111
|
+
* Bitbucket has no `labels` parameter, so a label filter becomes a query clause —
|
|
112
|
+
* and its `state` vocabulary is `OPEN`/`MERGED`/`DECLINED`/`SUPERSEDED`, where
|
|
113
|
+
* "closed" is three different words. Rather than guess which one the reader
|
|
114
|
+
* meant, a `closed` filter is sent as the three closed states OR'd together,
|
|
115
|
+
* which is what the host's own UI means by closed.
|
|
116
|
+
*/
|
|
117
|
+
export function bitbucketQuery(section: ForgeSection, filter: ForgeFilter): string {
|
|
118
|
+
const clauses: string[] = [];
|
|
119
|
+
if (section === 'pulls') {
|
|
120
|
+
if (filter.state === 'open') clauses.push('state="OPEN"');
|
|
121
|
+
else if (filter.state === 'closed') clauses.push('(state="MERGED" OR state="DECLINED" OR state="SUPERSEDED")');
|
|
122
|
+
} else if (section === 'issues') {
|
|
123
|
+
if (filter.state === 'open') clauses.push('state="new" OR state="open"');
|
|
124
|
+
else if (filter.state === 'closed') {
|
|
125
|
+
clauses.push('(state="closed" OR state="resolved" OR state="invalid" OR state="duplicate" OR state="wontfix")');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const label = bare(filter.label);
|
|
129
|
+
if (label) clauses.push(`labels ~ ${quoted(label)}`);
|
|
130
|
+
const query = bare(filter.query);
|
|
131
|
+
if (query) clauses.push(`title ~ ${quoted(query)}`);
|
|
132
|
+
return clauses.join(' AND ');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Whether a filter would change what a read returns. */
|
|
136
|
+
export function filtersAnything(filter: ForgeFilter): boolean {
|
|
137
|
+
return filter.state !== 'open' || filter.mine || bare(filter.label) !== '' || bare(filter.query) !== '';
|
|
138
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gitea / Forgejo and Bitbucket, over recorded bodies.
|
|
8
|
+
*
|
|
9
|
+
* Two hosts in one file because they share the tests that matter most here —
|
|
10
|
+
* both answer a pull request's diff as TEXT, so both go through the shared
|
|
11
|
+
* parser, and a regression in it would otherwise be found twice.
|
|
12
|
+
*
|
|
13
|
+
* The cases are the ones that differ from the two big hosts:
|
|
14
|
+
*
|
|
15
|
+
* - **Gitea puts issues and pull requests on ONE endpoint**, split by `type`,
|
|
16
|
+
* and a pull request appears in the issues response as well.
|
|
17
|
+
* - **Gitea's `state=all` is spelled `all`** — sending `open,closed` matches
|
|
18
|
+
* nothing.
|
|
19
|
+
* - **Bitbucket wraps every collection in `{values, next, size}`**, never a bare
|
|
20
|
+
* array, and spells its states in uppercase.
|
|
21
|
+
* - **Bitbucket has no `draft` flag**, and a declined pull request is `closed`
|
|
22
|
+
* rather than `merged`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { describe, expect, test } from 'bun:test';
|
|
26
|
+
|
|
27
|
+
import { bitbucketState, detailBitbucket, listBitbucket } from './bitbucket';
|
|
28
|
+
import { detailGitea, giteaPullState, listGitea } from './gitea';
|
|
29
|
+
import { host } from './test-host';
|
|
30
|
+
import { hostContext, openFilter } from './test-context';
|
|
31
|
+
|
|
32
|
+
const gitea = (fetchImpl: typeof fetch, overrides: Parameters<typeof hostContext>[2] = {}) =>
|
|
33
|
+
hostContext('gitea', fetchImpl, overrides);
|
|
34
|
+
const bitbucket = (fetchImpl: typeof fetch, overrides: Parameters<typeof hostContext>[2] = {}) =>
|
|
35
|
+
hostContext('bitbucket', fetchImpl, overrides);
|
|
36
|
+
|
|
37
|
+
describe('listGitea', () => {
|
|
38
|
+
test('the section becomes a type parameter on ONE endpoint', async () => {
|
|
39
|
+
const { asked, fetchImpl } = host({});
|
|
40
|
+
await listGitea(gitea(fetchImpl));
|
|
41
|
+
const issueReads = asked.filter((url) => url.includes('/repos/team/app/issues'));
|
|
42
|
+
expect(issueReads.some((url) => url.includes('type=issues'))).toBe(true);
|
|
43
|
+
expect(issueReads.some((url) => url.includes('type=pulls'))).toBe(true);
|
|
44
|
+
// There is no separate `/pulls` collection for listing.
|
|
45
|
+
expect(asked.some((url) => url.includes('/repos/team/app/pulls?'))).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('a pull request in the issues response is not an issue', async () => {
|
|
49
|
+
const { fetchImpl } = host({
|
|
50
|
+
'/api/v1/repos/team/app/issues': [
|
|
51
|
+
{ number: 1, title: 'Real issue', state: 'open', user: { login: 'ana' } },
|
|
52
|
+
{ number: 2, title: 'A PR', state: 'open', user: { login: 'bo' }, pull_request: { merged: false } },
|
|
53
|
+
],
|
|
54
|
+
'/api/v1/repos/team/app/releases': [],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const list = await listGitea(gitea(fetchImpl));
|
|
58
|
+
// Both sections read the same endpoint, so the filter is what separates them.
|
|
59
|
+
expect(list.sections.issues.items.map((item) => item.number)).toEqual([1]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('the filter rides as parameters, and mine is assigned=true', async () => {
|
|
63
|
+
const { asked, fetchImpl } = host({});
|
|
64
|
+
await listGitea(gitea(fetchImpl, { filter: { ...openFilter(), mine: true, label: 'bug', query: 'crash' } }));
|
|
65
|
+
const read = asked.find((url) => url.includes('type=issues'));
|
|
66
|
+
expect(read).toContain('assigned=true');
|
|
67
|
+
expect(read).toContain('labels=bug');
|
|
68
|
+
expect(read).toContain('q=crash');
|
|
69
|
+
expect(read).toContain('state=open');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a repository with no releases answers 404, which is an empty section', async () => {
|
|
73
|
+
const { fetchImpl } = host({
|
|
74
|
+
'/api/v1/repos/team/app/issues': [{ number: 1, title: 'ok', state: 'open' }],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const list = await listGitea(gitea(fetchImpl));
|
|
78
|
+
expect(list.sections.releases.items).toEqual([]);
|
|
79
|
+
expect(list.notes).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('giteaPullState', () => {
|
|
84
|
+
test('merged is on the pull object or nested in the issue row', () => {
|
|
85
|
+
expect(giteaPullState({ state: 'closed', merged: true })).toBe('merged');
|
|
86
|
+
expect(giteaPullState({ state: 'closed', pull_request: { merged_at: '2026-01-01' } })).toBe('merged');
|
|
87
|
+
expect(giteaPullState({ state: 'closed' })).toBe('closed');
|
|
88
|
+
expect(giteaPullState({ state: 'open' })).toBe('open');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('detailGitea', () => {
|
|
93
|
+
test('the files come from the diff TEXT, through the shared parser', async () => {
|
|
94
|
+
const diff = `diff --git a/src/a.ts b/src/a.ts
|
|
95
|
+
--- a/src/a.ts
|
|
96
|
+
+++ b/src/a.ts
|
|
97
|
+
@@ -1,1 +1,2 @@
|
|
98
|
+
one
|
|
99
|
+
+two
|
|
100
|
+
`;
|
|
101
|
+
const { fetchImpl } = host({
|
|
102
|
+
'/api/v1/repos/team/app/pulls/4': {
|
|
103
|
+
number: 4,
|
|
104
|
+
title: 'A change',
|
|
105
|
+
state: 'open',
|
|
106
|
+
body: 'Body',
|
|
107
|
+
head: { ref: 'feat' },
|
|
108
|
+
base: { ref: 'main' },
|
|
109
|
+
},
|
|
110
|
+
'/api/v1/repos/team/app/issues/4/comments': [
|
|
111
|
+
{ id: 1, user: { login: 'ana' }, body: 'Nice', created_at: '2026-01-01' },
|
|
112
|
+
],
|
|
113
|
+
'/api/v1/repos/team/app/pulls/4/commits': [
|
|
114
|
+
{ sha: 'abc', commit: { message: 'One commit\n\nbody', author: { name: 'Ana', date: '2026-01-01' } } },
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
// The diff route answers TEXT, and the shared fake host sends JSON — so it is
|
|
118
|
+
// stubbed here, which is also what proves the adapter handles a string.
|
|
119
|
+
const withDiff = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
120
|
+
if (String(input).endsWith('.diff')) return new Response(diff, { status: 200 });
|
|
121
|
+
return fetchImpl(input, init);
|
|
122
|
+
}) as typeof fetch;
|
|
123
|
+
|
|
124
|
+
const detail = await detailGitea(gitea(withDiff), 'pulls', '4');
|
|
125
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
126
|
+
|
|
127
|
+
expect(detail.files.map((file) => [file.path, file.additions])).toEqual([['src/a.ts', 1]]);
|
|
128
|
+
expect(detail.facts).toContainEqual({ label: 'branch', value: 'main ← feat' });
|
|
129
|
+
expect(detail.commits.map((commit) => commit.message)).toEqual(['One commit']);
|
|
130
|
+
expect(detail.capabilities.review).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('bitbucketState', () => {
|
|
135
|
+
test('three closed words collapse to closed; merged is its own state', () => {
|
|
136
|
+
expect(bitbucketState('MERGED')).toBe('merged');
|
|
137
|
+
expect(bitbucketState('DECLINED')).toBe('closed');
|
|
138
|
+
expect(bitbucketState('SUPERSEDED')).toBe('closed');
|
|
139
|
+
expect(bitbucketState('OPEN')).toBe('open');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('listBitbucket', () => {
|
|
144
|
+
test('every collection is a paged envelope, never a bare array', async () => {
|
|
145
|
+
const { fetchImpl } = host({
|
|
146
|
+
'/2.0/repositories/team/app/pullrequests': {
|
|
147
|
+
size: 2,
|
|
148
|
+
values: [
|
|
149
|
+
{ id: 1, title: 'Open one', state: 'OPEN', author: { nickname: 'ana' }, links: { html: { href: 'u1' } } },
|
|
150
|
+
{ id: 2, title: 'Declined', state: 'DECLINED', author: { nickname: 'bo' }, links: { html: { href: 'u2' } } },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
'/2.0/repositories/team/app/issues': {
|
|
154
|
+
size: 1,
|
|
155
|
+
values: [{ id: 9, title: 'An issue', state: 'new', reporter: { nickname: 'ana' }, links: { html: { href: 'u9' } } }],
|
|
156
|
+
},
|
|
157
|
+
'/2.0/repositories/team/app/refs/tags': { size: 0, values: [] },
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const list = await listBitbucket(bitbucket(fetchImpl));
|
|
161
|
+
expect(list.sections.pulls.items.map((item) => item.state)).toEqual(['open', 'closed']);
|
|
162
|
+
expect(list.sections.issues.items[0].state).toBe('open');
|
|
163
|
+
// The envelope's own `size` is the total, which is what makes a truncation
|
|
164
|
+
// report honest.
|
|
165
|
+
expect(list.sections.pulls.total).toBe(2);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('the filter becomes a BBQL query, because there is no parameter for it', async () => {
|
|
169
|
+
const { asked, fetchImpl } = host({});
|
|
170
|
+
await listBitbucket(bitbucket(fetchImpl, { filter: { ...openFilter(), state: 'closed', label: 'bug' } }));
|
|
171
|
+
const read = asked.find((url) => url.includes('/pullrequests'));
|
|
172
|
+
// `URLSearchParams` encodes a space as `+`, so the query is decoded the way
|
|
173
|
+
// a reader of the URL would decode it.
|
|
174
|
+
const query = decodeURIComponent((read ?? '').replace(/\+/g, ' '));
|
|
175
|
+
expect(query).toContain('state="MERGED"');
|
|
176
|
+
expect(query).toContain('labels ~ "bug"');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('a nested slug is refused by name rather than read as another project', async () => {
|
|
180
|
+
const { fetchImpl } = host({});
|
|
181
|
+
const list = await listBitbucket(bitbucket(fetchImpl, { slug: 'a/b/c' }));
|
|
182
|
+
expect(list.sections.issues.items).toEqual([]);
|
|
183
|
+
expect(list.notes.join(' ')).toContain('workspace/repo');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('detailBitbucket', () => {
|
|
188
|
+
test('the description is content.raw, and the diff is text', async () => {
|
|
189
|
+
const diff = `diff --git a/a.ts b/a.ts
|
|
190
|
+
--- a/a.ts
|
|
191
|
+
+++ b/a.ts
|
|
192
|
+
@@ -1 +1,2 @@
|
|
193
|
+
-x
|
|
194
|
+
+y
|
|
195
|
+
+z
|
|
196
|
+
`;
|
|
197
|
+
const { fetchImpl } = host({
|
|
198
|
+
'/2.0/repositories/team/app/pullrequests/5': {
|
|
199
|
+
id: 5,
|
|
200
|
+
title: 'A change',
|
|
201
|
+
state: 'OPEN',
|
|
202
|
+
content: { raw: 'Body text' },
|
|
203
|
+
source: { branch: { name: 'feat' } },
|
|
204
|
+
destination: { branch: { name: 'main' } },
|
|
205
|
+
reviewers: [{ nickname: 'a' }, { nickname: 'b' }],
|
|
206
|
+
links: { html: { href: 'u5' } },
|
|
207
|
+
},
|
|
208
|
+
'/2.0/repositories/team/app/pullrequests/5/comments': {
|
|
209
|
+
values: [
|
|
210
|
+
{ id: 1, user: { nickname: 'ana' }, content: { raw: 'Nice' }, created_on: '2026-01-01' },
|
|
211
|
+
{ id: 2, user: { nickname: 'x' }, content: { raw: 'gone' }, deleted: true },
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
'/2.0/repositories/team/app/pullrequests/5/commits': {
|
|
215
|
+
values: [{ hash: 'abc', message: 'One commit', author: { raw: 'Ana <ana@example.com>' }, date: '2026-01-01' }],
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
const withDiff = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
219
|
+
if (String(input).endsWith('/diff')) return new Response(diff, { status: 200 });
|
|
220
|
+
return fetchImpl(input, init);
|
|
221
|
+
}) as typeof fetch;
|
|
222
|
+
|
|
223
|
+
const detail = await detailBitbucket(bitbucket(withDiff), 'pulls', '5');
|
|
224
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
225
|
+
|
|
226
|
+
expect(detail.body).toBe('Body text');
|
|
227
|
+
expect(detail.facts).toContainEqual({ label: 'branch', value: 'main ← feat' });
|
|
228
|
+
expect(detail.facts).toContainEqual({ label: 'reviewers', value: '2' });
|
|
229
|
+
// A deleted comment keeps its row in the envelope and is not a reply.
|
|
230
|
+
expect(detail.comments.map((comment) => comment.body)).toEqual(['Nice']);
|
|
231
|
+
expect(detail.files[0]).toMatchObject({ path: 'a.ts', additions: 2, deletions: 1 });
|
|
232
|
+
expect(detail.commits[0].author).toBe('Ana');
|
|
233
|
+
expect(detail.capabilities.review).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gitea / Forgejo's API (v1).
|
|
8
|
+
*
|
|
9
|
+
* The one host that puts issues and pull requests on a SINGLE endpoint, split by
|
|
10
|
+
* `type=issues|pulls` — which is why `filters.ts` turns the section into a
|
|
11
|
+
* parameter here rather than a path. It is also the host whose diff is served as
|
|
12
|
+
* TEXT (`/pulls/:index.diff`), so its file list comes from `diff.ts` rather than
|
|
13
|
+
* from a JSON collection.
|
|
14
|
+
*
|
|
15
|
+
* Four facts were checked against a running instance rather than assumed:
|
|
16
|
+
*
|
|
17
|
+
* - **`state` accepts `open`, `closed` and `all`**, and `all` is spelled that
|
|
18
|
+
* way — sending `state=open,closed` silently matches nothing.
|
|
19
|
+
* - **A pull request IS an issue with `pull_request` set**, so the issues read
|
|
20
|
+
* must filter exactly as GitHub's does.
|
|
21
|
+
* - **The number field is `number` for both**, not `index`; `index` appears only
|
|
22
|
+
* inside `pull_request` on some builds.
|
|
23
|
+
* - **Comments live at `/issues/:index/comments`** even for a pull request,
|
|
24
|
+
* because a pull request is an issue — the `/pulls/:index/comments` route
|
|
25
|
+
* answers only the REVIEW comments, which is a different collection.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ForgeDetail, ForgeCommit, ForgeFile, ForgeItem, ForgeItemState, ForgeList, ForgeSection } from '../protocol';
|
|
29
|
+
import { capabilitiesFor } from './capabilities';
|
|
30
|
+
import { ciBadge } from './ci';
|
|
31
|
+
import { get, getTextWith, joinUrl, pageSize, withParams, type ForgeContext } from './context';
|
|
32
|
+
import { parseUnifiedDiff } from './diff';
|
|
33
|
+
import { giteaParams } from './filters';
|
|
34
|
+
import { asRecord, count, flag, labelsOf, listAt, recordAt, text, textAt } from './map';
|
|
35
|
+
|
|
36
|
+
function issueItem(raw: unknown): ForgeItem | null {
|
|
37
|
+
const record = asRecord(raw);
|
|
38
|
+
if (!record) return null;
|
|
39
|
+
if (record.pull_request) return null;
|
|
40
|
+
const number = count(record.number, 0);
|
|
41
|
+
if (!number) return null;
|
|
42
|
+
return {
|
|
43
|
+
id: String(number),
|
|
44
|
+
number,
|
|
45
|
+
title: text(record.title, '(untitled)'),
|
|
46
|
+
state: text(record.state) === 'closed' ? 'closed' : 'open',
|
|
47
|
+
author: textAt(record.user, 'login', 'unknown'),
|
|
48
|
+
updatedAt: text(record.updated_at),
|
|
49
|
+
url: text(record.html_url),
|
|
50
|
+
labels: labelsOf(record.labels),
|
|
51
|
+
comments: count(record.comments, 0),
|
|
52
|
+
tag: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A pull request's state.
|
|
58
|
+
*
|
|
59
|
+
* Gitea reports `merged` only through `merged_at`/`merged` on the pull object,
|
|
60
|
+
* and a pull request row from the ISSUES endpoint carries `pull_request.merged_at`
|
|
61
|
+
* instead — the same split GitHub has, and the same trap.
|
|
62
|
+
*/
|
|
63
|
+
export function giteaPullState(record: Record<string, unknown>): ForgeItemState {
|
|
64
|
+
const nested = recordAt(record, 'pull_request');
|
|
65
|
+
if (record.merged_at || nested?.merged_at || flag(record.merged) || flag(nested?.merged)) return 'merged';
|
|
66
|
+
if (text(record.state) === 'closed') return 'closed';
|
|
67
|
+
return 'open';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function pullItem(raw: unknown): ForgeItem | null {
|
|
71
|
+
const record = asRecord(raw);
|
|
72
|
+
if (!record) return null;
|
|
73
|
+
const number = count(record.number, 0) || count(record.index, 0);
|
|
74
|
+
if (!number) return null;
|
|
75
|
+
return {
|
|
76
|
+
id: String(number),
|
|
77
|
+
number,
|
|
78
|
+
title: text(record.title, '(untitled)'),
|
|
79
|
+
state: giteaPullState(record),
|
|
80
|
+
author: textAt(record.user, 'login', 'unknown'),
|
|
81
|
+
updatedAt: text(record.updated_at),
|
|
82
|
+
url: text(record.html_url),
|
|
83
|
+
labels: labelsOf(record.labels),
|
|
84
|
+
comments: count(record.comments, 0),
|
|
85
|
+
tag: null,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function releaseItem(raw: unknown): ForgeItem | null {
|
|
90
|
+
const record = asRecord(raw);
|
|
91
|
+
if (!record) return null;
|
|
92
|
+
const tag = text(record.tag_name);
|
|
93
|
+
if (!tag) return null;
|
|
94
|
+
return {
|
|
95
|
+
id: tag,
|
|
96
|
+
number: null,
|
|
97
|
+
title: text(record.name) || tag,
|
|
98
|
+
state: flag(record.prerelease) ? 'prerelease' : 'published',
|
|
99
|
+
author: textAt(record.author, 'login', 'unknown'),
|
|
100
|
+
updatedAt: text(record.published_at) || text(record.created_at),
|
|
101
|
+
url: text(record.html_url),
|
|
102
|
+
labels: [],
|
|
103
|
+
comments: 0,
|
|
104
|
+
tag,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function readSection(
|
|
109
|
+
context: ForgeContext,
|
|
110
|
+
section: ForgeSection,
|
|
111
|
+
notes: string[],
|
|
112
|
+
): Promise<{ items: ForgeItem[]; truncated: boolean; total: number | null }> {
|
|
113
|
+
const perPage = pageSize(context);
|
|
114
|
+
const collection = section === 'releases' ? 'releases' : 'issues';
|
|
115
|
+
const params: Record<string, string> = {
|
|
116
|
+
limit: String(perPage),
|
|
117
|
+
...(section === 'releases' ? {} : giteaParams(section, context.filter)),
|
|
118
|
+
};
|
|
119
|
+
const url = withParams(joinUrl(context.apiBase, `/repos/${context.slug}/${collection}`), params);
|
|
120
|
+
|
|
121
|
+
const result = await get(context, url);
|
|
122
|
+
if (!result.ok) {
|
|
123
|
+
if (section === 'releases' && result.status === 404) return { items: [], truncated: false, total: null };
|
|
124
|
+
notes.push(`${section}: ${result.message}`);
|
|
125
|
+
return { items: [], truncated: false, total: null };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const mapper = section === 'issues' ? issueItem : section === 'pulls' ? pullItem : releaseItem;
|
|
129
|
+
// Gitea answers a bare array here; a future build that wraps it in
|
|
130
|
+
// `{data: [...]}` is read through the same path.
|
|
131
|
+
const rows = listAt(result.value).length > 0 ? listAt(result.value) : listAt(recordAt(result.value, 'data'));
|
|
132
|
+
const items = rows.map(mapper).filter((item): item is ForgeItem => item !== null);
|
|
133
|
+
return { items, truncated: rows.length >= perPage, total: null };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function listGitea(context: ForgeContext): Promise<ForgeList> {
|
|
137
|
+
const notes: string[] = [];
|
|
138
|
+
if (!context.token) {
|
|
139
|
+
notes.push(
|
|
140
|
+
'Reading anonymously: public repositories only. Set GITEA_TOKEN in the server environment to read a private one.',
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const [issues, pulls, releases] = await Promise.all([
|
|
145
|
+
readSection(context, 'issues', notes),
|
|
146
|
+
readSection(context, 'pulls', notes),
|
|
147
|
+
readSection(context, 'releases', notes),
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
provider: 'gitea',
|
|
152
|
+
host: context.host,
|
|
153
|
+
slug: context.slug,
|
|
154
|
+
webUrl: context.webUrl,
|
|
155
|
+
filter: context.filter,
|
|
156
|
+
sections: { issues, pulls, releases },
|
|
157
|
+
notes,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function itemUrl(context: ForgeContext, section: ForgeSection, id: string): string {
|
|
162
|
+
const base = `/repos/${context.slug}`;
|
|
163
|
+
if (section === 'issues') return joinUrl(context.apiBase, `${base}/issues/${encodeURIComponent(id)}`);
|
|
164
|
+
if (section === 'pulls') return joinUrl(context.apiBase, `${base}/pulls/${encodeURIComponent(id)}`);
|
|
165
|
+
return joinUrl(context.apiBase, `${base}/releases/tags/${encodeURIComponent(id)}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The pull request's changed files, parsed out of its `.diff` text. */
|
|
169
|
+
async function readFiles(context: ForgeContext, id: string, notes: string[]): Promise<ForgeFile[]> {
|
|
170
|
+
const url = joinUrl(context.apiBase, `/repos/${context.slug}/pulls/${encodeURIComponent(id)}.diff`);
|
|
171
|
+
const result = await getTextWith(context, url);
|
|
172
|
+
if (!result.ok) {
|
|
173
|
+
notes.push(`files: ${result.message}`);
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
return typeof result.value === 'string' ? parseUnifiedDiff(result.value) : [];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function readCommits(context: ForgeContext, id: string, notes: string[]): Promise<ForgeCommit[]> {
|
|
180
|
+
const url = joinUrl(context.apiBase, `/repos/${context.slug}/pulls/${encodeURIComponent(id)}/commits`);
|
|
181
|
+
const result = await get(context, url);
|
|
182
|
+
if (!result.ok) {
|
|
183
|
+
notes.push(`commits: ${result.message}`);
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
return listAt(result.value).flatMap((raw) => {
|
|
187
|
+
const entry = asRecord(raw);
|
|
188
|
+
if (!entry) return [];
|
|
189
|
+
const sha = text(entry.sha);
|
|
190
|
+
if (!sha) return [];
|
|
191
|
+
const commit = recordAt(entry, 'commit') ?? {};
|
|
192
|
+
return [
|
|
193
|
+
{
|
|
194
|
+
sha,
|
|
195
|
+
message: text(commit.message).split('\n')[0],
|
|
196
|
+
author: textAt(commit.author, 'name', 'unknown'),
|
|
197
|
+
at: textAt(commit.author, 'date'),
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function readComments(
|
|
204
|
+
context: ForgeContext,
|
|
205
|
+
id: string,
|
|
206
|
+
notes: string[],
|
|
207
|
+
): Promise<ForgeDetail['comments']> {
|
|
208
|
+
const url = withParams(joinUrl(context.apiBase, `/repos/${context.slug}/issues/${encodeURIComponent(id)}/comments`), {
|
|
209
|
+
limit: '100',
|
|
210
|
+
});
|
|
211
|
+
const result = await get(context, url);
|
|
212
|
+
if (!result.ok) {
|
|
213
|
+
notes.push(`comments: ${result.message}`);
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
return listAt(result.value).flatMap((raw) => {
|
|
217
|
+
const entry = asRecord(raw);
|
|
218
|
+
if (!entry) return [];
|
|
219
|
+
const author = textAt(entry.user, 'login', 'unknown');
|
|
220
|
+
return [
|
|
221
|
+
{
|
|
222
|
+
id: String(count(entry.id, 0)),
|
|
223
|
+
author,
|
|
224
|
+
body: text(entry.body),
|
|
225
|
+
createdAt: text(entry.created_at),
|
|
226
|
+
url: text(entry.html_url) || null,
|
|
227
|
+
system: false,
|
|
228
|
+
bot: /\[bot\]$/.test(author),
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export async function detailGitea(
|
|
235
|
+
context: ForgeContext,
|
|
236
|
+
section: ForgeSection,
|
|
237
|
+
id: string,
|
|
238
|
+
): Promise<ForgeDetail | { error: string }> {
|
|
239
|
+
const notes: string[] = [];
|
|
240
|
+
const result = await get(context, itemUrl(context, section, id));
|
|
241
|
+
if (!result.ok) return { error: result.message };
|
|
242
|
+
|
|
243
|
+
const record = asRecord(result.value) ?? {};
|
|
244
|
+
const mapper = section === 'issues' ? issueItem : section === 'pulls' ? pullItem : releaseItem;
|
|
245
|
+
const item = mapper(record);
|
|
246
|
+
if (!item) return { error: 'The host returned an item this plugin could not read.' };
|
|
247
|
+
|
|
248
|
+
const facts: Array<{ label: string; value: string }> = [];
|
|
249
|
+
if (section === 'pulls') {
|
|
250
|
+
const head = textAt(record.head, 'ref');
|
|
251
|
+
const base = textAt(record.base, 'ref');
|
|
252
|
+
if (head || base) facts.push({ label: 'branch', value: `${base || '?'} ← ${head || '?'}` });
|
|
253
|
+
const merged = flag(record.merged);
|
|
254
|
+
if (merged) facts.push({ label: 'merged', value: 'yes' });
|
|
255
|
+
else if (record.mergeable === false) facts.push({ label: 'mergeable', value: 'conflicts' });
|
|
256
|
+
}
|
|
257
|
+
if (section === 'releases') {
|
|
258
|
+
const tag = text(record.tag_name);
|
|
259
|
+
if (tag) facts.push({ label: 'tag', value: tag });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const [comments, files, commits] = await Promise.all([
|
|
263
|
+
section === 'releases' ? Promise.resolve([]) : readComments(context, id, notes),
|
|
264
|
+
section === 'pulls' ? readFiles(context, id, notes) : Promise.resolve([]),
|
|
265
|
+
section === 'pulls' ? readCommits(context, id, notes) : Promise.resolve([]),
|
|
266
|
+
]);
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
item,
|
|
270
|
+
body: text(record.body),
|
|
271
|
+
comments,
|
|
272
|
+
facts,
|
|
273
|
+
files,
|
|
274
|
+
commits,
|
|
275
|
+
// Gitea reports a commit's status per SHA and puts no badge on the pull
|
|
276
|
+
// object, so a badge would cost a second read for a value the reader can
|
|
277
|
+
// reach on the host in one click.
|
|
278
|
+
ci: null,
|
|
279
|
+
capabilities: capabilitiesFor({ provider: 'gitea', section, hasCredential: Boolean(context.token) }),
|
|
280
|
+
notes,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The CI verdict for a commit, for a caller that has the SHA.
|
|
286
|
+
*
|
|
287
|
+
* Kept for a future row-level badge rather than deleted with the other CI reads:
|
|
288
|
+
* Gitea DOES report a commit's combined status, and the only reason no badge is
|
|
289
|
+
* drawn is that the pull object carries no SHA — reaching one costs a read the
|
|
290
|
+
* panel has no other use for.
|
|
291
|
+
*/
|
|
292
|
+
export function giteaCommitCi(payload: unknown, url: string | null) {
|
|
293
|
+
const status = recordAt(payload, 'combined_status') ?? recordAt(payload, 'status');
|
|
294
|
+
const state = status ? text(status.state) : '';
|
|
295
|
+
return state ? ciBadge([state], url) : null;
|
|
296
|
+
}
|