@docupace/pipeline 1.0.1-2.ervinsUpdate2.5 → 1.0.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.
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.12.ervinsUpdate2.5",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "dp-changeset-cli": "src/changeset/cli.js",
9
- "dp-next-cli": "src/next/cli.js",
10
- "dp-auth0-cli": "src/auth0/cli.js"
9
+ "dp-next-cli": "src/next/cli.js"
11
10
  },
12
11
  "keywords": [
13
12
  "bash"
@@ -16,28 +15,14 @@
16
15
  "license": "ISC",
17
16
  "dependencies": {
18
17
  "@changesets/cli": "^2.27.10",
19
- "auth0-deploy-cli": "^7.24.3",
20
- "axios": "^1.7.9",
21
18
  "commander": "^12.1.0",
22
19
  "dotenv": "^16.4.7",
23
20
  "js-yaml": "^4.1.0",
24
- "lodash": "^4.17.21",
25
21
  "openai": "^4.76.3",
26
22
  "zod": "^3.24.1",
27
- "zx": "^8.3.0"
23
+ "zx": "^8.2.4"
28
24
  },
29
25
  "devDependencies": {
30
- "@eslint/js": "^9.17.0",
31
- "esbuild": "^0.24.0",
32
- "eslint": "^9.17.0",
33
- "eslint-config-prettier": "^9.1.0",
34
- "eslint-plugin-prettier": "^5.2.1",
35
- "globals": "^15.14.0",
36
- "prettier": "^3.4.2"
37
- },
38
- "scripts": {
39
- "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
40
- "test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template --deploy-core true",
41
- "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa"
26
+ "esbuild": "^0.24.0"
42
27
  }
43
28
  }
@@ -2,71 +2,47 @@
2
2
  import { Command } from 'commander';
3
3
  import { $ } from 'zx';
4
4
  import path from 'path';
5
- import { validateChangesets } from './validate.js';
5
+ import {validateChangesets} from "./validate.js";
6
6
  import fs from 'fs';
7
- import OpenAI from 'openai';
8
- import { zodResponseFormat } from 'openai/helpers/zod';
9
- import z from 'zod';
7
+ import OpenAI from "openai";
8
+ import {zodResponseFormat} from "openai/helpers/zod";
9
+ import z from 'zod'
10
10
  import dotenv from 'dotenv';
11
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
12
- import { exec } from 'child_process';
11
+ dotenv.config({path : ['.env.pipeline.local', 'config/.env.pipeline.local']});
13
12
 
14
13
  const program = new Command();
15
14
 
16
15
  const args = process.argv;
17
16
 
18
- async function createChangesetDirectory() {
19
- try {
20
- // Use path.join to build a safe path to `.changeset`
21
- const targetDir = path.join(process.cwd(), '.changeset');
22
-
23
- // Create the directory recursively if it doesn't exist
24
- await fs.promises.mkdir(targetDir, { recursive: true });
25
- } catch (error) {
26
- console.error('Error creating .changeset directory:', error);
27
- }
28
- }
29
-
30
-
31
- function run(command) {
32
- return new Promise((resolve, reject) => {
33
- exec(command, { shell: true }, (error, stdout, stderr) => {
34
- if (error) {
35
- reject(error);
36
- } else {
37
- resolve({ stdout, stderr });
38
- }
39
- });
40
- });
41
- }
17
+ const DIR = path.resolve(process.cwd());
42
18
 
43
19
  async function fileExists(filePath) {
44
- try {
45
- await fs.promises.access(filePath);
46
- return true;
47
- } catch {
48
- return false;
49
- }
20
+ try {
21
+ await fs.promises.access(filePath);
22
+ return true;
23
+ } catch {
24
+ return false;
25
+ }
50
26
  }
51
27
 
52
28
  async function getMainPackage() {
53
- const mainModulePath = process.cwd();
54
- if (mainModulePath) {
55
- const packageJsonPath = path.join(mainModulePath, 'package.json');
56
- if (await fileExists(packageJsonPath)) {
57
- const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
58
- const packageJson = JSON.parse(fileContent);
59
- return packageJson;
29
+ const mainModulePath = process.env.PWD;
30
+ if (mainModulePath) {
31
+ const packageJsonPath = path.join(mainModulePath, 'package.json');
32
+ if (await fileExists(packageJsonPath)) {
33
+ const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
34
+ const packageJson = JSON.parse(fileContent);
35
+ return packageJson;
36
+ }
60
37
  }
61
- }
62
- throw new Error('Main package.json not found');
38
+ throw new Error('Main package.json not found');
63
39
  }
64
40
 
65
41
  // Helper function to set Git info
66
42
  async function setGitInfo() {
67
- await $`git config --global user.email "gitops@docupace.com"`;
68
- await $`git config --global user.name "Gitops"`;
69
- await $`git remote set-url origin https://${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
43
+ await $`git config --global user.email "gitops@docupace.com"`;
44
+ await $`git config --global user.name "Gitops"`;
45
+ await $`git remote set-url origin https://x-token-auth:${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
70
46
  }
71
47
 
72
48
  const changeSetPackage = `{
@@ -84,198 +60,176 @@ const changeSetPackage = `{
84
60
  "@changesets/cli": "^2.27.10"
85
61
  }
86
62
  }
87
- `;
63
+ `
88
64
 
89
65
  async function versionCommand() {
90
- console.log('📦 Running Changeset versioning...');
91
- await setGitInfo();
92
- await $`mv package.json package.json.bak`;
93
- await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
94
- await fs.promises.writeFile('package.json', changeSetPackage);
95
- await $`pnpm install`;
96
- await $`rm package.json pnpm-lock.yaml`;
97
- await $`mv package.json.bak package.json`;
98
- await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
99
- await $`pnpm changeset version`;
100
- console.log('✅ Changeset versioning complete.');
66
+ console.log('📦 Running Changeset versioning...');
67
+ await setGitInfo();
68
+ await $`mv package.json package.json.bak`
69
+ await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`
70
+ await fs.promises.writeFile('package.json', changeSetPackage);
71
+ await $`pnpm install`;
72
+ await $`rm package.json pnpm-lock.yaml`
73
+ await $`mv package.json.bak package.json`
74
+ await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`
75
+ await $`pnpm changeset version`;
76
+ console.log('✅ Changeset versioning complete.');
101
77
  }
102
78
 
103
79
  async function commitTagCommand() {
104
- console.log('📌 Checking for updates to commit...');
105
-
106
- // Check if there are changes to commit
107
- const status = (await $`git status --porcelain`).stdout.trim();
108
- if (!status) {
109
- console.log('✅ No changes to commit. Exiting.');
110
- return;
111
- }
112
-
113
- console.log('📌 Committing and tagging the new version...');
114
- await setGitInfo();
115
- await $`git add .`;
116
- const newVersion = (
117
- await $`node -p "require('./package.json').version"`
118
- ).stdout.trim();
119
- await $`git commit -m "Version bump to ${newVersion} and changelog"`;
120
- await $`git push origin`;
121
- await $`git tag v${newVersion}`;
122
- await $`git push origin --tags`;
123
- console.log(`✅ Version ${newVersion} tagged and pushed.`);
80
+ console.log('📌 Committing and tagging the new version...');
81
+ await setGitInfo();
82
+ await $`git add .`;
83
+ const newVersion = (await $`node -p "require('./package.json').version"`).stdout.trim();
84
+ await $`git commit -m "Version bump to ${newVersion} and changelog"`;
85
+ await $`git push origin`;
86
+ await $`git tag v${newVersion}`;
87
+ await $`git push origin --tags`;
88
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
124
89
  }
125
90
 
126
91
  // Command: validate
127
92
  program
128
- .command('validate <path>')
129
- .description('Validate changesets for the provided PR')
130
- .action(async (path) => {
131
- if (!process.env.BITBUCKET_PR_ID) {
132
- return;
133
- }
134
- console.log('🔍 Validating changesets...');
135
- try {
136
- await validateChangesets(path);
137
- console.log('✅ Changeset validation passed.');
138
- } catch (error) {
139
- console.error(
140
- '❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next',
141
- );
142
- process.exit(1);
143
- }
144
- });
93
+ .command('validate <path>')
94
+ .description('Validate changesets for the provided PR')
95
+ .action(async (path) => {
96
+ if(!process.env.BITBUCKET_PR_ID) {
97
+ return;
98
+ }
99
+ console.log('🔍 Validating changesets...');
100
+ try {
101
+ await validateChangesets(path);
102
+ console.log('✅ Changeset validation passed.');
103
+ } catch (error) {
104
+ console.error(
105
+ '❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next'
106
+ );
107
+ process.exit(1);
108
+ }
109
+ });
145
110
  // Command: version
146
111
  program
147
- .command('version')
148
- .description('Run Changeset versioning')
149
- .action(async () => {
150
- await versionCommand();
151
- });
112
+ .command('version')
113
+ .description('Run Changeset versioning')
114
+ .action(async () => {
115
+ await versionCommand();
116
+ });
152
117
 
153
118
  // Command: commit-and-tag
154
119
  program
155
- .command('commit-tag')
156
- .description('Commit and tag the new version')
157
- .action(async () => {
158
- await commitTagCommand();
159
- });
120
+ .command('commit-tag')
121
+ .description('Commit and tag the new version')
122
+ .action(async () => {
123
+ await commitTagCommand();
124
+ });
160
125
 
161
126
  // Command: all
162
127
  program
163
- .command('version-commit-tag')
164
- .description('Run versioning and commit-and-tag in sequence')
165
- .action(async () => {
166
- console.log('📦 Running all steps...');
167
- await versionCommand();
168
- await commitTagCommand();
169
- });
128
+ .command('version-commit-tag')
129
+ .description('Run versioning and commit-and-tag in sequence')
130
+ .action(async () => {
131
+ console.log('📦 Running all steps...');
132
+ await versionCommand();
133
+ await commitTagCommand();
134
+ });
170
135
 
171
136
  program
172
- .name('create-changeset')
173
- .description(
174
- 'Creates a changeset based on the current branch and Jira ticket information',
175
- )
176
- .action(async () => {
177
- const mainPackage = await getMainPackage();
178
- const componentName = mainPackage.name;
179
-
180
- try {
181
- // Step 1: Get the current branch name
182
- const { stdout: branchStdout } = await run(`git branch --show-current`);
183
- const branchName = branchStdout.trim();
184
- console.log(`Current branch: ${branchName}`);
185
-
186
- // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
187
- const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
188
- if (!jiraTicketMatch) {
189
- throw new Error('No Jira ticket found in the branch name.');
190
- }
191
- const jiraTicketId = jiraTicketMatch[0];
192
-
193
- // Step 3: Fetch Jira ticket information
194
- const jiraBaseUrl = 'https://docupacellc.atlassian.net';
195
- const jiraEmail = process.env.JIRA_API_EMAIL;
196
- const jiraApiKey = process.env.JIRA_API_KEY;
197
- const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
198
- const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
199
- const jiraResponse = await fetch(jiraUrl, {
200
- headers: {
201
- Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
202
- 'Content-Type': 'application/json',
203
- },
204
- });
205
-
206
- if (!jiraResponse.ok) {
207
- throw new Error(
208
- `Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
209
- );
210
- }
211
- const jiraTicketData = await jiraResponse.json();
212
-
213
- if (jiraTicketData.fields.customfield_10107?.value !== 'Product') {
214
- throw new Error('Issue Type of Work must be Product');
215
- }
216
-
217
- const jiraSummary = jiraTicketData.fields.summary;
218
-
219
- console.log(
220
- `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
221
- );
222
-
223
- // Step 4: Use OpenAI to generate release notes
224
- const openaiClient = new OpenAI({
225
- apiKey: process.env['OPENAI_API_KEY'],
226
- });
227
-
228
- const ChangeRequestSchema = z.object({
229
- change_type: z.enum(['patch', 'minor']),
230
- summary: z.string(),
231
- jira_ticket_id: z.string(),
232
- });
233
-
234
- const openAiResponse = await openaiClient.chat.completions.create({
235
- model: 'gpt-4o-mini',
236
- messages: [
237
- {
238
- role: 'system',
239
- content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
240
- },
241
- {
242
- role: 'user',
243
- content: JSON.stringify(jiraTicketData),
244
- },
245
- ],
246
- response_format: zodResponseFormat(
247
- ChangeRequestSchema,
248
- 'changeset_schema',
249
- ),
250
- temperature: 0,
251
- });
252
-
253
- const assistantResponse = openAiResponse.choices[0].message.content;
254
- const parsedResponse = JSON.parse(assistantResponse);
255
-
256
- const { change_type, summary } = parsedResponse;
257
- console.log(`Change type: ${change_type}`);
258
- console.log(`Release note: ${summary}`);
259
-
260
- // Step 5: Create a changeset .md file
261
- const changesetContent = `---
137
+ .name('create-changeset')
138
+ .description('Creates a changeset based on the current branch and Jira ticket information')
139
+ .action(async () => {
140
+ const mainPackage = await getMainPackage();
141
+ const componentName = mainPackage.name;
142
+
143
+ try {
144
+ // Step 1: Get the current branch name
145
+ const branchName = (await $`git branch --show-current`).stdout.trim();
146
+ console.log(`Current branch: ${branchName}`);
147
+
148
+ // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
149
+ const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
150
+ if (!jiraTicketMatch) {
151
+ throw new Error('No Jira ticket found in the branch name.');
152
+ }
153
+ const jiraTicketId = jiraTicketMatch[0];
154
+
155
+ // Step 3: Fetch Jira ticket information
156
+ const jiraBaseUrl = 'https://docupacellc.atlassian.net';
157
+ const jiraEmail = process.env.JIRA_API_EMAIL;
158
+ const jiraApiKey = process.env.JIRA_API_KEY;
159
+ const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
160
+ const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
161
+ const jiraResponse = await fetch(jiraUrl, {
162
+ headers: {
163
+ Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
164
+ 'Content-Type': 'application/json',
165
+ },
166
+ });
167
+
168
+ if (!jiraResponse.ok) {
169
+ throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
170
+ }
171
+ const jiraTicketData = await jiraResponse.json();
172
+
173
+ if(jiraTicketData.fields.customfield_10107?.value !== 'Product') {
174
+ throw new Error("Issue Type of Work must be Product")
175
+ }
176
+
177
+ const jiraSummary = jiraTicketData.fields.summary;
178
+
179
+ console.log(`Generating release notes for ${jiraTicketId} - ${jiraSummary}`)
180
+
181
+ const openaiClient = new OpenAI({
182
+ apiKey: process.env['OPENAI_API_KEY'],
183
+ });
184
+
185
+ const ChangeRequestSchema = z.object({
186
+ change_type: z.enum(["patch", "minor"]),
187
+ summary: z.string(),
188
+ jira_ticket_id: z.string(),
189
+ });
190
+
191
+ const openAiResponse = await openaiClient.chat.completions.create({
192
+ model: "gpt-4o-mini",
193
+ messages: [
194
+ {
195
+ role: "system",
196
+ content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
197
+ },
198
+ {
199
+ role: "user",
200
+ content: JSON.stringify(jiraTicketData),
201
+ },
202
+ ],
203
+ response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
204
+ temperature: 0
205
+ });
206
+
207
+ const assistantResponse = openAiResponse.choices[0].message.content;
208
+ const parsedResponse = JSON.parse(assistantResponse);
209
+
210
+ const { change_type, summary } = parsedResponse;
211
+ console.log(`Change type: ${change_type}`);
212
+ console.log(`Release note: ${summary}`);
213
+
214
+ // Step 5: Create a changeset using pnpm
215
+ const changesetContent = `---
262
216
  "${componentName}": ${change_type}
263
217
  ---
264
218
 
265
219
  ${summary} [${jiraTicketId}]
266
- `;
267
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
220
+ `;
221
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
268
222
 
269
- await createChangesetDirectory();
270
- await fs.promises.writeFile(changesetFile, changesetContent);
271
- console.log(`Created changeset file at ${changesetFile}`);
223
+ await $`mkdir -p ./.changeset`;
224
+ await fs.promises.writeFile(changesetFile, changesetContent);
225
+ console.log(`Created changeset file at ${changesetFile}`);
226
+
227
+ console.log('Done!');
228
+ } catch (err) {
229
+ console.error(`Error: ${err.message}`);
230
+ }
231
+ });
272
232
 
273
- console.log('Done!');
274
- } catch (err) {
275
- console.error(`Error: ${err.message}`);
276
- process.exit(1);
277
- }
278
- });
279
233
 
280
234
  // Parse arguments
281
235
  program.parse(args);
@@ -2,46 +2,43 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
4
  export async function validateChangesets(directoryPath) {
5
- try {
6
- // Step 1: Read the directory for md files excluding README.md
7
- const allFiles = fs.readdirSync(directoryPath);
8
- const mdFiles = allFiles.filter(
9
- (file) => file.endsWith('.md') && file !== 'README.md',
10
- );
11
-
12
- // Step 2: Check for pre.json and parse it
13
- const preJsonPath = path.join(directoryPath, 'pre.json');
14
- let preJson;
15
-
16
- if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
17
- throw new Error('Error: No pre.json and no md files found.');
18
- }
5
+ try {
6
+ // Step 1: Read the directory for md files excluding README.md
7
+ const allFiles = fs.readdirSync(directoryPath);
8
+ const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
9
+
10
+ // Step 2: Check for pre.json and parse it
11
+ const preJsonPath = path.join(directoryPath, 'pre.json');
12
+ let preJson;
19
13
 
20
- if (fs.existsSync(preJsonPath)) {
21
- preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
14
+ if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
15
+ throw new Error("Error: No pre.json and no md files found.")
16
+ }
22
17
 
23
- if (preJson.mode == 'pre') {
24
- // Step 4a: Get list of changesets from pre.json
25
- const changesets = preJson.changesets || [];
26
- const changesetNames = changesets.map((change) => change);
18
+ if (fs.existsSync(preJsonPath)) {
19
+ preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
27
20
 
28
- // Step 4b: Match files with the list of changesets
29
- const mdFileNamesWithoutExt = mdFiles.map((file) =>
30
- path.basename(file, '.md'),
31
- );
32
- const unmatchedFiles = mdFileNamesWithoutExt.filter(
33
- (fileName) => !changesetNames.includes(fileName),
34
- );
21
+ if(preJson.mode == 'pre') {
22
+ // Step 4a: Get list of changesets from pre.json
23
+ const changesets = preJson.changesets || [];
24
+ const changesetNames = changesets.map(change => change);
35
25
 
36
- if (unmatchedFiles.length == 0) {
37
- throw new Error('Error: No new MD files found:');
26
+ // Step 4b: Match files with the list of changesets
27
+ const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
28
+ const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
29
+
30
+ if (unmatchedFiles.length == 0) {
31
+ throw new Error("Error: No new MD files found:");
32
+ }
33
+ }
38
34
  }
39
- }
40
- }
41
35
 
42
- console.log('Validation successful.');
43
- } catch (error) {
44
- console.log(error.message);
45
- throw error;
46
- }
36
+ console.log("Validation successful.");
37
+ } catch (error) {
38
+ console.log(error.message);
39
+ throw(error);
40
+ }
47
41
  }
42
+
43
+
44
+