@docupace/pipeline 1.0.71 → 1.0.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
2
2
  import { readFileSync, existsSync, mkdirSync } from 'fs';
3
3
  import { join, dirname } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
+ import { getExistingPRsWithDescription } from './pr.js';
5
6
 
6
7
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
8
 
@@ -335,7 +336,9 @@ async function processMergeBranch(
335
336
  const finalResults = await runFollowUpPhase(prepareResults, verbose);
336
337
 
337
338
  // Summary
338
- const allPassed = prepareResults.every((r) => r.exitCode === 0);
339
+ const allPassed = prepareResults.every(
340
+ (r) => r.exitCode === 0 || r.exitCode === 4,
341
+ );
339
342
  const mergeFailures = prepareResults.filter((r) => r.exitCode === 2);
340
343
  const buildFailures = prepareResults.filter((r) => r.exitCode === 3);
341
344
  const successes = prepareResults.filter((r) => r.exitCode === 0);
@@ -371,6 +374,27 @@ async function mergeAll(verbose = false) {
371
374
  // Read configuration
372
375
  const config = readMergeConfig(verbose);
373
376
 
377
+ // Check for existing PRs with "Automated merge with changeset" description
378
+ if (verbose) console.log('šŸ” Checking for existing automated merge PRs...');
379
+ const existingPRs = await getExistingPRsWithDescription(
380
+ 'Automated merge with changeset',
381
+ );
382
+
383
+ if (existingPRs.length > 0) {
384
+ console.log(
385
+ `āŒ Found ${existingPRs.length} existing pull request(s) with "Automated merge with changeset" description. Exiting to prevent conflicts.`,
386
+ );
387
+ if (verbose) {
388
+ existingPRs.forEach((pr) => {
389
+ console.log(` - PR #${pr.id}: ${pr.title} (${pr.links.html.href})`);
390
+ });
391
+ }
392
+ process.exit(1);
393
+ }
394
+
395
+ if (verbose)
396
+ console.log('āœ… No existing automated merge PRs found. Proceeding...');
397
+
374
398
  // Setup repos directory
375
399
  const reposDir = join(process.cwd(), 'repos');
376
400
  if (!existsSync(reposDir)) {
package/src/merge/pr.js CHANGED
@@ -8,6 +8,67 @@
8
8
  */
9
9
  import { execSync } from 'child_process';
10
10
 
11
+ /**
12
+ * Check for existing pull requests with specific description pattern
13
+ * @param {string} descriptionPattern - Pattern to match in PR descriptions
14
+ * @returns {Promise<Object[]>} - Array of matching PRs
15
+ */
16
+ export async function getExistingPRsWithDescription(descriptionPattern) {
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. Cannot check existing PRs.`,
39
+ );
40
+ return [];
41
+ }
42
+
43
+ const auth = Buffer.from(`${username}:${password}`).toString('base64');
44
+ const response = await fetch(
45
+ `https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests?state=OPEN`,
46
+ {
47
+ method: 'GET',
48
+ headers: {
49
+ Authorization: `Basic ${auth}`,
50
+ 'Content-Type': 'application/json',
51
+ },
52
+ },
53
+ );
54
+
55
+ if (!response.ok) {
56
+ const error = await response.text();
57
+ throw new Error(`Bitbucket API error: ${response.status} - ${error}`);
58
+ }
59
+
60
+ const data = await response.json();
61
+ const matchingPRs = data.values.filter(pr =>
62
+ pr.description && pr.description.startsWith(descriptionPattern)
63
+ );
64
+
65
+ return matchingPRs;
66
+ } catch (error) {
67
+ console.error(`Failed to get existing PRs: ${error.message}`);
68
+ return [];
69
+ }
70
+ }
71
+
11
72
  export async function createBitbucketPR(
12
73
  sourceBranch,
13
74
  targetBranch,
@@ -20,13 +20,13 @@ export const environmentConfig = {
20
20
  uat: {
21
21
  newUrl: (site) => `https://${site}.uat.dpai.tech`,
22
22
  oldUrl: (site) => `https://uat.paperout.com/${site}`,
23
- docupaceHost: () => 'uat.paperout.com',
23
+ docupaceHost: () => 'www.uat.paperout.com',
24
24
  ccUrl: (site) => `https://${site}-cc.uat.dpai.tech`,
25
25
  },
26
26
  stage: {
27
27
  newUrl: (site) => `https://${site}.stage.dpai.tech`,
28
28
  oldUrl: (site) => `https://stage.paperout.com/${site}`,
29
- docupaceHost: () => 'stage.paperout.com',
29
+ docupaceHost: () => 'www.stage.paperout.com',
30
30
  ccUrl: (site) => `https://${site}-cc.stage.dpai.tech`,
31
31
  },
32
32
  prod: {