@wascartech/devbot 0.0.0-stage → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +638 -2
- package/dist/access-grant-store.js +99 -0
- package/dist/access-grant-store.js.map +1 -0
- package/dist/access-resolve.js +11 -0
- package/dist/access-resolve.js.map +1 -0
- package/dist/access-rule-store.js +99 -0
- package/dist/access-rule-store.js.map +1 -0
- package/dist/admin/access-routes.js +73 -0
- package/dist/admin/access-routes.js.map +1 -0
- package/dist/admin/access-rule-routes.js +107 -0
- package/dist/admin/access-rule-routes.js.map +1 -0
- package/dist/admin/custom-repos-routes.js +93 -0
- package/dist/admin/custom-repos-routes.js.map +1 -0
- package/dist/admin/env-routes.js +74 -0
- package/dist/admin/env-routes.js.map +1 -0
- package/dist/admin/global-settings-routes.js +254 -0
- package/dist/admin/global-settings-routes.js.map +1 -0
- package/dist/admin/mcp-cleanup.js +12 -0
- package/dist/admin/mcp-cleanup.js.map +1 -0
- package/dist/admin/mcp-routes.js +169 -0
- package/dist/admin/mcp-routes.js.map +1 -0
- package/dist/admin/query-params.js +80 -0
- package/dist/admin/query-params.js.map +1 -0
- package/dist/admin/routes.js +150 -0
- package/dist/admin/routes.js.map +1 -0
- package/dist/admin/run-history-routes.js +44 -0
- package/dist/admin/run-history-routes.js.map +1 -0
- package/dist/admin/run-routes.js +99 -0
- package/dist/admin/run-routes.js.map +1 -0
- package/dist/admin/settings-routes.js +119 -0
- package/dist/admin/settings-routes.js.map +1 -0
- package/dist/admin/stats-routes.js +51 -0
- package/dist/admin/stats-routes.js.map +1 -0
- package/dist/admin/task-routes.js +213 -0
- package/dist/admin/task-routes.js.map +1 -0
- package/dist/admin/test-routes.js +38 -0
- package/dist/admin/test-routes.js.map +1 -0
- package/dist/admin/volume-routes.js +82 -0
- package/dist/admin/volume-routes.js.map +1 -0
- package/dist/admin/webhook-routes.js +174 -0
- package/dist/admin/webhook-routes.js.map +1 -0
- package/dist/agents.js +48 -0
- package/dist/agents.js.map +1 -0
- package/dist/assignee-value.js +6 -0
- package/dist/assignee-value.js.map +1 -0
- package/dist/attachments.js +76 -0
- package/dist/attachments.js.map +1 -0
- package/dist/auto-commands.js +88 -0
- package/dist/auto-commands.js.map +1 -0
- package/dist/auto-features.js +32 -0
- package/dist/auto-features.js.map +1 -0
- package/dist/base-branch-store.js +40 -0
- package/dist/base-branch-store.js.map +1 -0
- package/dist/base-branches.js +9 -0
- package/dist/base-branches.js.map +1 -0
- package/dist/build-workflow.js +116 -0
- package/dist/build-workflow.js.map +1 -0
- package/dist/change-request-lifecycle.js +16 -0
- package/dist/change-request-lifecycle.js.map +1 -0
- package/dist/change-request-store.js +72 -0
- package/dist/change-request-store.js.map +1 -0
- package/dist/ci-failure.js +80 -0
- package/dist/ci-failure.js.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -0
- package/dist/conflict-fix.js +178 -0
- package/dist/conflict-fix.js.map +1 -0
- package/dist/cookie.js +70 -0
- package/dist/cookie.js.map +1 -0
- package/dist/crypto-util.js +40 -0
- package/dist/crypto-util.js.map +1 -0
- package/dist/custom-repos-store.js +90 -0
- package/dist/custom-repos-store.js.map +1 -0
- package/dist/custom-repos-sync.js +118 -0
- package/dist/custom-repos-sync.js.map +1 -0
- package/dist/db.js +12 -0
- package/dist/db.js.map +1 -0
- package/dist/devbot-scripts.js +18 -0
- package/dist/devbot-scripts.js.map +1 -0
- package/dist/devcontainer.js +150 -0
- package/dist/devcontainer.js.map +1 -0
- package/dist/env-config-store.js +132 -0
- package/dist/env-config-store.js.map +1 -0
- package/dist/error-log-store.js +193 -0
- package/dist/error-log-store.js.map +1 -0
- package/dist/git.js +605 -0
- package/dist/git.js.map +1 -0
- package/dist/global-queue.js +127 -0
- package/dist/global-queue.js.map +1 -0
- package/dist/global-settings-store.js +307 -0
- package/dist/global-settings-store.js.map +1 -0
- package/dist/help.js +41 -0
- package/dist/help.js.map +1 -0
- package/dist/http-csp.js +15 -0
- package/dist/http-csp.js.map +1 -0
- package/dist/http-util.js +40 -0
- package/dist/http-util.js.map +1 -0
- package/dist/idempotency.js +50 -0
- package/dist/idempotency.js.map +1 -0
- package/dist/lifecycle.js +234 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/logger.js +33 -0
- package/dist/logger.js.map +1 -0
- package/dist/lsp-servers.js +81 -0
- package/dist/lsp-servers.js.map +1 -0
- package/dist/mcp/auth.js +62 -0
- package/dist/mcp/auth.js.map +1 -0
- package/dist/mcp/effective-mcp.js +42 -0
- package/dist/mcp/effective-mcp.js.map +1 -0
- package/dist/mcp/oauth-refresh.js +138 -0
- package/dist/mcp/oauth-refresh.js.map +1 -0
- package/dist/mcp/peer-sync.js +109 -0
- package/dist/mcp/peer-sync.js.map +1 -0
- package/dist/mcp/registry.js +54 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/runner-bridge.js +93 -0
- package/dist/mcp/runner-bridge.js.map +1 -0
- package/dist/mcp/server.js +173 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/_helpers.js +88 -0
- package/dist/mcp/tools/_helpers.js.map +1 -0
- package/dist/mcp/tools/attachments.js +117 -0
- package/dist/mcp/tools/attachments.js.map +1 -0
- package/dist/mcp/tools/cicd.js +105 -0
- package/dist/mcp/tools/cicd.js.map +1 -0
- package/dist/mcp/tools/discovery.js +34 -0
- package/dist/mcp/tools/discovery.js.map +1 -0
- package/dist/mcp/tools/issues.js +56 -0
- package/dist/mcp/tools/issues.js.map +1 -0
- package/dist/mcp/tools/merge_requests.js +67 -0
- package/dist/mcp/tools/merge_requests.js.map +1 -0
- package/dist/mcp/tools/metadata.js +127 -0
- package/dist/mcp/tools/metadata.js.map +1 -0
- package/dist/mcp/tools/peer_sync.js +43 -0
- package/dist/mcp/tools/peer_sync.js.map +1 -0
- package/dist/mcp/tools/repository.js +178 -0
- package/dist/mcp/tools/repository.js.map +1 -0
- package/dist/mcp/tools/work_tracking.js +125 -0
- package/dist/mcp/tools/work_tracking.js.map +1 -0
- package/dist/mcp/tools/workitems.js +30 -0
- package/dist/mcp/tools/workitems.js.map +1 -0
- package/dist/mcp/volume-files.js +187 -0
- package/dist/mcp/volume-files.js.map +1 -0
- package/dist/mcp-auth-store.js +134 -0
- package/dist/mcp-auth-store.js.map +1 -0
- package/dist/mcp-config-store.js +83 -0
- package/dist/mcp-config-store.js.map +1 -0
- package/dist/mention.js +512 -0
- package/dist/mention.js.map +1 -0
- package/dist/migrate.js +438 -0
- package/dist/migrate.js.map +1 -0
- package/dist/mr-assignee.js +71 -0
- package/dist/mr-assignee.js.map +1 -0
- package/dist/mr-content.js +90 -0
- package/dist/mr-content.js.map +1 -0
- package/dist/oauth-routes.js +54 -0
- package/dist/oauth-routes.js.map +1 -0
- package/dist/onboarding-allowlist.js +32 -0
- package/dist/onboarding-allowlist.js.map +1 -0
- package/dist/opencode.js +291 -0
- package/dist/opencode.js.map +1 -0
- package/dist/outbound-webhook-store.js +229 -0
- package/dist/outbound-webhook-store.js.map +1 -0
- package/dist/outbound-webhook.js +314 -0
- package/dist/outbound-webhook.js.map +1 -0
- package/dist/path-sandbox.js +200 -0
- package/dist/path-sandbox.js.map +1 -0
- package/dist/platform/git-auth.js +34 -0
- package/dist/platform/git-auth.js.map +1 -0
- package/dist/platform/gitealike/attachments.js +62 -0
- package/dist/platform/gitealike/attachments.js.map +1 -0
- package/dist/platform/gitealike/base.js +935 -0
- package/dist/platform/gitealike/base.js.map +1 -0
- package/dist/platform/gitealike/forgejo.js +16 -0
- package/dist/platform/gitealike/forgejo.js.map +1 -0
- package/dist/platform/gitealike/gitea.js +16 -0
- package/dist/platform/gitealike/gitea.js.map +1 -0
- package/dist/platform/gitealike/http.js +152 -0
- package/dist/platform/gitealike/http.js.map +1 -0
- package/dist/platform/gitealike/schemas.js +284 -0
- package/dist/platform/gitealike/schemas.js.map +1 -0
- package/dist/platform/github/attachments.js +52 -0
- package/dist/platform/github/attachments.js.map +1 -0
- package/dist/platform/github/http.js +153 -0
- package/dist/platform/github/http.js.map +1 -0
- package/dist/platform/github/index.js +936 -0
- package/dist/platform/github/index.js.map +1 -0
- package/dist/platform/github/schemas.js +308 -0
- package/dist/platform/github/schemas.js.map +1 -0
- package/dist/platform/github/zip.js +85 -0
- package/dist/platform/github/zip.js.map +1 -0
- package/dist/platform/gitlab/admin.js +105 -0
- package/dist/platform/gitlab/admin.js.map +1 -0
- package/dist/platform/gitlab/api.js +229 -0
- package/dist/platform/gitlab/api.js.map +1 -0
- package/dist/platform/gitlab/attachments.js +79 -0
- package/dist/platform/gitlab/attachments.js.map +1 -0
- package/dist/platform/gitlab/http.js +165 -0
- package/dist/platform/gitlab/http.js.map +1 -0
- package/dist/platform/gitlab/index.js +630 -0
- package/dist/platform/gitlab/index.js.map +1 -0
- package/dist/platform/gitlab/oauth.js +58 -0
- package/dist/platform/gitlab/oauth.js.map +1 -0
- package/dist/platform/gitlab/read.js +182 -0
- package/dist/platform/gitlab/read.js.map +1 -0
- package/dist/platform/gitlab/schemas-read.js +274 -0
- package/dist/platform/gitlab/schemas-read.js.map +1 -0
- package/dist/platform/gitlab/schemas.js +251 -0
- package/dist/platform/gitlab/schemas.js.map +1 -0
- package/dist/platform/gitlab/signature.js +52 -0
- package/dist/platform/gitlab/signature.js.map +1 -0
- package/dist/platform/index.js +38 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/port.js +26 -0
- package/dist/platform/port.js.map +1 -0
- package/dist/platform/types.js +80 -0
- package/dist/platform/types.js.map +1 -0
- package/dist/podman.js +119 -0
- package/dist/podman.js.map +1 -0
- package/dist/project-sync.js +69 -0
- package/dist/project-sync.js.map +1 -0
- package/dist/prompt.js +47 -0
- package/dist/prompt.js.map +1 -0
- package/dist/queue-store.js +236 -0
- package/dist/queue-store.js.map +1 -0
- package/dist/queue.js +129 -0
- package/dist/queue.js.map +1 -0
- package/dist/redact.js +23 -0
- package/dist/redact.js.map +1 -0
- package/dist/run-files.js +297 -0
- package/dist/run-files.js.map +1 -0
- package/dist/run-filters.js +54 -0
- package/dist/run-filters.js.map +1 -0
- package/dist/run-history-store.js +229 -0
- package/dist/run-history-store.js.map +1 -0
- package/dist/run-log-sink.js +270 -0
- package/dist/run-log-sink.js.map +1 -0
- package/dist/run-log.js +97 -0
- package/dist/run-log.js.map +1 -0
- package/dist/run-usage.js +29 -0
- package/dist/run-usage.js.map +1 -0
- package/dist/run-view.js +112 -0
- package/dist/run-view.js.map +1 -0
- package/dist/runner.js +1094 -0
- package/dist/runner.js.map +1 -0
- package/dist/runtime-apply.js +26 -0
- package/dist/runtime-apply.js.map +1 -0
- package/dist/runtime-settings.js +71 -0
- package/dist/runtime-settings.js.map +1 -0
- package/dist/runtime-state.js +19 -0
- package/dist/runtime-state.js.map +1 -0
- package/dist/server.js +119 -0
- package/dist/server.js.map +1 -0
- package/dist/settings-store.js +320 -0
- package/dist/settings-store.js.map +1 -0
- package/dist/status.js +121 -0
- package/dist/status.js.map +1 -0
- package/dist/stop.js +56 -0
- package/dist/stop.js.map +1 -0
- package/dist/sweeps.js +87 -0
- package/dist/sweeps.js.map +1 -0
- package/dist/task-log.js +279 -0
- package/dist/task-log.js.map +1 -0
- package/dist/task-view.js +62 -0
- package/dist/task-view.js.map +1 -0
- package/dist/token-store.js +68 -0
- package/dist/token-store.js.map +1 -0
- package/dist/types/access.js +74 -0
- package/dist/types/access.js.map +1 -0
- package/dist/types/custom-repos.js +28 -0
- package/dist/types/custom-repos.js.map +1 -0
- package/dist/types/env-config.js +25 -0
- package/dist/types/env-config.js.map +1 -0
- package/dist/types/env.js +190 -0
- package/dist/types/env.js.map +1 -0
- package/dist/types/global-settings.js +178 -0
- package/dist/types/global-settings.js.map +1 -0
- package/dist/types/lsp-servers.js +145 -0
- package/dist/types/lsp-servers.js.map +1 -0
- package/dist/types/mcp-config.js +77 -0
- package/dist/types/mcp-config.js.map +1 -0
- package/dist/types/opencode.js +59 -0
- package/dist/types/opencode.js.map +1 -0
- package/dist/types/outbound-webhook.js +56 -0
- package/dist/types/outbound-webhook.js.map +1 -0
- package/dist/types/project-settings.js +114 -0
- package/dist/types/project-settings.js.map +1 -0
- package/dist/types/provider-registry.js +37 -0
- package/dist/types/provider-registry.js.map +1 -0
- package/dist/types/runtime-settings.js +78 -0
- package/dist/types/runtime-settings.js.map +1 -0
- package/dist/usage-stats.js +159 -0
- package/dist/usage-stats.js.map +1 -0
- package/dist/version.js +19 -0
- package/dist/version.js.map +1 -0
- package/dist/volume-gc.js +193 -0
- package/dist/volume-gc.js.map +1 -0
- package/dist/volume-manage.js +191 -0
- package/dist/volume-manage.js.map +1 -0
- package/dist/volume-store.js +122 -0
- package/dist/volume-store.js.map +1 -0
- package/dist/webhook.js +1106 -0
- package/dist/webhook.js.map +1 -0
- package/dist/work-item-auto-store.js +75 -0
- package/dist/work-item-auto-store.js.map +1 -0
- package/dist/work-item-branch-store.js +37 -0
- package/dist/work-item-branch-store.js.map +1 -0
- package/migrations/0001_initial.sql +59 -0
- package/migrations/0002_queue_status.sql +15 -0
- package/migrations/0003_work_item_base_branch.sql +14 -0
- package/migrations/0004_project_settings.sql +15 -0
- package/migrations/0005_global_settings.sql +34 -0
- package/migrations/0006_model_variants.sql +8 -0
- package/migrations/0007_container_error_logs.sql +21 -0
- package/migrations/0008_project_access_grants.sql +16 -0
- package/migrations/0009_drop_imported_legacy.sql +4 -0
- package/migrations/0010_container_error_log_model.sql +6 -0
- package/migrations/0011_container_error_log_title.sql +5 -0
- package/migrations/0012_pending_task_cancel.sql +6 -0
- package/migrations/0013_builder_image.sql +6 -0
- package/migrations/0014_build_workflow.sql +7 -0
- package/migrations/0015_access_rules.sql +24 -0
- package/migrations/0016_trigger_policy.sql +17 -0
- package/migrations/0017_attachment_upload.sql +8 -0
- package/migrations/0018_work_item_branch.sql +11 -0
- package/migrations/0019_auto_push_mr.sql +18 -0
- package/migrations/0020_outbound_webhooks.sql +47 -0
- package/migrations/0021_runtime_settings.sql +12 -0
- package/migrations/0022_auto_resolve_conflicts.sql +17 -0
- package/migrations/0023_ci_fail_auto_report.sql +27 -0
- package/migrations/0024_work_item_auto_override.sql +22 -0
- package/migrations/0025_run_history.sql +37 -0
- package/migrations/0026_run_history_task_seq.sql +6 -0
- package/migrations/0027_custom_repos.sql +11 -0
- package/migrations/0028_run_usage.sql +14 -0
- package/migrations/0029_drop_ocr_langs.sql +6 -0
- package/migrations/0030_mr_assignee.sql +9 -0
- package/migrations/0031_lsp_servers.sql +14 -0
- package/opencode-config/managed/devbot-agent-policy.md +61 -0
- package/opencode-config/managed/opencode.json +77 -0
- package/opencode-config/opencode.json +211 -0
- package/opencode-config/plugins/devbot-path-guard.js +224 -0
- package/package.json +158 -4
- package/public/assets/DashboardSidebarCollapse-rIuzCmVm.js +1 -0
- package/public/assets/DashboardToolbar-DFCUqZ4Z.js +1 -0
- package/public/assets/ErrorLogModal.vue_vue_type_script_setup_true_lang-BCyNIf1E.js +1 -0
- package/public/assets/ErrorLogsPage-DyYK2Rop.js +1 -0
- package/public/assets/LogSlideover.vue_vue_type_script_setup_true_lang-33xie7TE.js +1 -0
- package/public/assets/OverviewPage-CFfa0uwg.js +1 -0
- package/public/assets/PageGrid-CBROIU87.js +1 -0
- package/public/assets/PeriodRangePicker.vue_vue_type_script_setup_true_lang-DiFUNem7.js +1 -0
- package/public/assets/ProjectDetailPage-CreyvUit.js +1 -0
- package/public/assets/ProjectsPage-CFx8-elJ.js +1 -0
- package/public/assets/RunDetailSlideover.vue_vue_type_script_setup_true_lang-DopYYmCT.js +1 -0
- package/public/assets/RunsPage-CRnnXU4P.js +1 -0
- package/public/assets/Select-Bvx32Diz.js +1 -0
- package/public/assets/SelectMenu-BjMxc4VB.js +1 -0
- package/public/assets/SettingsPage-Bb6LM3wO.js +60 -0
- package/public/assets/TimeCell.vue_vue_type_script_setup_true_lang-DW_UB0Fu.js +1 -0
- package/public/assets/UsagePage-BLMDEsv-.js +332 -0
- package/public/assets/UsagePage-DodEeAjB.css +1 -0
- package/public/assets/VolumesPage-CxcLc3L2.js +1 -0
- package/public/assets/WebhookConfigPanel.vue_vue_type_script_setup_true_lang-B2V2GF6b.js +1 -0
- package/public/assets/WorkItemCell.vue_vue_type_script_setup_true_lang-BQn6vTjd.js +1 -0
- package/public/assets/index-BMbMibyb.js +4 -0
- package/public/assets/index-C5RBBrPj.js +30 -0
- package/public/assets/index-CgX29UgC.css +1 -0
- package/public/assets/usage-format-jsb31_O8.js +1 -0
- package/public/assets/useManagedProjects-8rtjRqVJ.js +1 -0
- package/public/assets/useRouteTab-DfwrcMic.js +1 -0
- package/public/favicon.ico +0 -0
- package/public/favicon.png +0 -0
- package/public/index.html +15 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
// GitLab driver: implements the Platform port by delegating to the existing
|
|
2
|
+
// GitLab clients (gitlab.ts, gitlab-read.ts, admin-api.ts, oauth.ts,
|
|
3
|
+
// gitlab-client.ts, webhook-signature.ts, attachments.ts). Behavior-preserving
|
|
4
|
+
// extraction — the GitLab path is exactly what DevBot did before the abstraction.
|
|
5
|
+
import { config } from "../../config.js";
|
|
6
|
+
import { log } from "../../logger.js";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import * as gitlab from "./api.js";
|
|
9
|
+
import * as read from "./read.js";
|
|
10
|
+
import * as admin from "./admin.js";
|
|
11
|
+
import * as oauth from "./oauth.js";
|
|
12
|
+
import { gitExtraHeaderGitlab } from "../git-auth.js";
|
|
13
|
+
import { verifyWebhookSignature } from "./signature.js";
|
|
14
|
+
import { findAttachmentRefs, downloadAttachment, uploadAttachment } from "./attachments.js";
|
|
15
|
+
import { NoteHookPayloadSchema, WorkItemHookPayloadSchema, PipelineHookPayloadSchema } from "./schemas.js";
|
|
16
|
+
// ---- Mappers ---------------------------------------------------------------
|
|
17
|
+
function accessLevelToPermission(level) {
|
|
18
|
+
if (level >= 50)
|
|
19
|
+
return "owner";
|
|
20
|
+
if (level >= 40)
|
|
21
|
+
return "admin";
|
|
22
|
+
if (level >= 30)
|
|
23
|
+
return "write";
|
|
24
|
+
if (level >= 20)
|
|
25
|
+
return "read";
|
|
26
|
+
if (level >= 10)
|
|
27
|
+
return "read";
|
|
28
|
+
return "none";
|
|
29
|
+
}
|
|
30
|
+
function mapState(state) {
|
|
31
|
+
if (state === "opened")
|
|
32
|
+
return "open";
|
|
33
|
+
if (state === "merged")
|
|
34
|
+
return "merged";
|
|
35
|
+
if (state === "closed")
|
|
36
|
+
return "closed";
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
function toGitlabWorkItemState(state) {
|
|
40
|
+
if (state === "open")
|
|
41
|
+
return "opened";
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
function toGitlabMrState(state) {
|
|
45
|
+
if (state === "open")
|
|
46
|
+
return "opened";
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
function toGitlabMilestoneState(state) {
|
|
50
|
+
if (state === "open")
|
|
51
|
+
return "active";
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
// Neutral search scope -> GitLab `scope` query value.
|
|
55
|
+
const GITLAB_SEARCH_SCOPE = {
|
|
56
|
+
code: "blobs",
|
|
57
|
+
issues: "issues",
|
|
58
|
+
merge_requests: "merge_requests",
|
|
59
|
+
commits: "commits",
|
|
60
|
+
wiki: "wiki_blobs",
|
|
61
|
+
notes: "notes",
|
|
62
|
+
users: "users",
|
|
63
|
+
milestones: "milestones",
|
|
64
|
+
};
|
|
65
|
+
function mapRepo(p) {
|
|
66
|
+
const path = p.path_with_namespace ?? p.full_name ?? "";
|
|
67
|
+
return {
|
|
68
|
+
id: p.id,
|
|
69
|
+
path,
|
|
70
|
+
webUrl: p.web_url ?? "",
|
|
71
|
+
cloneUrl: p.http_url_to_repo ?? p.git_http_url ?? `${config.PLATFORM_URL.replace(/\/$/, "")}/${path}.git`,
|
|
72
|
+
defaultBranch: p.default_branch ?? null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// ---- Ingress ---------------------------------------------------------------
|
|
76
|
+
const gitlabIngress = {
|
|
77
|
+
platform: "gitlab",
|
|
78
|
+
eventName(headers) {
|
|
79
|
+
const v = headers["x-gitlab-event"];
|
|
80
|
+
return Array.isArray(v) ? v[0] : v;
|
|
81
|
+
},
|
|
82
|
+
projectIdFromBody(body) {
|
|
83
|
+
const raw = body?.project?.id;
|
|
84
|
+
return typeof raw === "number" ? raw : undefined;
|
|
85
|
+
},
|
|
86
|
+
deliveryId(headers) {
|
|
87
|
+
const v = headers["webhook-id"];
|
|
88
|
+
return Array.isArray(v) ? v[0] : v;
|
|
89
|
+
},
|
|
90
|
+
verifySignature(secret, headers, rawBody, nowMs) {
|
|
91
|
+
return verifyWebhookSignature(secret, headers, rawBody, nowMs);
|
|
92
|
+
},
|
|
93
|
+
generateWebhookSecret() {
|
|
94
|
+
return "whsec_" + Buffer.from(randomBytes(32)).toString("base64");
|
|
95
|
+
},
|
|
96
|
+
parseWebhook(headers, body) {
|
|
97
|
+
const event = this.eventName(headers);
|
|
98
|
+
if (event === "Note Hook") {
|
|
99
|
+
// Cheap pre-filter on the wire value: merge-request, commit, wiki and
|
|
100
|
+
// snippet notes all arrive as "Note Hook" but are not work-item mentions,
|
|
101
|
+
// so they must not reach the schema (their shape is legitimately
|
|
102
|
+
// different) nor the schema-mismatch warning below.
|
|
103
|
+
const noteableType = body
|
|
104
|
+
?.object_attributes?.noteable_type;
|
|
105
|
+
if (noteableType !== undefined && noteableType !== "Issue")
|
|
106
|
+
return null;
|
|
107
|
+
const parsed = NoteHookPayloadSchema.safeParse(body);
|
|
108
|
+
if (!parsed.success) {
|
|
109
|
+
// A signed payload we cannot read is schema drift, not an unhandled
|
|
110
|
+
// event: surface the failing field paths instead of dropping the
|
|
111
|
+
// mention silently behind a 204.
|
|
112
|
+
log.warn("gitlab webhook: Note Hook payload rejected", { issues: parsed.error.issues });
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const p = parsed.data;
|
|
116
|
+
if (p.object_attributes.action !== "create")
|
|
117
|
+
return null;
|
|
118
|
+
return {
|
|
119
|
+
kind: "comment",
|
|
120
|
+
rawEvent: "Note Hook",
|
|
121
|
+
repo: mapRepo(p.project),
|
|
122
|
+
workItem: {
|
|
123
|
+
id: p.issue.id,
|
|
124
|
+
number: p.issue.iid,
|
|
125
|
+
title: p.issue.title,
|
|
126
|
+
description: p.issue.description ?? "",
|
|
127
|
+
state: "open",
|
|
128
|
+
webUrl: p.issue.url,
|
|
129
|
+
},
|
|
130
|
+
actor: { id: p.user.id, username: p.user.username, name: p.user.name },
|
|
131
|
+
body: p.object_attributes.note,
|
|
132
|
+
commentId: p.object_attributes.id,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (event === "Issue Hook") {
|
|
136
|
+
const parsed = WorkItemHookPayloadSchema.safeParse(body);
|
|
137
|
+
if (!parsed.success) {
|
|
138
|
+
log.warn("gitlab webhook: Issue Hook payload rejected", { issues: parsed.error.issues });
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const p = parsed.data;
|
|
142
|
+
const action = p.object_attributes.action;
|
|
143
|
+
if (action !== "open" && action !== "close")
|
|
144
|
+
return null;
|
|
145
|
+
return {
|
|
146
|
+
kind: action === "close" ? "workitem-close" : "workitem-open",
|
|
147
|
+
rawEvent: "Issue Hook",
|
|
148
|
+
repo: mapRepo(p.project),
|
|
149
|
+
workItem: {
|
|
150
|
+
id: p.object_attributes.id,
|
|
151
|
+
number: p.object_attributes.iid,
|
|
152
|
+
title: p.object_attributes.title,
|
|
153
|
+
description: p.object_attributes.description ?? "",
|
|
154
|
+
state: action === "close" ? "closed" : "open",
|
|
155
|
+
webUrl: p.object_attributes.url,
|
|
156
|
+
},
|
|
157
|
+
actor: { id: p.user.id, username: p.user.username, name: p.user.name },
|
|
158
|
+
body: p.object_attributes.description ?? "",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (event === "Pipeline Hook") {
|
|
162
|
+
const parsed = PipelineHookPayloadSchema.safeParse(body);
|
|
163
|
+
if (!parsed.success) {
|
|
164
|
+
log.warn("gitlab webhook schema mismatch", { event, issues: parsed.error.issues });
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const p = parsed.data;
|
|
168
|
+
if (p.object_attributes.status !== "failed")
|
|
169
|
+
return null;
|
|
170
|
+
const mr = p.merge_request;
|
|
171
|
+
return {
|
|
172
|
+
kind: "pipeline-failed",
|
|
173
|
+
rawEvent: "Pipeline Hook",
|
|
174
|
+
repo: mapRepo(p.project),
|
|
175
|
+
sourceBranch: mr?.source_branch ?? p.object_attributes.ref,
|
|
176
|
+
pipelineId: p.object_attributes.id,
|
|
177
|
+
...(p.object_attributes.sha ? { commitSha: p.object_attributes.sha } : {}),
|
|
178
|
+
...(mr ? { changeRequestNumber: mr.iid } : {}),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
// `randomBytes` is imported at the top.
|
|
185
|
+
// ---- Work items ------------------------------------------------------------
|
|
186
|
+
const gitlabWorkItems = {
|
|
187
|
+
async postComment(repoId, number, body) {
|
|
188
|
+
const n = await gitlab.postNote(repoId, number, body);
|
|
189
|
+
return { id: n.id, body: n.body };
|
|
190
|
+
},
|
|
191
|
+
async replyInThread(repoId, number, commentId, body) {
|
|
192
|
+
const n = await gitlab.postDiscussionReply(repoId, number, String(commentId), body).catch(async () => {
|
|
193
|
+
return gitlab.postNote(repoId, number, body);
|
|
194
|
+
});
|
|
195
|
+
return { id: n.id, body: n.body };
|
|
196
|
+
},
|
|
197
|
+
async postErrorReply(repoId, number, triggeringCommentId, body) {
|
|
198
|
+
await gitlab.postErrorReply(repoId, number, triggeringCommentId, body);
|
|
199
|
+
},
|
|
200
|
+
async listComments(repoId, number) {
|
|
201
|
+
const notes = await gitlab.listIssueNotes(repoId, number);
|
|
202
|
+
return notes.map((n) => ({
|
|
203
|
+
id: n.id,
|
|
204
|
+
body: n.body,
|
|
205
|
+
...(n.system !== undefined ? { system: n.system } : {}),
|
|
206
|
+
...(n.author ? { author: n.author } : {}),
|
|
207
|
+
...(n.created_at ? { createdAt: n.created_at } : {}),
|
|
208
|
+
}));
|
|
209
|
+
},
|
|
210
|
+
async getWorkItem(repoId, number) {
|
|
211
|
+
const i = await gitlab.getIssueFull(repoId, number);
|
|
212
|
+
return {
|
|
213
|
+
id: i.id,
|
|
214
|
+
number: i.iid,
|
|
215
|
+
title: i.title,
|
|
216
|
+
description: i.description ?? "",
|
|
217
|
+
state: mapState(i.state),
|
|
218
|
+
webUrl: i.web_url,
|
|
219
|
+
...(i.author ? { author: { id: i.author.id } } : {}),
|
|
220
|
+
...(i.assignees ? { assignees: i.assignees.map((a) => ({ id: a.id })) } : {}),
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
async getWorkItemStateOrNull(repoId, number) {
|
|
224
|
+
const s = await gitlab.fetchIssueStateOrNull(repoId, number);
|
|
225
|
+
if (s === null)
|
|
226
|
+
return null;
|
|
227
|
+
return s === "opened" ? "open" : "closed";
|
|
228
|
+
},
|
|
229
|
+
async getMemberPermission(repoId, user) {
|
|
230
|
+
// A non-member (404) is "none" rather than a lookup failure, so a
|
|
231
|
+
// minRole=none policy can admit any authenticated project member. 5xx still
|
|
232
|
+
// throws and the caller fails closed.
|
|
233
|
+
const m = await gitlab.fetchProjectMemberOrNull(repoId, user.id);
|
|
234
|
+
return m ? accessLevelToPermission(m.access_level) : "none";
|
|
235
|
+
},
|
|
236
|
+
async resolveUser(username) {
|
|
237
|
+
const u = await gitlab.findUserByUsername(username);
|
|
238
|
+
return u ? { id: u.id, username: u.username, name: u.name } : null;
|
|
239
|
+
},
|
|
240
|
+
async searchUsers(query, opts = {}) {
|
|
241
|
+
return read.searchUsers(query, opts);
|
|
242
|
+
},
|
|
243
|
+
async listWorkItems(repoId, opts = {}) {
|
|
244
|
+
const items = await gitlab.listIssues(repoId, {
|
|
245
|
+
...(opts.state ? { state: toGitlabWorkItemState(opts.state) } : {}),
|
|
246
|
+
...(opts.search ? { search: opts.search } : {}),
|
|
247
|
+
...(opts.labels ? { labels: opts.labels } : {}),
|
|
248
|
+
...(opts.page ? { page: opts.page } : {}),
|
|
249
|
+
...(opts.perPage ? { perPage: opts.perPage } : {}),
|
|
250
|
+
});
|
|
251
|
+
return items.map(mapWorkItemSummary);
|
|
252
|
+
},
|
|
253
|
+
async getWorkItemSummary(repoId, number) {
|
|
254
|
+
return mapWorkItemSummary(await gitlab.getIssueFull(repoId, number));
|
|
255
|
+
},
|
|
256
|
+
async listCommentsFull(repoId, number, opts = {}) {
|
|
257
|
+
const notes = await read.listIssueNotesFull(repoId, number, opts);
|
|
258
|
+
return notes.map((n) => ({
|
|
259
|
+
id: n.id,
|
|
260
|
+
body: n.body,
|
|
261
|
+
...(n.system !== undefined ? { system: n.system } : {}),
|
|
262
|
+
...(n.author ? { author: n.author } : {}),
|
|
263
|
+
...(n.created_at ? { createdAt: n.created_at } : {}),
|
|
264
|
+
}));
|
|
265
|
+
},
|
|
266
|
+
async listLabels(repoId, opts = {}) {
|
|
267
|
+
const labels = await read.listLabels(repoId, opts);
|
|
268
|
+
return labels.map((l) => ({
|
|
269
|
+
id: l.id,
|
|
270
|
+
name: l.name,
|
|
271
|
+
...(l.color ? { color: l.color } : {}),
|
|
272
|
+
...(l.description !== undefined ? { description: l.description } : {}),
|
|
273
|
+
}));
|
|
274
|
+
},
|
|
275
|
+
async listMilestones(repoId, opts = {}) {
|
|
276
|
+
const ms = await read.listMilestones(repoId, {
|
|
277
|
+
...opts,
|
|
278
|
+
...(opts.state ? { state: toGitlabMilestoneState(opts.state) } : {}),
|
|
279
|
+
});
|
|
280
|
+
return ms.map((m) => ({
|
|
281
|
+
id: m.id,
|
|
282
|
+
number: m.iid,
|
|
283
|
+
title: m.title,
|
|
284
|
+
state: m.state,
|
|
285
|
+
...(m.description !== undefined ? { description: m.description } : {}),
|
|
286
|
+
...(m.due_date !== undefined ? { dueDate: m.due_date } : {}),
|
|
287
|
+
...(m.web_url ? { webUrl: m.web_url } : {}),
|
|
288
|
+
}));
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
function mapWorkItemSummary(i) {
|
|
292
|
+
return {
|
|
293
|
+
id: i.id,
|
|
294
|
+
number: i.iid,
|
|
295
|
+
title: i.title,
|
|
296
|
+
state: mapState(i.state),
|
|
297
|
+
webUrl: i.web_url,
|
|
298
|
+
...(i.description != null ? { description: i.description } : {}),
|
|
299
|
+
...(i.labels ? { labels: i.labels } : {}),
|
|
300
|
+
...(i.assignees ? { assignees: i.assignees.map((a) => ({ id: a.id, username: a.username, name: a.name })) } : {}),
|
|
301
|
+
...(i.author ? { author: { id: i.author.id, username: i.author.username, name: i.author.name } } : {}),
|
|
302
|
+
...(i.created_at ? { createdAt: i.created_at } : {}),
|
|
303
|
+
...(i.due_date !== undefined ? { dueDate: i.due_date } : {}),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// ---- Change requests -------------------------------------------------------
|
|
307
|
+
const gitlabChangeRequests = {
|
|
308
|
+
async list(repoId, opts = {}) {
|
|
309
|
+
const mrs = await gitlab.listMergeRequests(repoId, {
|
|
310
|
+
...(opts.state ? { state: toGitlabMrState(opts.state) } : {}),
|
|
311
|
+
...(opts.search ? { search: opts.search } : {}),
|
|
312
|
+
...(opts.sourceBranch ? { sourceBranch: opts.sourceBranch } : {}),
|
|
313
|
+
...(opts.page ? { page: opts.page } : {}),
|
|
314
|
+
...(opts.perPage ? { perPage: opts.perPage } : {}),
|
|
315
|
+
});
|
|
316
|
+
return mrs.map((m) => ({
|
|
317
|
+
id: m.id,
|
|
318
|
+
number: m.iid,
|
|
319
|
+
title: m.title,
|
|
320
|
+
state: mapState(m.state),
|
|
321
|
+
webUrl: m.web_url,
|
|
322
|
+
...(m.description !== undefined ? { description: m.description } : {}),
|
|
323
|
+
...(m.source_branch ? { sourceBranch: m.source_branch } : {}),
|
|
324
|
+
...(m.target_branch ? { targetBranch: m.target_branch } : {}),
|
|
325
|
+
...(m.labels ? { labels: m.labels } : {}),
|
|
326
|
+
...(m.author ? { author: m.author } : {}),
|
|
327
|
+
...(m.created_at ? { createdAt: m.created_at } : {}),
|
|
328
|
+
...(m.updated_at ? { updatedAt: m.updated_at } : {}),
|
|
329
|
+
...(m.merged_at !== undefined ? { mergedAt: m.merged_at } : {}),
|
|
330
|
+
...(m.draft !== undefined ? { draft: m.draft } : {}),
|
|
331
|
+
}));
|
|
332
|
+
},
|
|
333
|
+
async create(repoId, input) {
|
|
334
|
+
const m = await gitlab.createMergeRequest(repoId, {
|
|
335
|
+
source_branch: input.sourceBranch,
|
|
336
|
+
target_branch: input.targetBranch,
|
|
337
|
+
title: input.title,
|
|
338
|
+
description: input.description,
|
|
339
|
+
...(input.assignee ? { assignee_ids: [input.assignee.id] } : {}),
|
|
340
|
+
});
|
|
341
|
+
return {
|
|
342
|
+
id: m.id,
|
|
343
|
+
number: m.iid,
|
|
344
|
+
title: input.title,
|
|
345
|
+
state: mapState(m.state),
|
|
346
|
+
sourceBranch: m.source_branch,
|
|
347
|
+
targetBranch: m.target_branch,
|
|
348
|
+
webUrl: m.web_url,
|
|
349
|
+
};
|
|
350
|
+
},
|
|
351
|
+
async update(repoId, number, input) {
|
|
352
|
+
const m = await gitlab.updateMergeRequest(repoId, number, input);
|
|
353
|
+
return {
|
|
354
|
+
id: m.id,
|
|
355
|
+
number: m.iid,
|
|
356
|
+
title: input.title,
|
|
357
|
+
state: mapState(m.state),
|
|
358
|
+
sourceBranch: m.source_branch,
|
|
359
|
+
targetBranch: m.target_branch,
|
|
360
|
+
webUrl: m.web_url,
|
|
361
|
+
};
|
|
362
|
+
},
|
|
363
|
+
async get(repoId, number) {
|
|
364
|
+
const m = await read.getMergeRequestFull(repoId, number);
|
|
365
|
+
return {
|
|
366
|
+
id: m.id,
|
|
367
|
+
number: m.iid,
|
|
368
|
+
title: m.title,
|
|
369
|
+
state: mapState(m.state),
|
|
370
|
+
webUrl: m.web_url ?? "",
|
|
371
|
+
...(m.description !== undefined ? { description: m.description ?? "" } : {}),
|
|
372
|
+
...(m.source_branch ? { sourceBranch: m.source_branch } : {}),
|
|
373
|
+
...(m.target_branch ? { targetBranch: m.target_branch } : {}),
|
|
374
|
+
...(m.labels ? { labels: m.labels } : {}),
|
|
375
|
+
...(m.author ? { author: m.author } : {}),
|
|
376
|
+
...(m.created_at ? { createdAt: m.created_at } : {}),
|
|
377
|
+
...(m.updated_at ? { updatedAt: m.updated_at } : {}),
|
|
378
|
+
...(m.merged_at !== undefined ? { mergedAt: m.merged_at } : {}),
|
|
379
|
+
...(m.draft !== undefined ? { draft: m.draft } : {}),
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
async listReviewDiscussions(repoId, number, opts = {}) {
|
|
383
|
+
const ds = await gitlab.listMergeRequestDiscussions(repoId, number, opts);
|
|
384
|
+
return ds.map((d) => ({
|
|
385
|
+
id: d.id,
|
|
386
|
+
...(d.individual_note !== undefined ? { individualNote: d.individual_note } : {}),
|
|
387
|
+
notes: d.notes.map((n) => ({
|
|
388
|
+
id: n.id,
|
|
389
|
+
body: n.body,
|
|
390
|
+
...(n.type !== undefined ? { type: n.type } : {}),
|
|
391
|
+
...(n.system !== undefined ? { system: n.system } : {}),
|
|
392
|
+
...(n.author ? { author: n.author } : {}),
|
|
393
|
+
...(n.created_at ? { createdAt: n.created_at } : {}),
|
|
394
|
+
...(n.resolvable !== undefined ? { resolvable: n.resolvable } : {}),
|
|
395
|
+
...(n.resolved !== undefined ? { resolved: n.resolved } : {}),
|
|
396
|
+
...(n.position !== undefined ? { position: n.position } : {}),
|
|
397
|
+
})),
|
|
398
|
+
}));
|
|
399
|
+
},
|
|
400
|
+
async listNotes(repoId, number, opts = {}) {
|
|
401
|
+
const notes = await read.listMergeRequestNotes(repoId, number, opts);
|
|
402
|
+
return notes.map((n) => ({
|
|
403
|
+
id: n.id,
|
|
404
|
+
body: n.body,
|
|
405
|
+
...(n.system !== undefined ? { system: n.system } : {}),
|
|
406
|
+
...(n.author ? { author: n.author } : {}),
|
|
407
|
+
...(n.created_at ? { createdAt: n.created_at } : {}),
|
|
408
|
+
}));
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
// ---- Repository ------------------------------------------------------------
|
|
412
|
+
const gitlabRepository = {
|
|
413
|
+
async getRepo(repoId) {
|
|
414
|
+
return mapRepo(await read.getProjectDetail(repoId));
|
|
415
|
+
},
|
|
416
|
+
branchExists: (repoId, branch) => gitlab.branchExists(repoId, branch),
|
|
417
|
+
firstExistingBranch: (repoId, branches) => gitlab.firstExistingBranch(repoId, branches),
|
|
418
|
+
async listBranches(repoId, opts = {}) {
|
|
419
|
+
const bs = await read.listBranches(repoId, opts);
|
|
420
|
+
return bs.map((b) => ({
|
|
421
|
+
name: b.name,
|
|
422
|
+
...(b.protected !== undefined ? { protected: b.protected } : {}),
|
|
423
|
+
...(b.default !== undefined ? { default: b.default } : {}),
|
|
424
|
+
...(b.web_url ? { webUrl: b.web_url } : {}),
|
|
425
|
+
}));
|
|
426
|
+
},
|
|
427
|
+
listTree: (repoId, opts = {}) => read.listRepositoryTree(repoId, opts),
|
|
428
|
+
getFile: (repoId, filePath, ref, maxBytes) => read.getRepositoryFile(repoId, filePath, ref, maxBytes),
|
|
429
|
+
async listCommits(repoId, opts = {}) {
|
|
430
|
+
const cs = await read.listCommits(repoId, opts);
|
|
431
|
+
return cs.map(mapCommit);
|
|
432
|
+
},
|
|
433
|
+
async getCommit(repoId, sha) {
|
|
434
|
+
return mapCommit(await read.getCommit(repoId, sha));
|
|
435
|
+
},
|
|
436
|
+
compare: (repoId, from, to) => read.compareRefs(repoId, from, to).then((c) => mapCompare(c)),
|
|
437
|
+
async listTags(repoId, opts = {}) {
|
|
438
|
+
const ts = await read.listTags(repoId, opts);
|
|
439
|
+
return ts.map((t) => ({
|
|
440
|
+
name: t.name,
|
|
441
|
+
...(t.message !== undefined ? { message: t.message } : {}),
|
|
442
|
+
...(t.target ? { target: t.target } : {}),
|
|
443
|
+
...(t.protected !== undefined ? { protected: t.protected } : {}),
|
|
444
|
+
}));
|
|
445
|
+
},
|
|
446
|
+
async listMembers(repoId, opts = {}) {
|
|
447
|
+
const ms = await read.listMembers(repoId, opts);
|
|
448
|
+
return ms.map((m) => ({
|
|
449
|
+
id: m.id,
|
|
450
|
+
username: m.username,
|
|
451
|
+
name: m.name,
|
|
452
|
+
...(m.access_level !== undefined ? { permission: accessLevelToPermission(m.access_level) } : {}),
|
|
453
|
+
...(m.web_url ? { webUrl: m.web_url } : {}),
|
|
454
|
+
}));
|
|
455
|
+
},
|
|
456
|
+
async listReleases(repoId, opts = {}) {
|
|
457
|
+
const rs = await read.listReleases(repoId, opts);
|
|
458
|
+
return rs.map((r) => ({
|
|
459
|
+
tagName: r.tag_name,
|
|
460
|
+
...(r.name ? { name: r.name } : {}),
|
|
461
|
+
...(r.description !== undefined ? { description: r.description } : {}),
|
|
462
|
+
...(r.created_at ? { createdAt: r.created_at } : {}),
|
|
463
|
+
...(r.released_at ? { releasedAt: r.released_at } : {}),
|
|
464
|
+
...(r.author ? { author: r.author } : {}),
|
|
465
|
+
}));
|
|
466
|
+
},
|
|
467
|
+
async listWikiPages(repoId, opts = {}) {
|
|
468
|
+
const ws = await read.listWikiPages(repoId, opts);
|
|
469
|
+
return ws.map(mapWiki);
|
|
470
|
+
},
|
|
471
|
+
async getWikiPage(repoId, slug) {
|
|
472
|
+
return mapWiki(await read.getWikiPage(repoId, slug));
|
|
473
|
+
},
|
|
474
|
+
searchProject: (repoId, search, opts = {}) => read.searchProject(repoId, search, {
|
|
475
|
+
...opts,
|
|
476
|
+
...(opts.scope ? { scope: GITLAB_SEARCH_SCOPE[opts.scope] ?? opts.scope } : {}),
|
|
477
|
+
}),
|
|
478
|
+
};
|
|
479
|
+
function mapCommit(c) {
|
|
480
|
+
return {
|
|
481
|
+
id: c.id,
|
|
482
|
+
title: c.title,
|
|
483
|
+
...(c.short_id ? { shortId: c.short_id } : {}),
|
|
484
|
+
...(c.message !== undefined ? { message: c.message } : {}),
|
|
485
|
+
...(c.author_name ? { authorName: c.author_name } : {}),
|
|
486
|
+
...(c.authored_date ? { authoredDate: c.authored_date } : {}),
|
|
487
|
+
...(c.created_at ? { createdAt: c.created_at } : {}),
|
|
488
|
+
...(c.web_url ? { webUrl: c.web_url } : {}),
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function mapCompare(c) {
|
|
492
|
+
return {
|
|
493
|
+
...(c.commit ? { commit: { id: c.commit.id, ...(c.commit.short_id ? { shortId: c.commit.short_id } : {}), ...(c.commit.title ? { title: c.commit.title } : {}) } } : {}),
|
|
494
|
+
commits: c.commits.map((x) => ({
|
|
495
|
+
id: x.id,
|
|
496
|
+
...(x.short_id ? { shortId: x.short_id } : {}),
|
|
497
|
+
...(x.title ? { title: x.title } : {}),
|
|
498
|
+
...(x.author_name ? { authorName: x.author_name } : {}),
|
|
499
|
+
...(x.created_at ? { createdAt: x.created_at } : {}),
|
|
500
|
+
})),
|
|
501
|
+
...(c.diffs
|
|
502
|
+
? {
|
|
503
|
+
diffs: c.diffs.map((d) => ({
|
|
504
|
+
oldPath: d.old_path,
|
|
505
|
+
newPath: d.new_path,
|
|
506
|
+
...(d.diff ? { diff: d.diff } : {}),
|
|
507
|
+
...(d.new_file !== undefined ? { newFile: d.new_file } : {}),
|
|
508
|
+
...(d.renamed_file !== undefined ? { renamedFile: d.renamed_file } : {}),
|
|
509
|
+
...(d.deleted_file !== undefined ? { deletedFile: d.deleted_file } : {}),
|
|
510
|
+
...(d.too_large !== undefined ? { tooLarge: d.too_large } : {}),
|
|
511
|
+
})),
|
|
512
|
+
}
|
|
513
|
+
: {}),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function mapWiki(w) {
|
|
517
|
+
return {
|
|
518
|
+
slug: w.slug,
|
|
519
|
+
title: w.title,
|
|
520
|
+
...(w.format ? { format: w.format } : {}),
|
|
521
|
+
...(w.content !== undefined ? { content: w.content } : {}),
|
|
522
|
+
...(w.updated_at ? { updatedAt: w.updated_at } : {}),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
// ---- CI --------------------------------------------------------------------
|
|
526
|
+
const gitlabCi = {
|
|
527
|
+
async listPipelines(repoId, opts = {}) {
|
|
528
|
+
const ps = await read.listPipelines(repoId, opts);
|
|
529
|
+
return ps.map((p) => ({
|
|
530
|
+
id: p.id,
|
|
531
|
+
status: p.status,
|
|
532
|
+
...(p.ref ? { ref: p.ref } : {}),
|
|
533
|
+
...(p.sha ? { sha: p.sha } : {}),
|
|
534
|
+
...(p.name ? { name: p.name } : {}),
|
|
535
|
+
...(p.web_url ? { webUrl: p.web_url } : {}),
|
|
536
|
+
...(p.created_at ? { createdAt: p.created_at } : {}),
|
|
537
|
+
...(p.updated_at ? { updatedAt: p.updated_at } : {}),
|
|
538
|
+
...(p.duration !== undefined ? { duration: p.duration } : {}),
|
|
539
|
+
}));
|
|
540
|
+
},
|
|
541
|
+
async getPipeline(repoId, pipelineId) {
|
|
542
|
+
const p = await read.getPipeline(repoId, pipelineId);
|
|
543
|
+
return {
|
|
544
|
+
id: p.id,
|
|
545
|
+
status: p.status,
|
|
546
|
+
...(p.ref ? { ref: p.ref } : {}),
|
|
547
|
+
...(p.sha ? { sha: p.sha } : {}),
|
|
548
|
+
...(p.name ? { name: p.name } : {}),
|
|
549
|
+
...(p.web_url ? { webUrl: p.web_url } : {}),
|
|
550
|
+
...(p.created_at ? { createdAt: p.created_at } : {}),
|
|
551
|
+
...(p.updated_at ? { updatedAt: p.updated_at } : {}),
|
|
552
|
+
...(p.duration !== undefined ? { duration: p.duration } : {}),
|
|
553
|
+
};
|
|
554
|
+
},
|
|
555
|
+
async listPipelineJobs(repoId, pipelineId, opts = {}) {
|
|
556
|
+
// Neutral `outcome: "failed"` maps to GitLab's server-side scope=failed.
|
|
557
|
+
const js = await read.listPipelineJobs(repoId, pipelineId, {
|
|
558
|
+
...(opts.scope ? { scope: opts.scope } : {}),
|
|
559
|
+
...(opts.outcome === "failed" ? { scope: "failed" } : {}),
|
|
560
|
+
...(opts.page ? { page: opts.page } : {}),
|
|
561
|
+
...(opts.perPage ? { perPage: opts.perPage } : {}),
|
|
562
|
+
});
|
|
563
|
+
return js.map((j) => ({
|
|
564
|
+
id: j.id,
|
|
565
|
+
name: j.name,
|
|
566
|
+
status: j.status,
|
|
567
|
+
...(j.stage ? { stage: j.stage } : {}),
|
|
568
|
+
...(j.ref ? { ref: j.ref } : {}),
|
|
569
|
+
...(j.web_url ? { webUrl: j.web_url } : {}),
|
|
570
|
+
...(j.created_at ? { createdAt: j.created_at } : {}),
|
|
571
|
+
...(j.started_at !== undefined ? { startedAt: j.started_at } : {}),
|
|
572
|
+
...(j.finished_at !== undefined ? { finishedAt: j.finished_at } : {}),
|
|
573
|
+
...(j.duration !== undefined ? { duration: j.duration } : {}),
|
|
574
|
+
}));
|
|
575
|
+
},
|
|
576
|
+
getJobLog: (repoId, jobId, maxBytes) => read.getJobLog(repoId, jobId, maxBytes),
|
|
577
|
+
};
|
|
578
|
+
// ---- Git auth --------------------------------------------------------------
|
|
579
|
+
const gitlabGitAuth = {
|
|
580
|
+
gitExtraHeader: () => gitExtraHeaderGitlab(config.PLATFORM_TOKEN),
|
|
581
|
+
cloneUrl: (path) => `${config.PLATFORM_URL.replace(/\/$/, "")}/${path}.git`,
|
|
582
|
+
};
|
|
583
|
+
// ---- Attachments -----------------------------------------------------------
|
|
584
|
+
const gitlabAttachments = {
|
|
585
|
+
findRefs: (body) => findAttachmentRefs(body),
|
|
586
|
+
download: (repoId, ref) => downloadAttachment(repoId, ref),
|
|
587
|
+
upload: (repoId, _number, file) => uploadAttachment(repoId, file),
|
|
588
|
+
};
|
|
589
|
+
// ---- Onboarding ------------------------------------------------------------
|
|
590
|
+
const gitlabOnboarding = {
|
|
591
|
+
authorizeUrl: (state) => oauth.getAuthorizationUrl(state),
|
|
592
|
+
exchangeCode: (code) => oauth.exchangeCodeForToken(code),
|
|
593
|
+
async currentUser(accessToken) {
|
|
594
|
+
const u = await oauth.fetchCurrentUser(accessToken);
|
|
595
|
+
return { id: u.id, username: u.username };
|
|
596
|
+
},
|
|
597
|
+
async listProjects(accessToken, q) {
|
|
598
|
+
const ps = await admin.listAllProjects(accessToken, q);
|
|
599
|
+
return ps.map((p) => ({ id: p.id, path: p.pathWithNamespace, webUrl: p.webUrl }));
|
|
600
|
+
},
|
|
601
|
+
addBot: (accessToken, project) => admin.inviteBotToProject(accessToken, project.id),
|
|
602
|
+
removeBot: (accessToken, project) => admin.removeBotFromProject(accessToken, project.id),
|
|
603
|
+
findOrCreateWebhook: (accessToken, project, url, secret) => admin.findOrCreateWebhookForUrl(accessToken, project.id, url, secret),
|
|
604
|
+
setWebhookSecret: (accessToken, project, webhookId, secret) => admin.updateWebhookToken(accessToken, project.id, webhookId, secret),
|
|
605
|
+
ensureCiFailureEvents: (accessToken, project, webhookId) => admin.ensureCiFailureEvents(accessToken, project.id, webhookId),
|
|
606
|
+
deleteWebhook: (accessToken, project, webhookId) => admin.deleteWebhook(accessToken, project.id, webhookId),
|
|
607
|
+
testWebhook: (accessToken, project, webhookId) => admin.triggerTestWebhook(accessToken, project.id, webhookId),
|
|
608
|
+
};
|
|
609
|
+
// ---- Links -----------------------------------------------------------------
|
|
610
|
+
const gitlabLinks = {
|
|
611
|
+
workItemUrl(projectPath, number) {
|
|
612
|
+
if (!projectPath || !Number.isInteger(number) || number <= 0)
|
|
613
|
+
return "";
|
|
614
|
+
return `${config.PLATFORM_URL.replace(/\/$/, "")}/${projectPath}/-/work_items/${number}`;
|
|
615
|
+
},
|
|
616
|
+
};
|
|
617
|
+
// ---- Assembly --------------------------------------------------------------
|
|
618
|
+
export const gitlabPlatform = {
|
|
619
|
+
name: "gitlab",
|
|
620
|
+
ingress: gitlabIngress,
|
|
621
|
+
workItems: gitlabWorkItems,
|
|
622
|
+
changeRequests: gitlabChangeRequests,
|
|
623
|
+
repository: gitlabRepository,
|
|
624
|
+
ci: gitlabCi,
|
|
625
|
+
gitAuth: gitlabGitAuth,
|
|
626
|
+
attachments: gitlabAttachments,
|
|
627
|
+
onboarding: gitlabOnboarding,
|
|
628
|
+
links: gitlabLinks,
|
|
629
|
+
};
|
|
630
|
+
//# sourceMappingURL=index.js.map
|