@docupace/pipeline 1.0.83 → 1.0.85

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.83",
3
+ "version": "1.0.85",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
package/src/next/cli.js CHANGED
@@ -89,11 +89,19 @@ program
89
89
  .requiredOption('-t, --to-env <toEnv>', 'Target environment')
90
90
  .requiredOption('-F, --from-site <fromSite>', 'Source site')
91
91
  .requiredOption('-T, --to-site <toSite>', 'Target site')
92
+ .option('-j, --jira-ticket [jiraTicket]', 'JIRA ticket (optional)')
92
93
  .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
93
94
  .option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
94
95
  .action(async (options) => {
95
- const { fromEnv, fromSite, toEnv, toSite, deployCore, deployConnect } =
96
- options;
96
+ const {
97
+ fromEnv,
98
+ fromSite,
99
+ toEnv,
100
+ toSite,
101
+ deployCore,
102
+ deployConnect,
103
+ jiraTicket,
104
+ } = options;
97
105
  await deployFromSite(
98
106
  fromEnv,
99
107
  fromSite,
@@ -101,6 +109,7 @@ program
101
109
  toSite,
102
110
  deployCore,
103
111
  deployConnect,
112
+ jiraTicket,
104
113
  );
105
114
  });
106
115
 
@@ -9,6 +9,7 @@ import { appInfo, environmentConfig, getRepUrl } from './config.js';
9
9
  import { copy2 } from './copy.js';
10
10
  import { gitDescribeToSemver } from './git-to-semver.js';
11
11
  import { deployConnect, deployCore } from './jenkins.js';
12
+ import { makeJiraRequest } from './jira.js';
12
13
 
13
14
  /**
14
15
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -557,7 +558,73 @@ export async function deployFromSite(
557
558
  toSite,
558
559
  isDeployCore,
559
560
  isDeployConnect,
561
+ jiraTicket,
560
562
  ) {
563
+ console.log(
564
+ `Deploying changes from ${fromSite} in ${fromEnv} to ${toSite} in ${toEnv}${jiraTicket ? ` approved by JIRA ticket ${jiraTicket}` : ''}`,
565
+ );
566
+
567
+ if (jiraTicket) {
568
+ try {
569
+ const response = await makeJiraRequest(`/rest/api/2/issue/${jiraTicket}`);
570
+ const docupacecInstance = response.fields.customfield_10045.value;
571
+ const siteUrl = response.fields.customfield_10041;
572
+ const status = response.fields.status.name;
573
+ const jiraBaseUrl = response.self.split('/rest/api')[0];
574
+ const jiraTicketUrl = `${jiraBaseUrl}/browse/${response.key}`;
575
+
576
+ console.log(`Docupace Instance: ${docupacecInstance}`);
577
+ console.log(`Docupace Site URL: ${siteUrl}`);
578
+ console.log(`JIRA Ticket Status: ${status}`);
579
+ console.log(`JIRA Ticket URL: ${jiraTicketUrl}`);
580
+
581
+ const allowedStatuses = ['To Do', 'In Progress'];
582
+ if (!allowedStatuses.includes(status)) {
583
+ console.error(
584
+ `The JIRA ticket status must be "To Do" or "In Progress", but got "${status}"`,
585
+ );
586
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
587
+ process.exit(1);
588
+ }
589
+
590
+ if (!siteUrl.includes(toSite)) {
591
+ console.error(
592
+ `The toSite "${toSite}" must be present in the Docupace Site URL: "${siteUrl}"`,
593
+ );
594
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
595
+ process.exit(1);
596
+ }
597
+
598
+ if (toEnv === 'prod') {
599
+ if (docupacecInstance !== 'Production') {
600
+ console.error(
601
+ `The deployment to prod environment requires Docupace Instance to be "Production", but got "${docupacecInstance}"`,
602
+ );
603
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
604
+ process.exit(1);
605
+ }
606
+
607
+ if (fromSite !== toSite) {
608
+ console.error(
609
+ `The deployment to prod environment requires fromSite and toSite to be equal, but fromSite: "${fromSite}", toSite: "${toSite}"`,
610
+ );
611
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
612
+ process.exit(1);
613
+ }
614
+
615
+ console.log('Production deployment validations passed');
616
+ }
617
+ } catch (error) {
618
+ console.error(`Failed to make a Jira request: ${error.message}`);
619
+ process.exit(1);
620
+ }
621
+ } else if (toEnv === 'prod') {
622
+ console.error(
623
+ 'The deployment to prod environment requires a JIRA ticket to be provided',
624
+ );
625
+ process.exit(1);
626
+ }
627
+
561
628
  if (isDeployCore === 'true') {
562
629
  const branchName = await getCoreBranchName(fromEnv, fromSite);
563
630