@docupace/pipeline 1.0.7-7.micro-cli11 → 1.0.7-alpha.0

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.
Files changed (68) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/bin/next-changeset-validate.sh +8 -8
  3. package/eslint.config.js +26 -49
  4. package/next/changeset.sh +75 -75
  5. package/next/copy.sh +34 -34
  6. package/next/deploy.sh +40 -40
  7. package/next/execute.sh +117 -123
  8. package/next/sonar.sh +23 -23
  9. package/package.json +7 -23
  10. package/src/changeset/cli.js +281 -237
  11. package/src/changeset/validate.js +47 -91
  12. package/src/jenkins/setParams.groovy +59 -58
  13. package/src/next/cli.js +15 -111
  14. package/src/next/config.js +72 -137
  15. package/src/next/copy.js +30 -61
  16. package/src/next/deploy.js +314 -633
  17. package/src/next/jenkins.js +88 -123
  18. package/src/next/pipline.js +115 -114
  19. package/src/next/publish.js +48 -71
  20. package/src/next/pull.js +7 -7
  21. package/src/next/sonar.js +23 -23
  22. package/README.md +0 -136
  23. package/bin/azuread_update_callbacks_for_app.sh +0 -58
  24. package/bitbucket-pipelines.yml +0 -60
  25. package/jest.config.js +0 -15
  26. package/src/auth0/alias.js +0 -79
  27. package/src/auth0/alias.test.js +0 -172
  28. package/src/auth0/cli.js +0 -82
  29. package/src/auth0/configure.js +0 -902
  30. package/src/auth0/configure.test.js +0 -167
  31. package/src/auth0/export.js +0 -48
  32. package/src/auth0/export.test.js +0 -103
  33. package/src/auth0/metadata.js +0 -141
  34. package/src/auth0/metadata.test.js +0 -186
  35. package/src/auth0/vault.js +0 -60
  36. package/src/auth0/vault.test.js +0 -134
  37. package/src/changeset/changelog-wiki.js +0 -328
  38. package/src/changeset/changeset-config.js +0 -34
  39. package/src/changeset/create.js +0 -215
  40. package/src/changeset/package-util.js +0 -87
  41. package/src/changeset/util.js +0 -43
  42. package/src/changeset/version.js +0 -102
  43. package/src/lib/merge-driver.js +0 -204
  44. package/src/merge/cli-merge-all.js +0 -507
  45. package/src/merge/cli-merge.js +0 -492
  46. package/src/merge/cli-resolve.js +0 -399
  47. package/src/merge/cli.js +0 -38
  48. package/src/merge/merge-changelog.js +0 -87
  49. package/src/merge/merge-package.js +0 -106
  50. package/src/merge/merge-types.js +0 -82
  51. package/src/merge/pr.js +0 -231
  52. package/src/micro/cli.js +0 -51
  53. package/src/micro/ms-deploy.js +0 -451
  54. package/src/micro/ms-publish.js +0 -186
  55. package/src/next/alias.js +0 -53
  56. package/src/next/apache.js +0 -81
  57. package/src/next/connect.js +0 -226
  58. package/src/next/git-to-semver.js +0 -79
  59. package/src/next/haproxy.js +0 -76
  60. package/src/next/jira.js +0 -84
  61. package/src/next/logger.js +0 -17
  62. package/src/next/test.js +0 -5
  63. package/src/next/util.js +0 -93
  64. package/src/next/vault.js +0 -45
  65. package/terraform/apply.sh +0 -37
  66. package/terraform/init.sh +0 -72
  67. package/terraform/plan.sh +0 -76
  68. package/terraform/validate.sh +0 -17
package/next/sonar.sh CHANGED
@@ -1,23 +1,23 @@
1
- #!/bin/bash
2
-
3
- # Initialize sonar-scanner command with common parameters
4
- SONAR_CMD="npx sonarqube-scanner"
5
-
6
- echo "PR_ID=$PR_ID"
7
- echo "BRANCH=$BRANCH"
8
- echo "PR_DESTINATION_BRANCH=$PR_DESTINATION_BRANCH"
9
-
10
- # Determine the type of scan based on environment variables
11
- if [[ ! -z "$PR_ID" ]]; then
12
- SONAR_CMD+=" \
13
- -Dsonar.pullrequest.key=$PR_ID \
14
- -Dsonar.pullrequest.branch=$BRANCH \
15
- -Dsonar.pullrequest.base=$PR_DESTINATION_BRANCH"
16
- else
17
- SONAR_CMD+=" \
18
- -Dsonar.branch.name=$BRANCH"
19
- fi
20
-
21
- # Execute the sonar-scanner command
22
- echo "Running: $SONAR_CMD"
23
- $SONAR_CMD
1
+ #!/bin/bash
2
+
3
+ # Initialize sonar-scanner command with common parameters
4
+ SONAR_CMD="npx sonarqube-scanner"
5
+
6
+ echo "PR_ID=$PR_ID"
7
+ echo "BRANCH=$BRANCH"
8
+ echo "PR_DESTINATION_BRANCH=$PR_DESTINATION_BRANCH"
9
+
10
+ # Determine the type of scan based on environment variables
11
+ if [[ ! -z "$PR_ID" ]]; then
12
+ SONAR_CMD+=" \
13
+ -Dsonar.pullrequest.key=$PR_ID \
14
+ -Dsonar.pullrequest.branch=$BRANCH \
15
+ -Dsonar.pullrequest.base=$PR_DESTINATION_BRANCH"
16
+ else
17
+ SONAR_CMD+=" \
18
+ -Dsonar.branch.name=$BRANCH"
19
+ fi
20
+
21
+ # Execute the sonar-scanner command
22
+ echo "Running: $SONAR_CMD"
23
+ $SONAR_CMD
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.77.micro-cli11",
3
+ "version": "1.0.7-alpha.0",
4
+ "description": "",
4
5
  "main": "index.js",
5
6
  "type": "module",
6
7
  "bin": {
7
8
  "dp-changeset-cli": "src/changeset/cli.js",
8
- "dp-next-cli": "src/next/cli.js",
9
- "dp-auth0-cli": "src/auth0/cli.js",
10
- "dp-merge-cli": "src/merge/cli.js",
11
- "dp-micro-cli": "src/micro/cli.js"
9
+ "dp-next-cli": "src/next/cli.js"
12
10
  },
13
11
  "keywords": [
14
12
  "bash"
@@ -17,41 +15,27 @@
17
15
  "license": "ISC",
18
16
  "dependencies": {
19
17
  "@changesets/cli": "^2.27.10",
20
- "@docupace/core-client": "^1.0.1",
21
- "@docupace/pipeline": "^1.0.12",
22
- "@jest/globals": "^30.1.2",
23
- "auth0-deploy-cli": "^8.8.0",
24
18
  "axios": "^1.7.9",
25
19
  "commander": "^12.1.0",
26
20
  "dotenv": "^16.4.7",
27
- "eslint-plugin-import": "^2.32.0",
28
- "fs-extra": "^11.3.0",
29
- "inquirer": "^12.6.1",
30
21
  "js-yaml": "^4.1.0",
31
22
  "lodash": "^4.17.21",
32
23
  "openai": "^4.76.3",
33
- "semver": "^7.7.2",
34
24
  "zod": "^3.24.1",
35
- "zx": "^8.8.1"
25
+ "zx": "^8.2.4"
36
26
  },
37
27
  "devDependencies": {
38
28
  "@eslint/js": "^9.17.0",
39
- "esbuild": "^0.25.12",
40
- "eslint": "^9.34.0",
29
+ "esbuild": "^0.24.0",
30
+ "eslint": "^9.17.0",
41
31
  "eslint-config-prettier": "^9.1.0",
42
- "eslint-import-resolver-node": "^0.3.9",
43
- "eslint-import-resolver-typescript": "^4.4.4",
44
32
  "eslint-plugin-prettier": "^5.2.1",
45
33
  "globals": "^15.14.0",
46
- "jest": "^30.1.3",
47
34
  "prettier": "^3.4.2"
48
35
  },
49
36
  "scripts": {
50
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --testPathIgnorePatterns='src/next/test\\.js'",
51
37
  "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
52
38
  "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",
53
- "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa",
54
- "test-validate": "dp-changset-cli validate",
55
- "test-create": "dp-changset-cli create-changeset"
39
+ "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa"
56
40
  }
57
41
  }
@@ -1,237 +1,281 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { $ } from 'zx';
4
- import { validateChangesets } from './validate.js';
5
- import dotenv from 'dotenv';
6
- import { isMonoRepo, setGitInfo } from '../next/util.js';
7
- import {
8
- toShortVersion,
9
- updateJiraWithVersion,
10
- versionCommand,
11
- } from './version.js';
12
- import { createChangeset } from './create.js';
13
- import {
14
- updateWikiWithVersion,
15
- upsertReleaseNotesFromFile,
16
- } from './changelog-wiki.js';
17
-
18
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
19
-
20
- const program = new Command();
21
-
22
- const args = process.argv;
23
-
24
- async function commitTagCommand(releases) {
25
- console.log('📌 Checking for updates to commit...');
26
-
27
- // Check if there are changes to commit
28
- const status = (await $`git status --porcelain`).stdout.trim();
29
- if (!status) {
30
- console.log('✅ No changes to commit. Exiting.');
31
- return;
32
- }
33
-
34
- console.log('📌 Committing and tagging the new version...');
35
- await setGitInfo();
36
- await $`git add .`;
37
-
38
- if (isMonoRepo()) {
39
- await commitTagMono(releases);
40
- } else {
41
- await commitTag();
42
- }
43
- }
44
-
45
- export function getAppReleases(releases) {
46
- const appReleases = releases.filter(
47
- (release) =>
48
- release.name.endsWith('-app') || release.name.endsWith('-template'),
49
- );
50
- return appReleases;
51
- }
52
-
53
- function getAppNameFromPackageName(packageName) {
54
- const appName = packageName.includes('/')
55
- ? packageName.split('/')[1]
56
- : packageName;
57
-
58
- return appName;
59
- }
60
-
61
- async function commitTagMono(releases) {
62
- let versions = [];
63
- for (const release of getAppReleases(releases)) {
64
- const newVersion = release.newVersion;
65
- const appName = getAppNameFromPackageName(release.name);
66
- versions.push(`${appName}@${newVersion}`);
67
- }
68
-
69
- const defaultBranch = process.env.BITBUCKET_BRANCH;
70
-
71
- if (!process.env.IS_DEV) {
72
- await $`git commit -m "Version bump to ${versions.join(',')} and changelog"`;
73
- await $`git push origin ${defaultBranch}`;
74
- } else {
75
- console.log(`Simulate Version bump to ${versions.join(',')} and changelog`);
76
- }
77
-
78
- for (const newVersion of versions) {
79
- if (!process.env.IS_DEV) {
80
- await $`git tag ${newVersion}`;
81
- console.log(`✅ Version ${newVersion} tagged.`);
82
- } else {
83
- console.log(`✅ Simulate Version ${newVersion} tagged.`);
84
- }
85
- }
86
-
87
- if (!process.env.IS_DEV) {
88
- await $`git push origin --tags`;
89
- console.log(`✅ Version pushed.`);
90
- } else {
91
- console.log(`✅ Simulate Version pushed.`);
92
- }
93
- }
94
-
95
- async function commitTag() {
96
- const newVersion = (
97
- await $`node -p "require('./package.json').version"`
98
- ).stdout.trim();
99
-
100
- if (process.env.IS_DEV) {
101
- console.log(`Simulate commit of version ${newVersion}`);
102
- return;
103
- }
104
-
105
- const defaultBranch = process.env.BITBUCKET_BRANCH;
106
-
107
- await $`git commit -m "Version bump to ${newVersion} and changelog"`;
108
- await $`git push origin ${defaultBranch}`;
109
- await $`git tag v${newVersion}`;
110
- await $`git push origin --tags`;
111
- console.log(`✅ Version ${newVersion} tagged and pushed.`);
112
- }
113
-
114
- // Command: validate
115
- program
116
- .command('validate')
117
- .description('Validate changesets for the provided PR')
118
- .action(async () => {
119
- if (!process.env.BITBUCKET_PR_ID) {
120
- return;
121
- }
122
- await validateChangesets();
123
- });
124
- // Command: version
125
- program
126
- .command('version')
127
- .description('Run Changeset versioning')
128
- .action(async () => {
129
- await versionCommand();
130
- });
131
-
132
- // Command: commit-and-tag
133
- program
134
- .command('commit-tag')
135
- .description('Commit and tag the new version')
136
- .action(async () => {
137
- await commitTagCommand();
138
- });
139
-
140
- // Command: all
141
- program
142
- .command('version-commit-tag')
143
- .description('Run versioning and commit-and-tag in sequence')
144
- .action(async () => {
145
- console.log('📦 Running all steps...');
146
- const releases = await versionCommand();
147
- await updateJiraWithVersion(releases);
148
- await updateWikiWithVersion(releases);
149
- await commitTagCommand(releases);
150
- });
151
-
152
- program
153
- .command('close-version')
154
- .description('Closes a version')
155
- .action(async () => {
156
- console.log('📦 Running all steps...');
157
- const releases = await versionCommand(true);
158
- await commitTagCommand(releases);
159
-
160
- const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
161
-
162
- if (isMonoRepo()) {
163
- for (const release of getAppReleases(releases)) {
164
- const appName = getAppNameFromPackageName(release.name);
165
- const newVersion = toShortVersion(release.newVersion);
166
- if (!newVersion) {
167
- throw new Error('Error calculating branch name');
168
- }
169
- await $`git checkout -b release/${appName}/${newVersion}`;
170
- await $`git push origin release/${appName}/${newVersion}`;
171
- }
172
- } else {
173
- const newVersion = toShortVersion(releases[0].newVersion);
174
- if (!newVersion) {
175
- throw new Error('Error calculating branch name');
176
- }
177
- await $`git checkout -b release/${newVersion}`;
178
- await $`git push origin release/${newVersion}`;
179
- }
180
-
181
- // Return to original branch
182
- await $`git checkout ${currentBranch.trim()}`;
183
-
184
- // Open next alpha version
185
- await $`pnpm changeset pre enter alpha`;
186
- await $`git add .`;
187
- await $`git commit -m "Open next alpha version"`;
188
- await $`git push origin`;
189
- });
190
-
191
- program
192
- .name('create-changeset')
193
- .description(
194
- 'Creates a changeset based on the current branch and Jira ticket information',
195
- )
196
- .action(async () => {
197
- await createChangeset();
198
- });
199
-
200
- program
201
- .command('upload-wiki')
202
- .description('Upload release notes from markdown file to Confluence')
203
- .requiredOption(
204
- '-v, --version <version>',
205
- 'Version title (e.g., "Version 1.0")',
206
- )
207
- .requiredOption(
208
- '-c, --component <component>',
209
- 'Component title (e.g., "Component A")',
210
- )
211
- .requiredOption('-f, --file <file>', 'Path to markdown file')
212
- .requiredOption('-g, --group <group>', 'Group of release notes')
213
-
214
- .action(async (options) => {
215
- try {
216
- console.log('📤 Uploading release notes to Confluence...');
217
- const { versionPage, componentPage } = await upsertReleaseNotesFromFile({
218
- version: options.version,
219
- component: options.component,
220
- markdownFile: options.file,
221
- group: options.group,
222
- });
223
-
224
- console.log('✅ Successfully uploaded to Confluence');
225
- console.log('Version page:', versionPage._links?.webui || versionPage.id);
226
- console.log(
227
- 'Component page:',
228
- componentPage._links?.webui || componentPage.id,
229
- );
230
- } catch (error) {
231
- console.error('❌ Error uploading to Confluence:', error.message);
232
- process.exit(1);
233
- }
234
- });
235
-
236
- // Parse arguments
237
- program.parse(args);
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { $ } from 'zx';
4
+ import path from 'path';
5
+ import { validateChangesets } from './validate.js';
6
+ import fs from 'fs';
7
+ import OpenAI from 'openai';
8
+ import { zodResponseFormat } from 'openai/helpers/zod';
9
+ import z from 'zod';
10
+ import dotenv from 'dotenv';
11
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
12
+ import { exec } from 'child_process';
13
+
14
+ const program = new Command();
15
+
16
+ const args = process.argv;
17
+
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
+ }
42
+
43
+ async function fileExists(filePath) {
44
+ try {
45
+ await fs.promises.access(filePath);
46
+ return true;
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
51
+
52
+ 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;
60
+ }
61
+ }
62
+ throw new Error('Main package.json not found');
63
+ }
64
+
65
+ // Helper function to set Git info
66
+ 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`;
70
+ }
71
+
72
+ const changeSetPackage = `{
73
+ "name": "changeset-package",
74
+ "version": "1.0.0",
75
+ "description": "",
76
+ "scripts": {
77
+ },
78
+ "type": "module",
79
+ "keywords": [],
80
+ "author": "",
81
+ "license": "ISC",
82
+ "dependencies": {},
83
+ "devDependencies": {
84
+ "@changesets/cli": "^2.27.10"
85
+ }
86
+ }
87
+ `;
88
+
89
+ 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.');
101
+ }
102
+
103
+ 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.`);
124
+ }
125
+
126
+ // Command: validate
127
+ 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
+ });
145
+ // Command: version
146
+ program
147
+ .command('version')
148
+ .description('Run Changeset versioning')
149
+ .action(async () => {
150
+ await versionCommand();
151
+ });
152
+
153
+ // Command: commit-and-tag
154
+ program
155
+ .command('commit-tag')
156
+ .description('Commit and tag the new version')
157
+ .action(async () => {
158
+ await commitTagCommand();
159
+ });
160
+
161
+ // Command: all
162
+ 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
+ });
170
+
171
+ 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 = `---
262
+ "${componentName}": ${change_type}
263
+ ---
264
+
265
+ ${summary} [${jiraTicketId}]
266
+ `;
267
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
268
+
269
+ await createChangesetDirectory();
270
+ await fs.promises.writeFile(changesetFile, changesetContent);
271
+ console.log(`Created changeset file at ${changesetFile}`);
272
+
273
+ console.log('Done!');
274
+ } catch (err) {
275
+ console.error(`Error: ${err.message}`);
276
+ process.exit(1);
277
+ }
278
+ });
279
+
280
+ // Parse arguments
281
+ program.parse(args);