@atercates/bitbucket-mcp 1.0.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +347 -0
  3. package/dist/client.d.ts +16 -0
  4. package/dist/client.js +35 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/config.d.ts +11 -0
  7. package/dist/config.js +54 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/handlers/branching-model.d.ts +2 -0
  10. package/dist/handlers/branching-model.js +324 -0
  11. package/dist/handlers/branching-model.js.map +1 -0
  12. package/dist/handlers/commits.d.ts +2 -0
  13. package/dist/handlers/commits.js +78 -0
  14. package/dist/handlers/commits.js.map +1 -0
  15. package/dist/handlers/index.d.ts +17 -0
  16. package/dist/handlers/index.js +29 -0
  17. package/dist/handlers/index.js.map +1 -0
  18. package/dist/handlers/pipelines.d.ts +2 -0
  19. package/dist/handlers/pipelines.js +538 -0
  20. package/dist/handlers/pipelines.js.map +1 -0
  21. package/dist/handlers/pr-comments.d.ts +2 -0
  22. package/dist/handlers/pr-comments.js +509 -0
  23. package/dist/handlers/pr-comments.js.map +1 -0
  24. package/dist/handlers/pr-content.d.ts +2 -0
  25. package/dist/handlers/pr-content.js +332 -0
  26. package/dist/handlers/pr-content.js.map +1 -0
  27. package/dist/handlers/pr-tasks.d.ts +2 -0
  28. package/dist/handlers/pr-tasks.js +275 -0
  29. package/dist/handlers/pr-tasks.js.map +1 -0
  30. package/dist/handlers/pull-requests.d.ts +2 -0
  31. package/dist/handlers/pull-requests.js +902 -0
  32. package/dist/handlers/pull-requests.js.map +1 -0
  33. package/dist/handlers/refs.d.ts +2 -0
  34. package/dist/handlers/refs.js +225 -0
  35. package/dist/handlers/refs.js.map +1 -0
  36. package/dist/handlers/repositories.d.ts +2 -0
  37. package/dist/handlers/repositories.js +131 -0
  38. package/dist/handlers/repositories.js.map +1 -0
  39. package/dist/handlers/source.d.ts +2 -0
  40. package/dist/handlers/source.js +35 -0
  41. package/dist/handlers/source.js.map +1 -0
  42. package/dist/handlers/types.d.ts +42 -0
  43. package/dist/handlers/types.js +2 -0
  44. package/dist/handlers/types.js.map +1 -0
  45. package/dist/handlers/users.d.ts +2 -0
  46. package/dist/handlers/users.js +38 -0
  47. package/dist/handlers/users.js.map +1 -0
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.js +4 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/logger.d.ts +3 -0
  52. package/dist/logger.js +60 -0
  53. package/dist/logger.js.map +1 -0
  54. package/dist/pagination.d.ts +32 -0
  55. package/dist/pagination.js +116 -0
  56. package/dist/pagination.js.map +1 -0
  57. package/dist/schemas.d.ts +21 -0
  58. package/dist/schemas.js +23 -0
  59. package/dist/schemas.js.map +1 -0
  60. package/dist/server.d.ts +33 -0
  61. package/dist/server.js +124 -0
  62. package/dist/server.js.map +1 -0
  63. package/dist/types.d.ts +296 -0
  64. package/dist/types.js +3 -0
  65. package/dist/types.js.map +1 -0
  66. package/dist/utils.d.ts +18 -0
  67. package/dist/utils.js +17 -0
  68. package/dist/utils.js.map +1 -0
  69. package/docs/README.md +216 -0
  70. package/docs/TOOLS.md +464 -0
  71. package/docs/architecture/ARCHITECTURE.md +302 -0
  72. package/docs/guides/ENVIRONMENT_VARIABLES.md +306 -0
  73. package/docs/guides/GETTING_STARTED.md +267 -0
  74. package/docs/guides/GITHUB_ACTIONS_SETUP.md +148 -0
  75. package/docs/guides/NPM_DEPLOYMENT.md +266 -0
  76. package/docs/guides/PROJECT_STRUCTURE.md +317 -0
  77. package/package.json +84 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Matan Yemini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,347 @@
1
+ # Bitbucket MCP Server
2
+
3
+ A Model Context Protocol (MCP) server for integrating with Bitbucket Cloud and Server APIs. This MCP server enables AI assistants like Claude and Cursor to interact with your Bitbucket repositories, pull requests, pipelines, and other resources.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![npm version](https://badge.fury.io/js/bitbucket-mcp.svg)](https://www.npmjs.com/package/bitbucket-mcp)
7
+
8
+ ## Features
9
+
10
+ ✨ **Comprehensive Bitbucket Integration** - 59 tools covering repositories, PRs, branches, commits, pipelines, and more
11
+
12
+ 🔒 **Secure Authentication** - App password tokens or basic auth with granular permission control via Bitbucket
13
+
14
+ 📝 **Well-Documented** - Complete API reference, architecture guides, and deployment instructions in `/docs`
15
+
16
+ 🧪 **Fully Tested** - Comprehensive unit test suite with full tool coverage (Vitest)
17
+
18
+ ⚡ **Modular Design** - Clean, maintainable architecture organized by feature domain (11 handler modules)
19
+
20
+ 🛡️ **Safety First** - Dangerous operations (deletes) require explicit `BITBUCKET_ALLOW_DANGEROUS=true`
21
+
22
+ 🚀 **Production Ready** - Built with pnpm, ESLint, Prettier, and modern TypeScript
23
+
24
+ ## Quick Start
25
+
26
+ ### Installation
27
+
28
+ ```bash
29
+ # Option 1: Global install with NPM
30
+ npm install -g bitbucket-mcp
31
+
32
+ # Option 2: Use with NPX (no installation required)
33
+ npx -y bitbucket-mcp@latest
34
+
35
+ # Option 3: Local development
36
+ git clone <repository>
37
+ cd bitbucket-mcp
38
+ pnpm install
39
+ pnpm build
40
+ pnpm start
41
+ ```
42
+
43
+ ### Configuration
44
+
45
+ Set environment variables before running:
46
+
47
+ ```bash
48
+ # Authentication (choose one method)
49
+ export BITBUCKET_TOKEN="your_app_password"
50
+ # OR
51
+ export BITBUCKET_USERNAME="your_email@example.com"
52
+ export BITBUCKET_PASSWORD="your_app_password"
53
+
54
+ # Basic configuration
55
+ export BITBUCKET_WORKSPACE="my-workspace" # Optional: default workspace
56
+
57
+ # Optional: Enable dangerous operations (delete branch, delete tag, etc.)
58
+ export BITBUCKET_ALLOW_DANGEROUS=true
59
+ ```
60
+
61
+ ### Running the Server
62
+
63
+ ```bash
64
+ # If installed globally
65
+ bitbucket-mcp
66
+
67
+ # If using NPX
68
+ npx -y bitbucket-mcp@latest
69
+
70
+ # If installed locally
71
+ pnpm start
72
+ ```
73
+
74
+ The server will start and listen for MCP protocol connections via stdio.
75
+
76
+ ## Integration with MCP Clients
77
+
78
+ ### Claude / Cursor Configuration
79
+
80
+ Add to your MCP configuration (`.mcp.json` or similar):
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "bitbucket": {
86
+ "command": "bitbucket-mcp",
87
+ "env": {
88
+ "BITBUCKET_TOKEN": "your_app_password",
89
+ "BITBUCKET_WORKSPACE": "my-workspace"
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ Or with npx:
97
+
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "bitbucket": {
102
+ "command": "npx",
103
+ "args": ["-y", "bitbucket-mcp@latest"],
104
+ "env": {
105
+ "BITBUCKET_TOKEN": "your_app_password",
106
+ "BITBUCKET_WORKSPACE": "my-workspace"
107
+ }
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ ## Available Tools
114
+
115
+ The server provides 59 tools organized into 11 categories:
116
+
117
+ | Category | Tools |
118
+ |----------|-------|
119
+ | **Repositories** | List, get, create repositories |
120
+ | **Pull Requests** | Create, approve, merge, decline PRs |
121
+ | **PR Comments** | Create, delete PR comments |
122
+ | **PR Tasks** | Create, update, delete PR tasks (TODOs) |
123
+ | **PR Content** | Get diffs and commits |
124
+ | **Branches & Tags** | List, create, delete branches and tags |
125
+ | **Commits** | List commits and commit details |
126
+ | **Pipelines** | List, run, stop pipeline runs |
127
+ | **Source Code** | Read file content from repositories |
128
+ | **Users** | Get current user and workspace info |
129
+ | **Branching Model** | Get branching strategy configuration |
130
+
131
+ **Complete reference:** See [docs/TOOLS.md](docs/TOOLS.md)
132
+
133
+ ## Environment Variables
134
+
135
+ ### Authentication (Required - one method)
136
+
137
+ - `BITBUCKET_TOKEN` - App password (recommended)
138
+ - OR `BITBUCKET_USERNAME` + `BITBUCKET_PASSWORD` - Basic authentication
139
+
140
+ ### Configuration (Optional)
141
+
142
+ - `BITBUCKET_URL` - API base URL (default: `https://api.bitbucket.org/2.0`)
143
+ - `BITBUCKET_WORKSPACE` - Default workspace name
144
+ - `BITBUCKET_ALLOW_DANGEROUS` - Enable delete operations (default: false)
145
+
146
+ ### Logging (Optional)
147
+
148
+ - `BITBUCKET_LOG_DISABLE` - Disable file logging (default: false)
149
+ - `BITBUCKET_LOG_FILE` - Custom log file path
150
+ - `BITBUCKET_LOG_DIR` - Custom log directory
151
+ - `BITBUCKET_LOG_PER_CWD` - Create per-directory logs (default: false)
152
+
153
+ ## Getting Credentials
154
+
155
+ ### Create Bitbucket App Password
156
+
157
+ 1. Go to https://bitbucket.org/account/settings/app-passwords/
158
+ 2. Click "Create app password"
159
+ 3. Give it a name (e.g., "MCP Server")
160
+ 4. Select permissions:
161
+ - Pipelines: Read
162
+ - Repositories: Read, Write
163
+ - Pull requests: Read, Write
164
+ 5. Copy the generated password
165
+ 6. Set `BITBUCKET_TOKEN` to this password
166
+
167
+ ### Find Your Workspace
168
+
169
+ The workspace name is visible in your Bitbucket URL: `https://bitbucket.org/{workspace}`
170
+
171
+ ## Documentation
172
+
173
+ - **[Getting Started Guide](docs/guides/GETTING_STARTED.md)** - Installation, configuration, and basic usage
174
+ - **[Tools Reference](docs/TOOLS.md)** - Complete API documentation for all 59 tools with examples
175
+ - **[Architecture Guide](docs/architecture/ARCHITECTURE.md)** - Technical design, modular structure, and extension guide
176
+ - **[Environment Variables](docs/guides/ENVIRONMENT_VARIABLES.md)** - Complete reference for all configuration options
177
+ - **[NPM Deployment](docs/guides/NPM_DEPLOYMENT.md)** - Publishing and deployment instructions
178
+ - **[Main Documentation](docs/README.md)** - Overview and quick links
179
+
180
+ ## Development
181
+
182
+ ### Prerequisites
183
+
184
+ - Node.js 18+
185
+ - pnpm (or npm)
186
+
187
+ ### Setup
188
+
189
+ ```bash
190
+ git clone <repository>
191
+ cd bitbucket-mcp
192
+ pnpm install
193
+ ```
194
+
195
+ ### Build
196
+
197
+ ```bash
198
+ pnpm build # Compile TypeScript
199
+ pnpm lint # Run ESLint
200
+ pnpm format # Format with Prettier
201
+ pnpm format:check # Check formatting
202
+ ```
203
+
204
+ ### Testing
205
+
206
+ ```bash
207
+ pnpm test # Run Vitest suite
208
+ pnpm test:watch # Watch mode
209
+ ```
210
+
211
+ ### Running in Development
212
+
213
+ ```bash
214
+ pnpm dev # Run with tsx (watch mode, no build required)
215
+ # OR
216
+ pnpm build && pnpm start
217
+ ```
218
+
219
+ ### MCP Inspector (Debugging)
220
+
221
+ ```bash
222
+ pnpm inspector # Launch interactive MCP inspector to test tools
223
+ ```
224
+
225
+ ## Project Structure
226
+
227
+ ```
228
+ src/
229
+ ├─ index.ts # Entry point
230
+ ├─ server.ts # MCP server orchestration
231
+ ├─ client.ts # Bitbucket API client
232
+ ├─ config.ts # Configuration management
233
+ ├─ logger.ts # File-based logging
234
+ ├─ types.ts # TypeScript definitions
235
+ ├─ schemas.ts # JSON schemas
236
+ ├─ utils.ts # Utilities
237
+ ├─ pagination.ts # Pagination helper
238
+ └─ handlers/ # Feature modules
239
+ ├─ repositories.ts
240
+ ├─ pull-requests.ts
241
+ ├─ pr-comments.ts
242
+ ├─ pr-tasks.ts
243
+ ├─ pr-content.ts
244
+ ├─ refs.ts
245
+ ├─ commits.ts
246
+ ├─ pipelines.ts
247
+ ├─ source.ts
248
+ ├─ users.ts
249
+ ├─ branching-model.ts
250
+ └─ index.ts
251
+
252
+ docs/
253
+ ├─ README.md # Documentation overview
254
+ ├─ TOOLS.md # Tools reference
255
+ ├─ guides/
256
+ │ └─ GETTING_STARTED.md # Setup guide
257
+ └─ architecture/
258
+ └─ ARCHITECTURE.md # Technical design
259
+
260
+ __tests__/
261
+ ├─ test-utils.ts # Test helpers
262
+ └─ handlers/ # Handler tests
263
+ ```
264
+
265
+ ## Architecture
266
+
267
+ The server uses a modular handler-based architecture:
268
+
269
+ ```
270
+ MCP Client → Server → Handler Modules → BitbucketClient → Bitbucket API
271
+ ```
272
+
273
+ Each handler module:
274
+ - Defines tools (names, schemas, descriptions)
275
+ - Implements handlers (async functions)
276
+ - Can mark tools as dangerous
277
+ - Is automatically registered by the server
278
+
279
+ See [docs/architecture/ARCHITECTURE.md](docs/architecture/ARCHITECTURE.md) for details.
280
+
281
+ ## Dangerous Operations
282
+
283
+ Some tools that perform destructive operations are marked as dangerous:
284
+
285
+ - `deletePullRequestComment`
286
+ - `deletePullRequestTask`
287
+ - `deleteBranch`
288
+ - `deleteTag`
289
+
290
+ These require `BITBUCKET_ALLOW_DANGEROUS=true` to use, preventing accidental data loss.
291
+
292
+ ## Troubleshooting
293
+
294
+ ### Authentication Issues
295
+
296
+ ```bash
297
+ # Test your credentials
298
+ curl -X GET https://api.bitbucket.org/2.0/user \
299
+ -u your_username:your_app_password
300
+ ```
301
+
302
+ ### View Logs
303
+
304
+ **macOS:**
305
+ ```bash
306
+ tail -f ~/Library/Logs/bitbucket-mcp/bitbucket.log
307
+ ```
308
+
309
+ **Linux:**
310
+ ```bash
311
+ tail -f ~/.local/state/bitbucket-mcp/bitbucket.log
312
+ ```
313
+
314
+ **Windows:**
315
+ ```bash
316
+ Get-Content -Path "$env:LOCALAPPDATA\bitbucket-mcp\bitbucket.log" -Tail 50 -Wait
317
+ ```
318
+
319
+ ### Self-Hosted Bitbucket
320
+
321
+ For self-hosted Bitbucket Server, set the API URL:
322
+
323
+ ```bash
324
+ BITBUCKET_URL=https://bitbucket.mycompany.com/rest/api/2.0 bitbucket-mcp
325
+ ```
326
+
327
+ ## License
328
+
329
+ MIT License - See [LICENSE](LICENSE) file for details.
330
+
331
+ ## Support
332
+
333
+ - 📖 See [docs/guides/GETTING_STARTED.md](docs/guides/GETTING_STARTED.md) for setup help
334
+ - 🔧 Check [docs/TOOLS.md](docs/TOOLS.md) for tool documentation with examples
335
+ - 🏗️ Review [docs/architecture/ARCHITECTURE.md](docs/architecture/ARCHITECTURE.md) for technical details
336
+ - ⚙️ Check [docs/guides/ENVIRONMENT_VARIABLES.md](docs/guides/ENVIRONMENT_VARIABLES.md) for all configuration options
337
+ - 🚀 See [docs/guides/NPM_DEPLOYMENT.md](docs/guides/NPM_DEPLOYMENT.md) for deployment to NPM
338
+ - 🐛 Enable logging with `BITBUCKET_LOG_DISABLE=false` for debugging
339
+ - 📝 Check [docs/README.md](docs/README.md) for complete documentation index
340
+
341
+ ---
342
+
343
+ **Version:** 5.0.6
344
+ **Last Updated:** January 2025
345
+ **Architecture:** Modular handler-based design with 11 feature modules
346
+ **Test Framework:** Vitest
347
+ **Package Manager:** pnpm
@@ -0,0 +1,16 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { BitbucketPaginator } from "./pagination.js";
3
+ import { BitbucketConfig } from "./types.js";
4
+ /**
5
+ * Bitbucket API client that wraps axios and provides paginator support
6
+ */
7
+ export declare class BitbucketClient {
8
+ readonly api: AxiosInstance;
9
+ readonly config: BitbucketConfig;
10
+ readonly paginator: BitbucketPaginator;
11
+ constructor(config: BitbucketConfig);
12
+ /**
13
+ * Resolves workspace from argument or falls back to default config
14
+ */
15
+ resolveWorkspace(workspace?: string): string;
16
+ }
package/dist/client.js ADDED
@@ -0,0 +1,35 @@
1
+ import axios from "axios";
2
+ import { BitbucketPaginator } from "./pagination.js";
3
+ import { logger } from "./logger.js";
4
+ /**
5
+ * Bitbucket API client that wraps axios and provides paginator support
6
+ */
7
+ export class BitbucketClient {
8
+ constructor(config) {
9
+ this.config = config;
10
+ // Setup Axios instance
11
+ const headers = {};
12
+ if (config.token) {
13
+ headers.Authorization = `Bearer ${config.token}`;
14
+ }
15
+ this.api = axios.create({
16
+ baseURL: config.baseUrl,
17
+ headers,
18
+ auth: config.username && config.password
19
+ ? { username: config.username, password: config.password }
20
+ : undefined,
21
+ });
22
+ this.paginator = new BitbucketPaginator(this.api, logger);
23
+ }
24
+ /**
25
+ * Resolves workspace from argument or falls back to default config
26
+ */
27
+ resolveWorkspace(workspace) {
28
+ const resolved = workspace || this.config.defaultWorkspace;
29
+ if (!resolved) {
30
+ throw new Error("Workspace must be provided either as a parameter or through BITBUCKET_WORKSPACE environment variable");
31
+ }
32
+ return resolved;
33
+ }
34
+ }
35
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,OAAO,eAAe;IAK1B,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,uBAAuB;QACvB,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,aAAa,GAAG,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO;YACP,IAAI,EACF,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ;gBAChC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE;gBAC1D,CAAC,CAAC,SAAS;SAChB,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,SAAkB;QACjC,MAAM,QAAQ,GAAG,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;QACJ,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { BitbucketConfig } from "./types.js";
2
+ /**
3
+ * Normalize Bitbucket configuration for backward compatibility and DX.
4
+ * Handles URL normalization and workspace extraction from web URLs.
5
+ */
6
+ export declare function normalizeBitbucketConfig(rawConfig: BitbucketConfig): BitbucketConfig;
7
+ /**
8
+ * Load Bitbucket configuration from environment variables.
9
+ * Reads all relevant BITBUCKET_* env vars and returns a normalized config.
10
+ */
11
+ export declare function loadConfigFromEnv(): BitbucketConfig;
package/dist/config.js ADDED
@@ -0,0 +1,54 @@
1
+ import { isTruthyEnv } from "./logger.js";
2
+ /**
3
+ * Normalize Bitbucket configuration for backward compatibility and DX.
4
+ * Handles URL normalization and workspace extraction from web URLs.
5
+ */
6
+ export function normalizeBitbucketConfig(rawConfig) {
7
+ const normalizedConfig = { ...rawConfig };
8
+ try {
9
+ const parsed = new URL(rawConfig.baseUrl);
10
+ const host = parsed.hostname.toLowerCase();
11
+ // If users provide a web URL like https://bitbucket.org/<workspace>,
12
+ // extract the workspace and switch to the public API base URL
13
+ if (host === "bitbucket.org" || host === "www.bitbucket.org") {
14
+ const segments = parsed.pathname.split("/").filter(Boolean);
15
+ if (!normalizedConfig.defaultWorkspace && segments.length >= 1) {
16
+ normalizedConfig.defaultWorkspace = segments[0];
17
+ }
18
+ normalizedConfig.baseUrl = "https://api.bitbucket.org/2.0";
19
+ }
20
+ // If users provide https://api.bitbucket.org (without /2.0), ensure /2.0
21
+ if (host === "api.bitbucket.org") {
22
+ const pathname = parsed.pathname.replace(/\/+$/, "");
23
+ if (!pathname.startsWith("/2.0")) {
24
+ normalizedConfig.baseUrl = "https://api.bitbucket.org/2.0";
25
+ }
26
+ else {
27
+ normalizedConfig.baseUrl = "https://api.bitbucket.org/2.0";
28
+ }
29
+ }
30
+ // Remove trailing slashes for a consistent axios baseURL
31
+ normalizedConfig.baseUrl = normalizedConfig.baseUrl.replace(/\/+$/, "");
32
+ }
33
+ catch {
34
+ // If baseUrl is not a valid absolute URL, keep as-is (custom/self-hosted cases)
35
+ }
36
+ return normalizedConfig;
37
+ }
38
+ /**
39
+ * Load Bitbucket configuration from environment variables.
40
+ * Reads all relevant BITBUCKET_* env vars and returns a normalized config.
41
+ */
42
+ export function loadConfigFromEnv() {
43
+ const initialConfig = {
44
+ baseUrl: process.env.BITBUCKET_URL || "https://api.bitbucket.org/2.0",
45
+ token: process.env.BITBUCKET_TOKEN,
46
+ username: process.env.BITBUCKET_USERNAME,
47
+ password: process.env.BITBUCKET_PASSWORD,
48
+ defaultWorkspace: process.env.BITBUCKET_WORKSPACE,
49
+ allowDangerousCommands: isTruthyEnv(process.env.BITBUCKET_ENABLE_DANGEROUS) ||
50
+ isTruthyEnv(process.env.BITBUCKET_ALLOW_DANGEROUS),
51
+ };
52
+ return normalizeBitbucketConfig(initialConfig);
53
+ }
54
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAA0B;IACjE,MAAM,gBAAgB,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAE3C,qEAAqE;QACrE,8DAA8D;QAC9D,IAAI,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;YAC7D,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5D,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBAC/D,gBAAgB,CAAC,gBAAgB,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAClD,CAAC;YACD,gBAAgB,CAAC,OAAO,GAAG,+BAA+B,CAAC;QAC7D,CAAC;QAED,yEAAyE;QACzE,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACrD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjC,gBAAgB,CAAC,OAAO,GAAG,+BAA+B,CAAC;YAC7D,CAAC;iBAAM,CAAC;gBACN,gBAAgB,CAAC,OAAO,GAAG,+BAA+B,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,yDAAyD;QACzD,gBAAgB,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,gFAAgF;IAClF,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,aAAa,GAAoB;QACrC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,+BAA+B;QACrE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAClC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;QACxC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;QACxC,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;QACjD,sBAAsB,EACpB,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;YACnD,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;KACrD,CAAC;IAEF,OAAO,wBAAwB,CAAC,aAAa,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { HandlerModule } from "./types.js";
2
+ export declare const branchingModelModule: HandlerModule;