@atlassian-dc-mcp/bitbucket 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { initializeRuntimeConfig } from '@atlassian-dc-mcp/common';
1
5
  import { BitbucketService } from '../bitbucket-service.js';
2
6
  import { PullRequestsService } from '../bitbucket-client/index.js';
3
7
 
@@ -67,12 +71,25 @@ function createComment(overrides: Record<string, unknown> = {}) {
67
71
 
68
72
  describe('BitbucketService token optimization paths', () => {
69
73
  let service: BitbucketService;
74
+ let tempHome: string;
75
+ let homedirSpy: jest.SpyInstance;
76
+ const originalPlatform = process.platform;
70
77
 
71
78
  beforeEach(() => {
79
+ tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'bitbucket-token-opt-home-'));
80
+ homedirSpy = jest.spyOn(os, 'homedir').mockReturnValue(tempHome);
81
+ Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });
82
+ initializeRuntimeConfig();
72
83
  service = new BitbucketService('test-host', 'test-token');
73
84
  jest.clearAllMocks();
74
85
  });
75
86
 
87
+ afterEach(() => {
88
+ homedirSpy.mockRestore();
89
+ Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
90
+ fs.rmSync(tempHome, { recursive: true, force: true });
91
+ });
92
+
76
93
  describe('getPullRequestCommentsAndActions', () => {
77
94
  const mockActivityResponse = {
78
95
  isLastPage: false,
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { OpenAPI, ProjectService, PullRequestsService, RepositoryService } from './bitbucket-client/index.js';
3
3
  import { request as __request } from './bitbucket-client/core/request.js';
4
- import { handleApiOperation } from '@atlassian-dc-mcp/common';
4
+ import { handleApiOperation, resolveOpenApiBase } from '@atlassian-dc-mcp/common';
5
5
  import { simplifyInboxPullRequests } from './inbox-pr-mapper.js';
6
6
  import { getDefaultPageSize, getMissingConfig } from './config.js';
7
7
  import {
@@ -29,17 +29,15 @@ export class BitbucketService {
29
29
  constructor(
30
30
  host: string | undefined,
31
31
  token: string | (() => string | undefined),
32
- fullBaseUrl?: string,
32
+ apiBasePath?: string,
33
33
  getPageSize: () => number = getDefaultPageSize,
34
34
  ) {
35
- if (fullBaseUrl) {
36
- OpenAPI.BASE = fullBaseUrl;
37
- } else if (host) {
38
- OpenAPI.BASE = `https://${host}/rest`;
39
- } else {
40
- throw new Error('Either host or fullBaseUrl must be provided');
41
- }
42
-
35
+ OpenAPI.BASE = resolveOpenApiBase({
36
+ host,
37
+ apiBasePath,
38
+ defaultBasePath: '/rest',
39
+ strippableSuffixes: ['/api/1.0', '/api/latest'],
40
+ });
43
41
  OpenAPI.TOKEN = resolveToken(token, 'Missing required environment variable: BITBUCKET_API_TOKEN');
44
42
  OpenAPI.VERSION = '1.0';
45
43
  this.getPageSize = getPageSize;
package/src/config.ts CHANGED
@@ -12,7 +12,7 @@ export const BITBUCKET_PRODUCT: ProductDefinition = {
12
12
  token: 'BITBUCKET_API_TOKEN',
13
13
  defaultPageSize: 'BITBUCKET_DEFAULT_PAGE_SIZE',
14
14
  },
15
- defaultApiBasePath: '/rest/api/1.0',
15
+ defaultApiBasePath: '/rest',
16
16
  };
17
17
 
18
18
  export function getBitbucketRuntimeConfig() {