UNPKG

@aashari/mcp-server-atlassian-bitbucket

Version:

Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MC

87 lines (86 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const atlassian_pullrequests_base_controller_js_1 = require("./atlassian.pullrequests.base.controller.js"); /** * Create a new pull request in Bitbucket * @param options - Options including workspace slug, repo slug, source branch, target branch, title, etc. * @returns Promise with formatted pull request details as Markdown content */ async function add(options) { const methodLogger = atlassian_pullrequests_base_controller_js_1.Logger.forContext('controllers/atlassian.pullrequests.create.controller.ts', 'add'); try { // Apply defaults if needed (none for this operation) const mergedOptions = (0, atlassian_pullrequests_base_controller_js_1.applyDefaults)(options, {}); // Handle optional workspaceSlug - get default if not provided if (!mergedOptions.workspaceSlug) { methodLogger.debug('No workspace provided, fetching default workspace'); const defaultWorkspace = await (0, atlassian_pullrequests_base_controller_js_1.getDefaultWorkspace)(); if (!defaultWorkspace) { throw new Error('Could not determine a default workspace. Please provide a workspaceSlug.'); } mergedOptions.workspaceSlug = defaultWorkspace; methodLogger.debug(`Using default workspace: ${mergedOptions.workspaceSlug}`); } const { workspaceSlug, repoSlug, title, sourceBranch, destinationBranch, description, closeSourceBranch, } = mergedOptions; // Validate required parameters if (!workspaceSlug || !repoSlug || !title || !sourceBranch || !destinationBranch) { throw new Error('Workspace slug, repository slug, title, source branch, and destination branch are required'); } methodLogger.debug(`Creating PR in ${workspaceSlug}/${repoSlug} from ${sourceBranch} to ${destinationBranch}`, { title, descriptionLength: description?.length, closeSourceBranch, }); // Process description - optimize Markdown if provided const optimizedDescription = description ? (0, atlassian_pullrequests_base_controller_js_1.optimizeBitbucketMarkdown)(description) : undefined; // Map controller options to service parameters const serviceParams = { workspace: workspaceSlug, repo_slug: repoSlug, title, source: { branch: { name: sourceBranch, }, }, destination: { branch: { name: destinationBranch, }, }, description: optimizedDescription, close_source_branch: closeSourceBranch, }; // Create the pull request through the service const pullRequestResult = await atlassian_pullrequests_base_controller_js_1.atlassianPullRequestsService.create(serviceParams); methodLogger.debug('Pull request created successfully', { id: pullRequestResult.id, title: pullRequestResult.title, sourceBranch, destinationBranch, }); // Format the pull request details using the formatter const formattedContent = (0, atlassian_pullrequests_base_controller_js_1.formatPullRequestDetails)(pullRequestResult); // Return formatted content with success message return { content: `## Pull Request Created Successfully\n\n${formattedContent}`, }; } catch (error) { // Use the standardized error handler throw (0, atlassian_pullrequests_base_controller_js_1.handleControllerError)(error, { entityType: 'Pull Request', operation: 'creating', source: 'controllers/atlassian.pullrequests.create.controller.ts@add', additionalInfo: { options }, }); } } // Export the controller functions exports.default = { add };