@docupace/pipeline 1.0.2-3.test7 → 1.0.2-3.test8
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 +75 -75
- package/src/auth0/cli.js +41 -41
- package/src/auth0/vault.js +107 -107
- package/src/changeset/cli.js +281 -281
- 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/connect.js +159 -171
- package/src/next/deploy.js +81 -1
- package/src/next/pipline.js +0 -1
- 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 +47 -47
- package/terraform/plan.sh +54 -54
- package/terraform/validate.sh +17 -17
package/src/changeset/cli.js
CHANGED
|
@@ -1,281 +1,281 @@
|
|
|
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);
|
|
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);
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
export async function validateChangesets(directoryPath) {
|
|
5
|
-
try {
|
|
6
|
-
// Step 1: Read the directory for md files excluding README.md
|
|
7
|
-
const allFiles = fs.readdirSync(directoryPath);
|
|
8
|
-
const mdFiles = allFiles.filter(
|
|
9
|
-
(file) => file.endsWith('.md') && file !== 'README.md',
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
// Step 2: Check for pre.json and parse it
|
|
13
|
-
const preJsonPath = path.join(directoryPath, 'pre.json');
|
|
14
|
-
let preJson;
|
|
15
|
-
|
|
16
|
-
if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
|
|
17
|
-
throw new Error('Error: No pre.json and no md files found.');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (fs.existsSync(preJsonPath)) {
|
|
21
|
-
preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
|
|
22
|
-
|
|
23
|
-
if (preJson.mode == 'pre') {
|
|
24
|
-
// Step 4a: Get list of changesets from pre.json
|
|
25
|
-
const changesets = preJson.changesets || [];
|
|
26
|
-
const changesetNames = changesets.map((change) => change);
|
|
27
|
-
|
|
28
|
-
// Step 4b: Match files with the list of changesets
|
|
29
|
-
const mdFileNamesWithoutExt = mdFiles.map((file) =>
|
|
30
|
-
path.basename(file, '.md'),
|
|
31
|
-
);
|
|
32
|
-
const unmatchedFiles = mdFileNamesWithoutExt.filter(
|
|
33
|
-
(fileName) => !changesetNames.includes(fileName),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
if (unmatchedFiles.length == 0) {
|
|
37
|
-
throw new Error('Error: No new MD files found:');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
console.log('Validation successful.');
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.log(error.message);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export async function validateChangesets(directoryPath) {
|
|
5
|
+
try {
|
|
6
|
+
// Step 1: Read the directory for md files excluding README.md
|
|
7
|
+
const allFiles = fs.readdirSync(directoryPath);
|
|
8
|
+
const mdFiles = allFiles.filter(
|
|
9
|
+
(file) => file.endsWith('.md') && file !== 'README.md',
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// Step 2: Check for pre.json and parse it
|
|
13
|
+
const preJsonPath = path.join(directoryPath, 'pre.json');
|
|
14
|
+
let preJson;
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
|
|
17
|
+
throw new Error('Error: No pre.json and no md files found.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (fs.existsSync(preJsonPath)) {
|
|
21
|
+
preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
|
|
22
|
+
|
|
23
|
+
if (preJson.mode == 'pre') {
|
|
24
|
+
// Step 4a: Get list of changesets from pre.json
|
|
25
|
+
const changesets = preJson.changesets || [];
|
|
26
|
+
const changesetNames = changesets.map((change) => change);
|
|
27
|
+
|
|
28
|
+
// Step 4b: Match files with the list of changesets
|
|
29
|
+
const mdFileNamesWithoutExt = mdFiles.map((file) =>
|
|
30
|
+
path.basename(file, '.md'),
|
|
31
|
+
);
|
|
32
|
+
const unmatchedFiles = mdFileNamesWithoutExt.filter(
|
|
33
|
+
(fileName) => !changesetNames.includes(fileName),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (unmatchedFiles.length == 0) {
|
|
37
|
+
throw new Error('Error: No new MD files found:');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('Validation successful.');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.log(error.message);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|