@docupace/pipeline 1.0.40 → 1.0.41
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/.prettierrc.cjs +12 -12
- package/bin/next-changeset-validate.sh +8 -8
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +117 -117
- package/next/sonar.sh +23 -23
- package/package.json +1 -1
- package/src/auth0/alias.js +72 -72
- package/src/auth0/cli.js +76 -76
- package/src/auth0/configure.js +783 -783
- package/src/auth0/export.js +43 -43
- package/src/auth0/metadata.js +132 -132
- package/src/auth0/vault.js +107 -107
- package/src/changeset/cli.js +334 -334
- package/src/changeset/validate.js +47 -47
- package/src/jenkins/setParams.groovy +59 -59
- package/src/next/alias.js +53 -53
- package/src/next/apache.js +40 -40
- package/src/next/config.js +99 -99
- package/src/next/copy.js +55 -55
- package/src/next/haproxy.js +2 -1
- package/src/next/jira.js +83 -83
- package/src/next/pipline.js +114 -114
- package/src/next/publish.js +48 -48
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/vault.js +43 -43
- package/terraform/apply.sh +26 -26
- package/terraform/init.sh +61 -61
- package/terraform/plan.sh +63 -63
- package/terraform/validate.sh +17 -17
- package/commit-message +0 -40
- package/pull-request-sum +0 -42
- package/pull-request-summary +0 -34
- package/pull-request-title +0 -66
package/src/changeset/cli.js
CHANGED
|
@@ -1,334 +1,334 @@
|
|
|
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
|
-
import { makeJiraRequest, updateComponentVersion } from '../next/jira.js';
|
|
12
|
-
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
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
|
-
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
|
-
}
|
|
41
|
-
|
|
42
|
-
async function fileExists(filePath) {
|
|
43
|
-
try {
|
|
44
|
-
await fs.promises.access(filePath);
|
|
45
|
-
return true;
|
|
46
|
-
} catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
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;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
throw new Error('Main package.json not found');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Helper function to set Git info
|
|
65
|
-
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`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const changeSetPackage = `{
|
|
72
|
-
"name": "changeset-package",
|
|
73
|
-
"version": "1.0.0",
|
|
74
|
-
"description": "",
|
|
75
|
-
"scripts": {
|
|
76
|
-
},
|
|
77
|
-
"type": "module",
|
|
78
|
-
"keywords": [],
|
|
79
|
-
"author": "",
|
|
80
|
-
"license": "ISC",
|
|
81
|
-
"dependencies": {},
|
|
82
|
-
"devDependencies": {
|
|
83
|
-
"@changesets/cli": "^2.27.10"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
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 };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function commitTagCommand() {
|
|
138
|
-
console.log('📌 Checking for updates to commit...');
|
|
139
|
-
|
|
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
|
-
}
|
|
146
|
-
|
|
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.`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Command: validate
|
|
161
|
-
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
|
-
});
|
|
179
|
-
// Command: version
|
|
180
|
-
program
|
|
181
|
-
.command('version')
|
|
182
|
-
.description('Run Changeset versioning')
|
|
183
|
-
.action(async () => {
|
|
184
|
-
await versionCommand();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// Command: commit-and-tag
|
|
188
|
-
program
|
|
189
|
-
.command('commit-tag')
|
|
190
|
-
.description('Commit and tag the new version')
|
|
191
|
-
.action(async () => {
|
|
192
|
-
await commitTagCommand();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// Command: all
|
|
196
|
-
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
|
-
});
|
|
230
|
-
|
|
231
|
-
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
|
-
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
253
|
-
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
254
|
-
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
255
|
-
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
256
|
-
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
257
|
-
const jiraResponse = await fetch(jiraUrl, {
|
|
258
|
-
headers: {
|
|
259
|
-
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
260
|
-
'Content-Type': 'application/json',
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
if (!jiraResponse.ok) {
|
|
265
|
-
throw new Error(
|
|
266
|
-
`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
const jiraTicketData = await jiraResponse.json();
|
|
270
|
-
|
|
271
|
-
const jiraSummary = jiraTicketData.fields.summary;
|
|
272
|
-
|
|
273
|
-
console.log(
|
|
274
|
-
`Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
const openaiClient = new OpenAI({
|
|
278
|
-
apiKey: process.env['OPENAI_API_KEY'],
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
const ChangeRequestSchema = z.object({
|
|
282
|
-
change_type: z.enum(['patch', 'minor']),
|
|
283
|
-
summary: z.string(),
|
|
284
|
-
jira_ticket_id: z.string(),
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
const openAiResponse = await openaiClient.chat.completions.create({
|
|
288
|
-
model: 'gpt-4o-mini',
|
|
289
|
-
messages: [
|
|
290
|
-
{
|
|
291
|
-
role: 'system',
|
|
292
|
-
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`,
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
role: 'user',
|
|
296
|
-
content: JSON.stringify(jiraTicketData),
|
|
297
|
-
},
|
|
298
|
-
],
|
|
299
|
-
response_format: zodResponseFormat(
|
|
300
|
-
ChangeRequestSchema,
|
|
301
|
-
'changeset_schema',
|
|
302
|
-
),
|
|
303
|
-
temperature: 0,
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
307
|
-
const parsedResponse = JSON.parse(assistantResponse);
|
|
308
|
-
|
|
309
|
-
const { change_type, summary } = parsedResponse;
|
|
310
|
-
console.log(`Change type: ${change_type}`);
|
|
311
|
-
console.log(`Release note: ${summary}`);
|
|
312
|
-
|
|
313
|
-
// Step 5: Create a changeset .md file
|
|
314
|
-
const changesetContent = `---
|
|
315
|
-
"${componentName}": ${change_type}
|
|
316
|
-
---
|
|
317
|
-
|
|
318
|
-
${summary} [${jiraTicketId}]
|
|
319
|
-
`;
|
|
320
|
-
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
321
|
-
|
|
322
|
-
await createChangesetDirectory();
|
|
323
|
-
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
324
|
-
console.log(`Created changeset file at ${changesetFile}`);
|
|
325
|
-
|
|
326
|
-
console.log('Done!');
|
|
327
|
-
} catch (err) {
|
|
328
|
-
console.error(`Error: ${err.message}`);
|
|
329
|
-
process.exit(1);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// Parse arguments
|
|
334
|
-
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
|
+
import { makeJiraRequest, updateComponentVersion } from '../next/jira.js';
|
|
12
|
+
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
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
|
+
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
|
+
}
|
|
41
|
+
|
|
42
|
+
async function fileExists(filePath) {
|
|
43
|
+
try {
|
|
44
|
+
await fs.promises.access(filePath);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
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;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error('Main package.json not found');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Helper function to set Git info
|
|
65
|
+
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`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const changeSetPackage = `{
|
|
72
|
+
"name": "changeset-package",
|
|
73
|
+
"version": "1.0.0",
|
|
74
|
+
"description": "",
|
|
75
|
+
"scripts": {
|
|
76
|
+
},
|
|
77
|
+
"type": "module",
|
|
78
|
+
"keywords": [],
|
|
79
|
+
"author": "",
|
|
80
|
+
"license": "ISC",
|
|
81
|
+
"dependencies": {},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@changesets/cli": "^2.27.10"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
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 };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function commitTagCommand() {
|
|
138
|
+
console.log('📌 Checking for updates to commit...');
|
|
139
|
+
|
|
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
|
+
}
|
|
146
|
+
|
|
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.`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Command: validate
|
|
161
|
+
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
|
+
});
|
|
179
|
+
// Command: version
|
|
180
|
+
program
|
|
181
|
+
.command('version')
|
|
182
|
+
.description('Run Changeset versioning')
|
|
183
|
+
.action(async () => {
|
|
184
|
+
await versionCommand();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Command: commit-and-tag
|
|
188
|
+
program
|
|
189
|
+
.command('commit-tag')
|
|
190
|
+
.description('Commit and tag the new version')
|
|
191
|
+
.action(async () => {
|
|
192
|
+
await commitTagCommand();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Command: all
|
|
196
|
+
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
|
+
});
|
|
230
|
+
|
|
231
|
+
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
|
+
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
253
|
+
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
254
|
+
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
255
|
+
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
256
|
+
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
257
|
+
const jiraResponse = await fetch(jiraUrl, {
|
|
258
|
+
headers: {
|
|
259
|
+
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
if (!jiraResponse.ok) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
const jiraTicketData = await jiraResponse.json();
|
|
270
|
+
|
|
271
|
+
const jiraSummary = jiraTicketData.fields.summary;
|
|
272
|
+
|
|
273
|
+
console.log(
|
|
274
|
+
`Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const openaiClient = new OpenAI({
|
|
278
|
+
apiKey: process.env['OPENAI_API_KEY'],
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const ChangeRequestSchema = z.object({
|
|
282
|
+
change_type: z.enum(['patch', 'minor']),
|
|
283
|
+
summary: z.string(),
|
|
284
|
+
jira_ticket_id: z.string(),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const openAiResponse = await openaiClient.chat.completions.create({
|
|
288
|
+
model: 'gpt-4o-mini',
|
|
289
|
+
messages: [
|
|
290
|
+
{
|
|
291
|
+
role: 'system',
|
|
292
|
+
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`,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
role: 'user',
|
|
296
|
+
content: JSON.stringify(jiraTicketData),
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
response_format: zodResponseFormat(
|
|
300
|
+
ChangeRequestSchema,
|
|
301
|
+
'changeset_schema',
|
|
302
|
+
),
|
|
303
|
+
temperature: 0,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
307
|
+
const parsedResponse = JSON.parse(assistantResponse);
|
|
308
|
+
|
|
309
|
+
const { change_type, summary } = parsedResponse;
|
|
310
|
+
console.log(`Change type: ${change_type}`);
|
|
311
|
+
console.log(`Release note: ${summary}`);
|
|
312
|
+
|
|
313
|
+
// Step 5: Create a changeset .md file
|
|
314
|
+
const changesetContent = `---
|
|
315
|
+
"${componentName}": ${change_type}
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
${summary} [${jiraTicketId}]
|
|
319
|
+
`;
|
|
320
|
+
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
321
|
+
|
|
322
|
+
await createChangesetDirectory();
|
|
323
|
+
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
324
|
+
console.log(`Created changeset file at ${changesetFile}`);
|
|
325
|
+
|
|
326
|
+
console.log('Done!');
|
|
327
|
+
} catch (err) {
|
|
328
|
+
console.error(`Error: ${err.message}`);
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Parse arguments
|
|
334
|
+
program.parse(args);
|