@docupace/pipeline 1.0.61-alpha.0 → 1.0.61

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/src/merge/pr.js DELETED
@@ -1,85 +0,0 @@
1
- /**
2
- * Create a Bitbucket pull request
3
- * @param {string} sourceBranch - Source branch name
4
- * @param {string} targetBranch - Target branch name
5
- * @param {string} title - PR title
6
- * @param {string} description - PR description
7
- * @returns {Promise<Object>} - PR creation result
8
- */
9
- import { execSync } from 'child_process';
10
-
11
- export async function createBitbucketPR(
12
- sourceBranch,
13
- targetBranch,
14
- title,
15
- description,
16
- ) {
17
- try {
18
- // Get Bitbucket workspace and repo from git remote
19
- const remoteUrl = execSync('git config --get remote.origin.url', {
20
- encoding: 'utf-8',
21
- }).trim();
22
- const match = remoteUrl.match(/bitbucket\.org[\/:]([^\/]+)\/([^\/\.]+)/);
23
-
24
- if (!match) {
25
- throw new Error(
26
- 'Could not parse Bitbucket workspace and repository from remote URL',
27
- );
28
- }
29
-
30
- const [, workspace, repoSlug] = match;
31
-
32
- // Check for Bitbucket credentials
33
- const username = process.env.BITBUCKET_USERNAME;
34
- const password = process.env.BITBUCKET_APP_PASSWORD;
35
-
36
- if (!username || !password) {
37
- console.log(
38
- `\n⚠️ Bitbucket credentials not found in environment variables.`,
39
- );
40
- console.log(
41
- 'Please set BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD to auto-create PR.',
42
- );
43
- console.log(
44
- `Manual PR creation URL: https://bitbucket.org/${workspace}/${repoSlug}/pull-requests/new?source=${sourceBranch}&dest=${targetBranch}`,
45
- );
46
- return {
47
- success: false,
48
- manual: true,
49
- url: `https://bitbucket.org/${workspace}/${repoSlug}/pull-requests/new?source=${sourceBranch}&dest=${targetBranch}`,
50
- };
51
- }
52
-
53
- // Create PR via Bitbucket API
54
- const prData = {
55
- title,
56
- description,
57
- source: { branch: { name: sourceBranch } },
58
- destination: { branch: { name: targetBranch } },
59
- };
60
-
61
- const auth = Buffer.from(`${username}:${password}`).toString('base64');
62
- const response = await fetch(
63
- `https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests`,
64
- {
65
- method: 'POST',
66
- headers: {
67
- Authorization: `Basic ${auth}`,
68
- 'Content-Type': 'application/json',
69
- },
70
- body: JSON.stringify(prData),
71
- },
72
- );
73
-
74
- if (!response.ok) {
75
- const error = await response.text();
76
- throw new Error(`Bitbucket API error: ${response.status} - ${error}`);
77
- }
78
-
79
- const pr = await response.json();
80
- return { success: true, pr, url: pr.links.html.href };
81
- } catch (error) {
82
- console.error(`Failed to create Bitbucket PR: ${error.message}`);
83
- return { success: false, error: error.message };
84
- }
85
- }