@docupace/pipeline 1.0.7-beta.2 → 1.0.8-6.xray

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 (64) hide show
  1. package/README.md +136 -0
  2. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  3. package/bin/xray.sh +273 -0
  4. package/bitbucket-pipelines.yml +142 -0
  5. package/eslint.config.js +25 -2
  6. package/jest.config.js +15 -0
  7. package/next/execute.sh +8 -2
  8. package/package.json +23 -7
  9. package/src/auth0/alias.js +79 -0
  10. package/src/auth0/alias.test.js +172 -0
  11. package/src/auth0/cli.js +82 -0
  12. package/src/auth0/configure.js +902 -0
  13. package/src/auth0/configure.test.js +167 -0
  14. package/src/auth0/export.js +48 -0
  15. package/src/auth0/export.test.js +103 -0
  16. package/src/auth0/metadata.js +141 -0
  17. package/src/auth0/metadata.test.js +186 -0
  18. package/src/auth0/vault.js +60 -0
  19. package/src/auth0/vault.test.js +134 -0
  20. package/src/changeset/changelog-wiki.js +328 -0
  21. package/src/changeset/changeset-config.js +34 -0
  22. package/src/changeset/cli.js +151 -195
  23. package/src/changeset/create.js +215 -0
  24. package/src/changeset/package-util.js +87 -0
  25. package/src/changeset/util.js +43 -0
  26. package/src/changeset/validate.js +45 -1
  27. package/src/changeset/version.js +102 -0
  28. package/src/jenkins/setParams.groovy +1 -2
  29. package/src/jfrog/xray-scan.yaml +29 -0
  30. package/src/lib/merge-driver.js +204 -0
  31. package/src/merge/cli-merge-all.js +521 -0
  32. package/src/merge/cli-merge.js +572 -0
  33. package/src/merge/cli-resolve.js +399 -0
  34. package/src/merge/cli.js +38 -0
  35. package/src/merge/common.js +7 -0
  36. package/src/merge/merge-changelog.js +87 -0
  37. package/src/merge/merge-package.js +106 -0
  38. package/src/merge/merge-types.js +82 -0
  39. package/src/merge/pr.js +231 -0
  40. package/src/micro/cli.js +51 -0
  41. package/src/micro/ms-deploy.js +451 -0
  42. package/src/micro/ms-publish.js +186 -0
  43. package/src/next/alias.js +53 -0
  44. package/src/next/apache.js +81 -0
  45. package/src/next/cli.js +111 -15
  46. package/src/next/config.js +72 -7
  47. package/src/next/connect.js +226 -0
  48. package/src/next/copy.js +32 -1
  49. package/src/next/deploy.js +514 -75
  50. package/src/next/git-to-semver.js +79 -0
  51. package/src/next/haproxy.js +76 -0
  52. package/src/next/jenkins.js +3 -2
  53. package/src/next/jira.js +84 -0
  54. package/src/next/logger.js +17 -0
  55. package/src/next/pipline.js +0 -1
  56. package/src/next/publish.js +53 -30
  57. package/src/next/test.js +5 -0
  58. package/src/next/util.js +95 -0
  59. package/src/next/vault.js +45 -0
  60. package/terraform/apply.sh +41 -0
  61. package/terraform/import.sh +111 -0
  62. package/terraform/init.sh +78 -0
  63. package/terraform/plan.sh +95 -0
  64. package/terraform/validate.sh +17 -0
@@ -1,123 +1,111 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import { $ } from 'zx';
4
- import path from 'path';
5
4
  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
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
+
11
18
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
12
- import { exec } from 'child_process';
13
19
 
14
20
  const program = new Command();
15
21
 
16
22
  const args = process.argv;
17
23
 
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');
24
+ async function commitTagCommand(releases) {
25
+ console.log('📌 Checking for updates to commit...');
22
26
 
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
+ // 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;
27
32
  }
28
- }
29
-
30
33
 
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
- }
34
+ console.log('📌 Committing and tagging the new version...');
35
+ await setGitInfo();
36
+ await $`git add .`;
42
37
 
43
- async function fileExists(filePath) {
44
- try {
45
- await fs.promises.access(filePath);
46
- return true;
47
- } catch {
48
- return false;
38
+ if (isMonoRepo()) {
39
+ await commitTagMono(releases);
40
+ } else {
41
+ await commitTag();
49
42
  }
50
43
  }
51
44
 
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');
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;
63
51
  }
64
52
 
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`;
53
+ function getAppNameFromPackageName(packageName) {
54
+ const appName = packageName.includes('/')
55
+ ? packageName.split('/')[1]
56
+ : packageName;
57
+
58
+ return appName;
70
59
  }
71
60
 
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"
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}`);
85
67
  }
86
- }
87
- `;
88
68
 
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
- }
69
+ const defaultBranch = process.env.BITBUCKET_BRANCH;
102
70
 
103
- async function commitTagCommand() {
104
- console.log('📌 Checking for updates to commit...');
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
+ }
105
77
 
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;
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
+ }
111
85
  }
112
86
 
113
- console.log('📌 Committing and tagging the new version...');
114
- await setGitInfo();
115
- await $`git add .`;
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() {
116
96
  const newVersion = (
117
97
  await $`node -p "require('./package.json').version"`
118
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
+
119
107
  await $`git commit -m "Version bump to ${newVersion} and changelog"`;
120
- await $`git push origin`;
108
+ await $`git push origin ${defaultBranch}`;
121
109
  await $`git tag v${newVersion}`;
122
110
  await $`git push origin --tags`;
123
111
  console.log(`✅ Version ${newVersion} tagged and pushed.`);
@@ -125,22 +113,13 @@ async function commitTagCommand() {
125
113
 
126
114
  // Command: validate
127
115
  program
128
- .command('validate <path>')
116
+ .command('validate')
129
117
  .description('Validate changesets for the provided PR')
130
- .action(async (path) => {
118
+ .action(async () => {
131
119
  if (!process.env.BITBUCKET_PR_ID) {
132
120
  return;
133
121
  }
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
- }
122
+ await validateChangesets();
144
123
  });
145
124
  // Command: version
146
125
  program
@@ -164,8 +143,49 @@ program
164
143
  .description('Run versioning and commit-and-tag in sequence')
165
144
  .action(async () => {
166
145
  console.log('📦 Running all steps...');
167
- await versionCommand();
168
- await commitTagCommand();
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`;
169
189
  });
170
190
 
171
191
  program
@@ -174,105 +194,41 @@ program
174
194
  'Creates a changeset based on the current branch and Jira ticket information',
175
195
  )
176
196
  .action(async () => {
177
- const mainPackage = await getMainPackage();
178
- const componentName = mainPackage.name;
197
+ await createChangeset();
198
+ });
179
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) => {
180
215
  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
- },
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,
204
222
  });
205
223
 
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
-
224
+ console.log('✅ Successfully uploaded to Confluence');
225
+ console.log('Version page:', versionPage._links?.webui || versionPage.id);
219
226
  console.log(
220
- `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
227
+ 'Component page:',
228
+ componentPage._links?.webui || componentPage.id,
221
229
  );
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}`);
230
+ } catch (error) {
231
+ console.error('❌ Error uploading to Confluence:', error.message);
276
232
  process.exit(1);
277
233
  }
278
234
  });
@@ -0,0 +1,215 @@
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 writeJiraChangesetFile(
114
+ packages,
115
+ jiraTicketId,
116
+ changeType,
117
+ summary,
118
+ ) {
119
+ const text = `${summary} [${jiraTicketId}]`;
120
+ await writeChangesetFile(packages, jiraTicketId, changeType, text);
121
+ }
122
+
123
+ export async function writeChangesetFile(packages, filename, changeType, text) {
124
+ const packageEntries = packages
125
+ .map((pkg) => `'${pkg.name}': ${changeType}`)
126
+ .join('\n');
127
+
128
+ const changesetContent = `---
129
+ ${packageEntries}
130
+ ---
131
+
132
+ ${text}
133
+ `;
134
+
135
+ const changesetFile = `./.changeset/${filename}.md`;
136
+
137
+ await createChangesetDirectory();
138
+ await fs.promises.writeFile(changesetFile, changesetContent);
139
+ console.log(`Created changeset file at ${changesetFile}`);
140
+ }
141
+
142
+ /**
143
+ * Main function to create a changeset
144
+ */
145
+
146
+ export async function createChangeset() {
147
+ const packages = getPackageNames();
148
+
149
+ if (packages.length > 1) {
150
+ const allPackages = packages;
151
+ const response = await inquirer.prompt([
152
+ {
153
+ type: 'checkbox',
154
+ name: 'packages',
155
+ message: 'Which packages do you want to generate changesets for?',
156
+ choices: allPackages.map((appPackage) => ({
157
+ name: appPackage.name,
158
+ value: appPackage.name,
159
+ })),
160
+ validate: (input) => {
161
+ if (input.length === 0) {
162
+ return 'Please select at least one package.';
163
+ }
164
+ return true;
165
+ },
166
+ },
167
+ ]);
168
+
169
+ const selectedPackages = allPackages.filter((appPackage) =>
170
+ response.packages.includes(appPackage.name),
171
+ );
172
+
173
+ // Get package contents for all selected packages
174
+ const selectedPackageContents = await Promise.all(
175
+ selectedPackages.map(async (selectedPackage) => {
176
+ return await getPackage(selectedPackage.path);
177
+ }),
178
+ );
179
+
180
+ await createChangesetForPackage(selectedPackageContents);
181
+ } else {
182
+ const mainPackage = await getMainPackage();
183
+ await createChangesetForPackage([mainPackage]);
184
+ }
185
+ }
186
+
187
+ export async function createChangesetForPackage(packages) {
188
+ try {
189
+ // Step 1: Get the current branch name
190
+ const branchName = await getCurrentBranch();
191
+
192
+ // Step 2: Extract Jira ticket number
193
+ const jiraTicketId = extractJiraTicketId(branchName);
194
+
195
+ // Step 3: Fetch Jira ticket data
196
+ const jiraTicketData = await fetchJiraTicketData(jiraTicketId);
197
+ const jiraSummary = jiraTicketData.fields.summary;
198
+ console.log(
199
+ `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
200
+ );
201
+
202
+ // Step 4: Generate release notes using OpenAI
203
+ const { change_type, summary } = await generateReleaseNotes(jiraTicketData);
204
+ console.log(`Change type: ${change_type}`);
205
+ console.log(`Release note: ${summary}`);
206
+
207
+ // Step 5: Create a changeset .md file for all packages
208
+ await writeJiraChangesetFile(packages, jiraTicketId, change_type, summary);
209
+
210
+ console.log('Changeset created successfully!');
211
+ } catch (err) {
212
+ console.error(`Error: ${err.message}`);
213
+ process.exit(1);
214
+ }
215
+ }