@docupace/pipeline 1.0.4 → 1.0.5-4.ervins

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 (46) hide show
  1. package/.prettierrc.cjs +12 -0
  2. package/README.md +136 -0
  3. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  4. package/bin/next-changeset-validate.sh +8 -8
  5. package/eslint.config.js +26 -0
  6. package/next/changeset.sh +75 -75
  7. package/next/copy.sh +34 -34
  8. package/next/deploy.sh +40 -40
  9. package/next/execute.sh +123 -117
  10. package/next/sonar.sh +23 -23
  11. package/package.json +50 -28
  12. package/src/auth0/alias.js +72 -0
  13. package/src/auth0/cli.js +76 -0
  14. package/src/auth0/configure.js +783 -0
  15. package/src/auth0/export.js +43 -0
  16. package/src/auth0/metadata.js +132 -0
  17. package/src/auth0/vault.js +107 -0
  18. package/src/changeset/changeset-config.js +34 -0
  19. package/src/changeset/cli.js +200 -245
  20. package/src/changeset/create.js +205 -0
  21. package/src/changeset/package-util.js +86 -0
  22. package/src/changeset/util.js +43 -0
  23. package/src/changeset/validate.js +84 -44
  24. package/src/changeset/version.js +102 -0
  25. package/src/jenkins/setParams.groovy +58 -0
  26. package/src/next/alias.js +53 -0
  27. package/src/next/apache.js +73 -0
  28. package/src/next/cli.js +228 -59
  29. package/src/next/config.js +137 -0
  30. package/src/next/connect.js +227 -0
  31. package/src/next/copy.js +61 -27
  32. package/src/next/deploy.js +595 -128
  33. package/src/next/haproxy.js +71 -0
  34. package/src/next/jenkins.js +123 -0
  35. package/src/next/jira.js +84 -0
  36. package/src/next/logger.js +17 -0
  37. package/src/next/pipline.js +114 -0
  38. package/src/next/publish.js +71 -46
  39. package/src/next/pull.js +7 -7
  40. package/src/next/sonar.js +23 -23
  41. package/src/next/util.js +93 -0
  42. package/src/next/vault.js +45 -0
  43. package/terraform/apply.sh +37 -0
  44. package/terraform/init.sh +72 -0
  45. package/terraform/plan.sh +76 -0
  46. package/terraform/validate.sh +17 -0
@@ -1,245 +1,200 @@
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
-
13
- const program = new Command();
14
-
15
- const args = process.argv;
16
-
17
- const DIR = path.resolve(process.cwd());
18
-
19
- async function fileExists(filePath) {
20
- try {
21
- await fs.promises.access(filePath);
22
- return true;
23
- } catch {
24
- return false;
25
- }
26
- }
27
-
28
- async function getMainPackage() {
29
- const mainModulePath = process.cwd();
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
- }
37
- }
38
- throw new Error('Main package.json not found');
39
- }
40
-
41
- // Helper function to set Git info
42
- async function setGitInfo() {
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`;
46
- }
47
-
48
- const changeSetPackage = `{
49
- "name": "changeset-package",
50
- "version": "1.0.0",
51
- "description": "",
52
- "scripts": {
53
- },
54
- "type": "module",
55
- "keywords": [],
56
- "author": "",
57
- "license": "ISC",
58
- "dependencies": {},
59
- "devDependencies": {
60
- "@changesets/cli": "^2.27.10"
61
- }
62
- }
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.');
77
- }
78
-
79
- async function commitTagCommand() {
80
- console.log('📌 Checking for updates to commit...');
81
-
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
- }
88
-
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.`);
98
- }
99
-
100
-
101
- // Command: validate
102
- program
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
- });
120
- // Command: version
121
- program
122
- .command('version')
123
- .description('Run Changeset versioning')
124
- .action(async () => {
125
- await versionCommand();
126
- });
127
-
128
- // Command: commit-and-tag
129
- program
130
- .command('commit-tag')
131
- .description('Commit and tag the new version')
132
- .action(async () => {
133
- await commitTagCommand();
134
- });
135
-
136
- // Command: all
137
- program
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
- });
145
-
146
- program
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 = `---
226
- "${componentName}": ${change_type}
227
- ---
228
-
229
- ${summary} [${jiraTicketId}]
230
- `;
231
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
232
-
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
- });
242
-
243
-
244
- // Parse arguments
245
- program.parse(args);
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
+
14
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
15
+
16
+ const program = new Command();
17
+
18
+ const args = process.argv;
19
+
20
+ async function commitTagCommand(releases) {
21
+ console.log('📌 Checking for updates to commit...');
22
+
23
+ // Check if there are changes to commit
24
+ const status = (await $`git status --porcelain`).stdout.trim();
25
+ if (!status) {
26
+ console.log('✅ No changes to commit. Exiting.');
27
+ return;
28
+ }
29
+
30
+ console.log('📌 Committing and tagging the new version...');
31
+ await setGitInfo();
32
+ await $`git add .`;
33
+
34
+ if (isMonoRepo()) {
35
+ await commitTagMono(releases);
36
+ } else {
37
+ await commitTag();
38
+ }
39
+ }
40
+
41
+ export function getAppReleases(releases) {
42
+ const appReleases = releases.filter(
43
+ (release) =>
44
+ release.name.endsWith('-app') || release.name.endsWith('-template'),
45
+ );
46
+ return appReleases;
47
+ }
48
+
49
+ function getAppNameFromPackageName(packageName) {
50
+ const appName = packageName.includes('/')
51
+ ? packageName.split('/')[1]
52
+ : packageName;
53
+
54
+ return appName;
55
+ }
56
+
57
+ async function commitTagMono(releases) {
58
+ let versions = [];
59
+ for (const release of getAppReleases(releases)) {
60
+ const newVersion = release.newVersion;
61
+ const appName = getAppNameFromPackageName(release.name);
62
+ versions.push(`${appName}@${newVersion}`);
63
+ }
64
+
65
+ const defaultBranch = process.env.BITBUCKET_BRANCH;
66
+
67
+ if (!process.env.IS_DEV) {
68
+ await $`git commit -m "Version bump to ${versions.join(',')} and changelog"`;
69
+ await $`git push origin ${defaultBranch}`;
70
+ } else {
71
+ console.log(`Simulate Version bump to ${versions.join(',')} and changelog`);
72
+ }
73
+
74
+ for (const newVersion of versions) {
75
+ if (!process.env.IS_DEV) {
76
+ await $`git tag ${newVersion}`;
77
+ console.log(`✅ Version ${newVersion} tagged.`);
78
+ } else {
79
+ console.log(`✅ Simulate Version ${newVersion} tagged.`);
80
+ }
81
+ }
82
+
83
+ if (!process.env.IS_DEV) {
84
+ await $`git push origin --tags`;
85
+ console.log(`✅ Version pushed.`);
86
+ } else {
87
+ console.log(`✅ Simulate Version pushed.`);
88
+ }
89
+ }
90
+
91
+ async function commitTag() {
92
+ const newVersion = (
93
+ await $`node -p "require('./package.json').version"`
94
+ ).stdout.trim();
95
+
96
+ const defaultBranch = process.env.BITBUCKET_BRANCH;
97
+
98
+ await $`git commit -m "Version bump to ${newVersion} and changelog"`;
99
+ await $`git push origin ${defaultBranch}`;
100
+ await $`git tag v${newVersion}`;
101
+ await $`git push origin --tags`;
102
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
103
+ }
104
+
105
+ // Command: validate
106
+ program
107
+ .command('validate')
108
+ .description('Validate changesets for the provided PR')
109
+ .action(async () => {
110
+ if (!process.env.BITBUCKET_PR_ID) {
111
+ return;
112
+ }
113
+ console.log('🔍 Validating changesets...');
114
+ try {
115
+ await validateChangesets();
116
+ console.log('✅ Changeset validation passed.');
117
+ } catch {
118
+ console.error(
119
+ '❌ 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',
120
+ );
121
+ process.exit(1);
122
+ }
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 commitTagCommand(releases);
149
+ });
150
+
151
+ program
152
+ .command('close-version')
153
+ .description('Closes a version')
154
+ .action(async () => {
155
+ console.log('📦 Running all steps...');
156
+ const releases = await versionCommand(true);
157
+ await commitTagCommand(releases);
158
+
159
+ const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
160
+
161
+ if (isMonoRepo()) {
162
+ for (const release of getAppReleases(releases)) {
163
+ const appName = getAppNameFromPackageName(release.name);
164
+ const newVersion = toShortVersion(release.newVersion);
165
+ if (!newVersion) {
166
+ throw new Error('Error calculating branch name');
167
+ }
168
+ await $`git checkout -b release/${appName}/${newVersion}`;
169
+ await $`git push origin release/${appName}/${newVersion}`;
170
+ }
171
+ } else {
172
+ const newVersion = toShortVersion(releases[0].newVersion);
173
+ if (!newVersion) {
174
+ throw new Error('Error calculating branch name');
175
+ }
176
+ await $`git checkout -b release/${newVersion}`;
177
+ await $`git push origin release/${newVersion}`;
178
+ }
179
+
180
+ // Return to original branch
181
+ await $`git checkout ${currentBranch.trim()}`;
182
+
183
+ // Open next alpha version
184
+ await $`pnpm changeset pre enter alpha`;
185
+ await $`git add .`;
186
+ await $`git commit -m "Open next alpha version"`;
187
+ await $`git push origin`;
188
+ });
189
+
190
+ program
191
+ .name('create-changeset')
192
+ .description(
193
+ 'Creates a changeset based on the current branch and Jira ticket information',
194
+ )
195
+ .action(async () => {
196
+ await createChangeset();
197
+ });
198
+
199
+ // Parse arguments
200
+ program.parse(args);
@@ -0,0 +1,205 @@
1
+ import OpenAI from 'openai';
2
+ import z from 'zod';
3
+ import { zodResponseFormat } from 'openai/helpers/zod';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import inquirer from 'inquirer';
7
+ import { getMainPackage, getPackage, findJiraTicketId } from './util.js';
8
+ import { getPackageNames } from './package-util.js';
9
+ import { execSync } from 'child_process';
10
+
11
+ async function createChangesetDirectory() {
12
+ try {
13
+ // Use path.join to build a safe path to `.changeset`
14
+ const targetDir = path.join(process.cwd(), '.changeset');
15
+
16
+ // Create the directory recursively if it doesn't exist
17
+ await fs.promises.mkdir(targetDir, { recursive: true });
18
+ } catch (error) {
19
+ console.error('Error creating .changeset directory:', error);
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Gets the current git branch name
25
+ */
26
+ async function getCurrentBranch() {
27
+ try {
28
+ const branchName = execSync('git branch --show-current', {
29
+ encoding: 'utf8',
30
+ shell: true,
31
+ }).trim();
32
+ console.log(`Current branch: ${branchName}`);
33
+ return branchName;
34
+ } catch (error) {
35
+ console.error('Error getting current branch:', error.message);
36
+ throw error;
37
+ }
38
+ }
39
+ /**
40
+ * Extracts a Jira ticket ID from a branch name
41
+ */
42
+ function extractJiraTicketId(branchName) {
43
+ const jiraTicketId = findJiraTicketId(branchName);
44
+ if (!jiraTicketId) {
45
+ throw new Error('No Jira ticket found in the branch name.');
46
+ }
47
+ return jiraTicketId;
48
+ }
49
+
50
+ /**
51
+ * Fetches Jira ticket data from Jira API
52
+ */
53
+ async function fetchJiraTicketData(jiraTicketId) {
54
+ const jiraBaseUrl = 'https://docupacellc.atlassian.net';
55
+ const jiraEmail = process.env.JIRA_API_EMAIL;
56
+ const jiraApiKey = process.env.JIRA_API_KEY;
57
+ const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
58
+ const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
59
+
60
+ const jiraResponse = await fetch(jiraUrl, {
61
+ headers: {
62
+ Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
63
+ 'Content-Type': 'application/json',
64
+ },
65
+ });
66
+
67
+ if (!jiraResponse.ok) {
68
+ throw new Error(
69
+ `Failed to fetch Jira ticket ${jiraTicketId}. Status: ${jiraResponse.status}, Ticket URL: ${jiraUrl}`,
70
+ );
71
+ }
72
+
73
+ return await jiraResponse.json();
74
+ }
75
+
76
+ /**
77
+ * Generates release notes using OpenAI
78
+ */
79
+ async function generateReleaseNotes(jiraTicketData) {
80
+ const openaiClient = new OpenAI({
81
+ apiKey: process.env['OPENAI_API_KEY'],
82
+ });
83
+
84
+ const ChangeRequestSchema = z.object({
85
+ change_type: z.enum(['patch', 'minor']),
86
+ summary: z.string(),
87
+ jira_ticket_id: z.string(),
88
+ });
89
+
90
+ const openAiResponse = await openaiClient.chat.completions.create({
91
+ model: 'gpt-4o-mini',
92
+ messages: [
93
+ {
94
+ role: 'system',
95
+ 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`,
96
+ },
97
+ {
98
+ role: 'user',
99
+ content: JSON.stringify(jiraTicketData),
100
+ },
101
+ ],
102
+ response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
103
+ temperature: 0,
104
+ });
105
+
106
+ const assistantResponse = openAiResponse.choices[0].message.content;
107
+ return JSON.parse(assistantResponse);
108
+ }
109
+
110
+ /**
111
+ * Writes the changeset file
112
+ */
113
+ async function writeChangesetFile(packages, jiraTicketId, changeType, summary) {
114
+ // Generate the YAML frontmatter for multiple packages
115
+ const packageEntries = packages
116
+ .map((pkg) => `'${pkg.name}': ${changeType}`)
117
+ .join('\n');
118
+
119
+ const changesetContent = `---
120
+ ${packageEntries}
121
+ ---
122
+
123
+ ${summary} [${jiraTicketId}]
124
+ `;
125
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
126
+
127
+ await createChangesetDirectory();
128
+ await fs.promises.writeFile(changesetFile, changesetContent);
129
+ console.log(`Created changeset file at ${changesetFile}`);
130
+ }
131
+
132
+ /**
133
+ * Main function to create a changeset
134
+ */
135
+
136
+ export async function createChangeset() {
137
+ const packages = getPackageNames();
138
+
139
+ if (packages.length > 1) {
140
+ const allPackages = packages;
141
+ const response = await inquirer.prompt([
142
+ {
143
+ type: 'checkbox',
144
+ name: 'packages',
145
+ message: 'Which packages do you want to generate changesets for?',
146
+ choices: allPackages.map((appPackage) => ({
147
+ name: appPackage.name,
148
+ value: appPackage.name,
149
+ })),
150
+ validate: (input) => {
151
+ if (input.length === 0) {
152
+ return 'Please select at least one package.';
153
+ }
154
+ return true;
155
+ },
156
+ },
157
+ ]);
158
+
159
+ const selectedPackages = allPackages.filter((appPackage) =>
160
+ response.packages.includes(appPackage.name),
161
+ );
162
+
163
+ // Get package contents for all selected packages
164
+ const selectedPackageContents = await Promise.all(
165
+ selectedPackages.map(async (selectedPackage) => {
166
+ return await getPackage(selectedPackage.path);
167
+ }),
168
+ );
169
+
170
+ await createChangesetForPackage(selectedPackageContents);
171
+ } else {
172
+ const mainPackage = await getMainPackage();
173
+ await createChangesetForPackage([mainPackage]);
174
+ }
175
+ }
176
+
177
+ export async function createChangesetForPackage(packages) {
178
+ try {
179
+ // Step 1: Get the current branch name
180
+ const branchName = await getCurrentBranch();
181
+
182
+ // Step 2: Extract Jira ticket number
183
+ const jiraTicketId = extractJiraTicketId(branchName);
184
+
185
+ // Step 3: Fetch Jira ticket data
186
+ const jiraTicketData = await fetchJiraTicketData(jiraTicketId);
187
+ const jiraSummary = jiraTicketData.fields.summary;
188
+ console.log(
189
+ `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
190
+ );
191
+
192
+ // Step 4: Generate release notes using OpenAI
193
+ const { change_type, summary } = await generateReleaseNotes(jiraTicketData);
194
+ console.log(`Change type: ${change_type}`);
195
+ console.log(`Release note: ${summary}`);
196
+
197
+ // Step 5: Create a changeset .md file for all packages
198
+ await writeChangesetFile(packages, jiraTicketId, change_type, summary);
199
+
200
+ console.log('Changeset created successfully!');
201
+ } catch (err) {
202
+ console.error(`Error: ${err.message}`);
203
+ process.exit(1);
204
+ }
205
+ }