@docupace/pipeline 1.0.3-1.demo1 → 1.0.3

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.31.demo1",
3
+ "version": "1.0.3",
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,29 +15,14 @@
16
15
  "license": "ISC",
17
16
  "dependencies": {
18
17
  "@changesets/cli": "^2.27.10",
19
- "@docupace/core-client": "^0.1.59",
20
- "auth0-deploy-cli": "^7.24.3",
21
- "axios": "^1.7.9",
22
18
  "commander": "^12.1.0",
23
19
  "dotenv": "^16.4.7",
24
20
  "js-yaml": "^4.1.0",
25
- "lodash": "^4.17.21",
26
21
  "openai": "^4.76.3",
27
22
  "zod": "^3.24.1",
28
- "zx": "^8.3.0"
23
+ "zx": "^8.2.4"
29
24
  },
30
25
  "devDependencies": {
31
- "@eslint/js": "^9.17.0",
32
- "esbuild": "^0.24.0",
33
- "eslint": "^9.17.0",
34
- "eslint-config-prettier": "^9.1.0",
35
- "eslint-plugin-prettier": "^5.2.1",
36
- "globals": "^15.14.0",
37
- "prettier": "^3.4.2"
38
- },
39
- "scripts": {
40
- "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
41
- "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",
42
- "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa"
26
+ "esbuild": "^0.24.0"
43
27
  }
44
28
  }
@@ -2,70 +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
- import { makeJiraRequest, updateComponentVersion } from '../next/jira.js';
12
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
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
- function run(command) {
31
- return new Promise((resolve, reject) => {
32
- exec(command, { shell: true }, (error, stdout, stderr) => {
33
- if (error) {
34
- reject(error);
35
- } else {
36
- resolve({ stdout, stderr });
37
- }
38
- });
39
- });
40
- }
17
+ const DIR = path.resolve(process.cwd());
41
18
 
42
19
  async function fileExists(filePath) {
43
- try {
44
- await fs.promises.access(filePath);
45
- return true;
46
- } catch {
47
- return false;
48
- }
20
+ try {
21
+ await fs.promises.access(filePath);
22
+ return true;
23
+ } catch {
24
+ return false;
25
+ }
49
26
  }
50
27
 
51
28
  async function getMainPackage() {
52
- const mainModulePath = process.cwd();
53
- if (mainModulePath) {
54
- const packageJsonPath = path.join(mainModulePath, 'package.json');
55
- if (await fileExists(packageJsonPath)) {
56
- const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
57
- const packageJson = JSON.parse(fileContent);
58
- 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
+ }
59
37
  }
60
- }
61
- throw new Error('Main package.json not found');
38
+ throw new Error('Main package.json not found');
62
39
  }
63
40
 
64
41
  // Helper function to set Git info
65
42
  async function setGitInfo() {
66
- await $`git config --global user.email "gitops@docupace.com"`;
67
- await $`git config --global user.name "Gitops"`;
68
- 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://${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
69
46
  }
70
47
 
71
48
  const changeSetPackage = `{
@@ -83,242 +60,186 @@ const changeSetPackage = `{
83
60
  "@changesets/cli": "^2.27.10"
84
61
  }
85
62
  }
86
- `;
87
-
88
- async function versionCommand(closeVersion = false) {
89
- console.log('📦 Running Changeset versioning...');
90
- await setGitInfo();
91
- await $`mv package.json package.json.bak`;
92
- await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
93
- await fs.promises.writeFile('package.json', changeSetPackage);
94
- await $`pnpm install`;
95
- await $`rm package.json pnpm-lock.yaml`;
96
- await $`mv package.json.bak package.json`;
97
- await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
98
- if (closeVersion) {
99
- await $`pnpm changeset pre exit`;
100
- }
101
-
102
- await $`pnpm changeset version`;
103
-
104
- // Read the updated package.json to get the new version and package name
105
- const packageJson = JSON.parse(
106
- await fs.promises.readFile('package.json', 'utf-8'),
107
- );
108
- const version = packageJson.version;
109
- const packageName = packageJson.name;
110
-
111
- if (closeVersion) {
112
- return { version, packageName };
113
- }
114
-
115
- // Get the last commit message and extract Jira ticket
116
- const lastCommit = (await $`git log -1 --pretty=%B`).stdout.trim();
117
- console.log(`Last commit '${lastCommit}' being processed to get Jira ticket`);
118
-
119
- const jiraTicketMatch = lastCommit.match(/([A-Z]+-\d+)/);
120
- const jiraTicketId = jiraTicketMatch ? jiraTicketMatch[0] : null;
121
-
122
- // If we have all the necessary data, update the component version in Jira
123
- if (jiraTicketId && version && packageName) {
124
- try {
125
- await updateComponentVersion(jiraTicketId, packageName, version);
126
- } catch (error) {
127
- console.error(
128
- `Failed to update Jira component version: ${error.message}`,
129
- );
130
- }
131
- }
132
-
133
- console.log('✅ Changeset versioning complete.');
134
- return { version, packageName };
63
+ `
64
+
65
+ async function versionCommand() {
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.');
135
77
  }
136
78
 
137
79
  async function commitTagCommand() {
138
- console.log('📌 Checking for updates to commit...');
80
+ console.log('📌 Checking for updates to commit...');
139
81
 
140
- // Check if there are changes to commit
141
- const status = (await $`git status --porcelain`).stdout.trim();
142
- if (!status) {
143
- console.log('✅ No changes to commit. Exiting.');
144
- return;
145
- }
82
+ // Check if there are changes to commit
83
+ const status = (await $`git status --porcelain`).stdout.trim();
84
+ if (!status) {
85
+ console.log('✅ No changes to commit. Exiting.');
86
+ return;
87
+ }
146
88
 
147
- console.log('📌 Committing and tagging the new version...');
148
- await setGitInfo();
149
- await $`git add .`;
150
- const newVersion = (
151
- await $`node -p "require('./package.json').version"`
152
- ).stdout.trim();
153
- await $`git commit -m "Version bump to ${newVersion} and changelog"`;
154
- await $`git push origin`;
155
- await $`git tag v${newVersion}`;
156
- await $`git push origin --tags`;
157
- console.log(`✅ Version ${newVersion} tagged and pushed.`);
89
+ console.log('📌 Committing and tagging the new version...');
90
+ await setGitInfo();
91
+ await $`git add .`;
92
+ const newVersion = (await $`node -p "require('./package.json').version"`).stdout.trim();
93
+ await $`git commit -m "Version bump to ${newVersion} and changelog"`;
94
+ await $`git push origin`;
95
+ await $`git tag v${newVersion}`;
96
+ await $`git push origin --tags`;
97
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
158
98
  }
159
99
 
100
+
160
101
  // Command: validate
161
102
  program
162
- .command('validate <path>')
163
- .description('Validate changesets for the provided PR')
164
- .action(async (path) => {
165
- if (!process.env.BITBUCKET_PR_ID) {
166
- return;
167
- }
168
- console.log('🔍 Validating changesets...');
169
- try {
170
- await validateChangesets(path);
171
- console.log('✅ Changeset validation passed.');
172
- } catch (error) {
173
- console.error(
174
- '❌ 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',
175
- );
176
- process.exit(1);
177
- }
178
- });
103
+ .command('validate <path>')
104
+ .description('Validate changesets for the provided PR')
105
+ .action(async (path) => {
106
+ if(!process.env.BITBUCKET_PR_ID) {
107
+ return;
108
+ }
109
+ console.log('🔍 Validating changesets...');
110
+ try {
111
+ await validateChangesets(path);
112
+ console.log('✅ Changeset validation passed.');
113
+ } catch (error) {
114
+ console.error(
115
+ '❌ 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'
116
+ );
117
+ process.exit(1);
118
+ }
119
+ });
179
120
  // Command: version
180
121
  program
181
- .command('version')
182
- .description('Run Changeset versioning')
183
- .action(async () => {
184
- await versionCommand();
185
- });
122
+ .command('version')
123
+ .description('Run Changeset versioning')
124
+ .action(async () => {
125
+ await versionCommand();
126
+ });
186
127
 
187
128
  // Command: commit-and-tag
188
129
  program
189
- .command('commit-tag')
190
- .description('Commit and tag the new version')
191
- .action(async () => {
192
- await commitTagCommand();
193
- });
130
+ .command('commit-tag')
131
+ .description('Commit and tag the new version')
132
+ .action(async () => {
133
+ await commitTagCommand();
134
+ });
194
135
 
195
136
  // Command: all
196
137
  program
197
- .command('version-commit-tag')
198
- .description('Run versioning and commit-and-tag in sequence')
199
- .action(async () => {
200
- console.log('📦 Running all steps...');
201
- await versionCommand();
202
- await commitTagCommand();
203
- });
204
-
205
- program
206
- .command('close-version')
207
- .description('Closes a version')
208
- .action(async () => {
209
- console.log('📦 Running all steps...');
210
- const { version } = await versionCommand(true);
211
- await commitTagCommand();
212
-
213
- // Get current branch
214
- const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
215
-
216
- // Create and push release branch
217
- await $`git checkout -b release/${version}`;
218
- await $`git push origin release/${version}`;
219
-
220
- // Return to original branch
221
- await $`git checkout ${currentBranch.trim()}`;
222
-
223
- // Open next alpha version
224
- await $`pnpm changeset pre enter alpha`;
225
- await $`git add .`;
226
- await $`git commit -m "Open next alpha version"`;
227
- await $`git push origin`;
228
-
229
- });
138
+ .command('version-commit-tag')
139
+ .description('Run versioning and commit-and-tag in sequence')
140
+ .action(async () => {
141
+ console.log('📦 Running all steps...');
142
+ await versionCommand();
143
+ await commitTagCommand();
144
+ });
230
145
 
231
146
  program
232
- .name('create-changeset')
233
- .description(
234
- 'Creates a changeset based on the current branch and Jira ticket information',
235
- )
236
- .action(async () => {
237
- const mainPackage = await getMainPackage();
238
- const componentName = mainPackage.name;
239
-
240
- try {
241
- // Step 1: Get the current branch name
242
- const branchName = (await $`git branch --show-current`).stdout.trim();
243
- console.log(`Current branch: ${branchName}`);
244
-
245
- // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
246
- const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
247
- if (!jiraTicketMatch) {
248
- throw new Error('No Jira ticket found in the branch name.');
249
- }
250
- const jiraTicketId = jiraTicketMatch[0];
251
-
252
- // Step 3: Fetch Jira ticket information
253
- const jiraTicketData = await makeJiraRequest(
254
- `/rest/api/2/issue/${jiraTicketId}`,
255
- );
256
-
257
- if (jiraTicketData.fields.customfield_10107?.value !== 'Product') {
258
- throw new Error('Issue Type of Work must be Product');
259
- }
260
-
261
- const jiraSummary = jiraTicketData.fields.summary;
262
-
263
- console.log(
264
- `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
265
- );
266
-
267
- const openaiClient = new OpenAI({
268
- apiKey: process.env['OPENAI_API_KEY'],
269
- });
270
-
271
- const ChangeRequestSchema = z.object({
272
- change_type: z.enum(['patch', 'minor']),
273
- summary: z.string(),
274
- jira_ticket_id: z.string(),
275
- });
276
-
277
- const openAiResponse = await openaiClient.chat.completions.create({
278
- model: 'gpt-4o-mini',
279
- messages: [
280
- {
281
- role: 'system',
282
- 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`,
283
- },
284
- {
285
- role: 'user',
286
- content: JSON.stringify(jiraTicketData),
287
- },
288
- ],
289
- response_format: zodResponseFormat(
290
- ChangeRequestSchema,
291
- 'changeset_schema',
292
- ),
293
- temperature: 0,
294
- });
295
-
296
- const assistantResponse = openAiResponse.choices[0].message.content;
297
- const parsedResponse = JSON.parse(assistantResponse);
298
-
299
- const { change_type, summary } = parsedResponse;
300
- console.log(`Change type: ${change_type}`);
301
- console.log(`Release note: ${summary}`);
302
-
303
- // Step 5: Create a changeset .md file
304
- const changesetContent = `---
147
+ .name('create-changeset')
148
+ .description('Creates a changeset based on the current branch and Jira ticket information')
149
+ .action(async () => {
150
+ const mainPackage = await getMainPackage();
151
+ const componentName = mainPackage.name;
152
+
153
+ try {
154
+ // Step 1: Get the current branch name
155
+ const branchName = (await $`git branch --show-current`).stdout.trim();
156
+ console.log(`Current branch: ${branchName}`);
157
+
158
+ // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
159
+ const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
160
+ if (!jiraTicketMatch) {
161
+ throw new Error('No Jira ticket found in the branch name.');
162
+ }
163
+ const jiraTicketId = jiraTicketMatch[0];
164
+
165
+ // Step 3: Fetch Jira ticket information
166
+ const jiraBaseUrl = 'https://docupacellc.atlassian.net';
167
+ const jiraEmail = process.env.JIRA_API_EMAIL;
168
+ const jiraApiKey = process.env.JIRA_API_KEY;
169
+ const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
170
+ const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
171
+ const jiraResponse = await fetch(jiraUrl, {
172
+ headers: {
173
+ Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
174
+ 'Content-Type': 'application/json',
175
+ },
176
+ });
177
+
178
+ if (!jiraResponse.ok) {
179
+ throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
180
+ }
181
+ const jiraTicketData = await jiraResponse.json();
182
+
183
+ if(jiraTicketData.fields.customfield_10107?.value !== 'Product') {
184
+ throw new Error("Issue Type of Work must be Product")
185
+ }
186
+
187
+ const jiraSummary = jiraTicketData.fields.summary;
188
+
189
+ console.log(`Generating release notes for ${jiraTicketId} - ${jiraSummary}`)
190
+
191
+ const openaiClient = new OpenAI({
192
+ apiKey: process.env['OPENAI_API_KEY'],
193
+ });
194
+
195
+ const ChangeRequestSchema = z.object({
196
+ change_type: z.enum(["patch", "minor"]),
197
+ summary: z.string(),
198
+ jira_ticket_id: z.string(),
199
+ });
200
+
201
+ const openAiResponse = await openaiClient.chat.completions.create({
202
+ model: "gpt-4o-mini",
203
+ messages: [
204
+ {
205
+ role: "system",
206
+ 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`,
207
+ },
208
+ {
209
+ role: "user",
210
+ content: JSON.stringify(jiraTicketData),
211
+ },
212
+ ],
213
+ response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
214
+ temperature: 0
215
+ });
216
+
217
+ const assistantResponse = openAiResponse.choices[0].message.content;
218
+ const parsedResponse = JSON.parse(assistantResponse);
219
+
220
+ const { change_type, summary } = parsedResponse;
221
+ console.log(`Change type: ${change_type}`);
222
+ console.log(`Release note: ${summary}`);
223
+
224
+ // Step 5: Create a changeset using pnpm
225
+ const changesetContent = `---
305
226
  "${componentName}": ${change_type}
306
227
  ---
307
228
 
308
229
  ${summary} [${jiraTicketId}]
309
230
  `;
310
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
231
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
311
232
 
312
- await createChangesetDirectory();
313
- await fs.promises.writeFile(changesetFile, changesetContent);
314
- console.log(`Created changeset file at ${changesetFile}`);
233
+ await $`mkdir -p ./.changeset`;
234
+ await fs.promises.writeFile(changesetFile, changesetContent);
235
+ console.log(`Created changeset file at ${changesetFile}`);
236
+
237
+ console.log('Done!');
238
+ } catch (err) {
239
+ console.error(`Error: ${err.message}`);
240
+ }
241
+ });
315
242
 
316
- console.log('Done!');
317
- } catch (err) {
318
- console.error(`Error: ${err.message}`);
319
- process.exit(1);
320
- }
321
- });
322
243
 
323
244
  // Parse arguments
324
245
  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
+