@docupace/pipeline 1.0.0-alpha.71 → 1.0.0-alpha.72
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/package.json +4 -1
- package/src/changeset/cli.js +51 -48
- package/src/next/copy.js +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docupace/pipeline",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.72",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@changesets/cli": "^2.27.10",
|
|
17
18
|
"commander": "^12.1.0",
|
|
19
|
+
"dotenv": "^16.4.7",
|
|
18
20
|
"js-yaml": "^4.1.0",
|
|
19
21
|
"openai": "^4.76.3",
|
|
22
|
+
"zod": "^3.24.1",
|
|
20
23
|
"zx": "^8.2.4"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
package/src/changeset/cli.js
CHANGED
|
@@ -5,7 +5,10 @@ import path from 'path';
|
|
|
5
5
|
import {validateChangesets} from "./validate.js";
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import OpenAI from "openai";
|
|
8
|
-
|
|
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']});
|
|
9
12
|
|
|
10
13
|
const program = new Command();
|
|
11
14
|
|
|
@@ -13,6 +16,28 @@ const args = process.argv;
|
|
|
13
16
|
|
|
14
17
|
const DIR = path.resolve(process.cwd());
|
|
15
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.env.PWD;
|
|
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
|
+
|
|
16
41
|
// Helper function to set Git info
|
|
17
42
|
async function setGitInfo() {
|
|
18
43
|
await $`git config --global user.email "gitops@docupace.com"`;
|
|
@@ -112,6 +137,9 @@ program
|
|
|
112
137
|
.name('create-changeset')
|
|
113
138
|
.description('Creates a changeset based on the current branch and Jira ticket information')
|
|
114
139
|
.action(async () => {
|
|
140
|
+
const mainPackage = await getMainPackage();
|
|
141
|
+
const componentName = mainPackage.name;
|
|
142
|
+
|
|
115
143
|
try {
|
|
116
144
|
// Step 1: Get the current branch name
|
|
117
145
|
const branchName = (await $`git branch --show-current`).stdout.trim();
|
|
@@ -123,17 +151,16 @@ program
|
|
|
123
151
|
throw new Error('No Jira ticket found in the branch name.');
|
|
124
152
|
}
|
|
125
153
|
const jiraTicketId = jiraTicketMatch[0];
|
|
126
|
-
console.log(`Extracted Jira ticket ID: ${jiraTicketId}`);
|
|
127
154
|
|
|
128
155
|
// Step 3: Fetch Jira ticket information
|
|
129
|
-
const jiraBaseUrl =
|
|
156
|
+
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
157
|
+
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
130
158
|
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
159
|
+
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
131
160
|
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
132
|
-
console.log(jiraApiKey);
|
|
133
|
-
console.log(jiraUrl);
|
|
134
161
|
const jiraResponse = await fetch(jiraUrl, {
|
|
135
162
|
headers: {
|
|
136
|
-
Authorization: `Basic ${Buffer.from(
|
|
163
|
+
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
137
164
|
'Content-Type': 'application/json',
|
|
138
165
|
},
|
|
139
166
|
});
|
|
@@ -142,13 +169,21 @@ program
|
|
|
142
169
|
throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
|
|
143
170
|
}
|
|
144
171
|
const jiraTicketData = await jiraResponse.json();
|
|
145
|
-
|
|
146
|
-
|
|
172
|
+
|
|
173
|
+
const jiraSummary = jiraTicketData.fields.summary;
|
|
174
|
+
|
|
175
|
+
console.log(`Generating release notes for ${jiraTicketId} - ${jiraSummary}`)
|
|
147
176
|
|
|
148
177
|
const openaiClient = new OpenAI({
|
|
149
178
|
apiKey: process.env['OPENAI_API_KEY'],
|
|
150
179
|
});
|
|
151
180
|
|
|
181
|
+
const ChangeRequestSchema = z.object({
|
|
182
|
+
change_type: z.enum(["patch", "minor"]),
|
|
183
|
+
summary: z.string(),
|
|
184
|
+
jira_ticket_id: z.string(),
|
|
185
|
+
});
|
|
186
|
+
|
|
152
187
|
const openAiResponse = await openaiClient.chat.completions.create({
|
|
153
188
|
model: "gpt-4o-mini",
|
|
154
189
|
messages: [
|
|
@@ -156,65 +191,33 @@ program
|
|
|
156
191
|
role: "system",
|
|
157
192
|
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`,
|
|
158
193
|
},
|
|
159
|
-
{
|
|
160
|
-
role: "user",
|
|
161
|
-
content: `Schema:
|
|
162
|
-
{
|
|
163
|
-
"name": "change_request",
|
|
164
|
-
"strict": true,
|
|
165
|
-
"schema": {
|
|
166
|
-
"type": "object",
|
|
167
|
-
"properties": {
|
|
168
|
-
"change_type": {
|
|
169
|
-
"type": "string",
|
|
170
|
-
"description": "The type of change requested, either a patch or minor update.",
|
|
171
|
-
"enum": [
|
|
172
|
-
"patch",
|
|
173
|
-
"minor"
|
|
174
|
-
]
|
|
175
|
-
},
|
|
176
|
-
"summary": {
|
|
177
|
-
"type": "string",
|
|
178
|
-
"description": "A brief summary of the change being requested."
|
|
179
|
-
},
|
|
180
|
-
"jira_ticket_id": {
|
|
181
|
-
"type": "string",
|
|
182
|
-
"description": "The ID of the related Jira ticket associated with this change request."
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
"required": [
|
|
186
|
-
"change_type",
|
|
187
|
-
"summary",
|
|
188
|
-
"jira_ticket_id"
|
|
189
|
-
],
|
|
190
|
-
"additionalProperties": false
|
|
191
|
-
}
|
|
192
|
-
}`,
|
|
193
|
-
},
|
|
194
194
|
{
|
|
195
195
|
role: "user",
|
|
196
196
|
content: JSON.stringify(jiraTicketData),
|
|
197
197
|
},
|
|
198
198
|
],
|
|
199
|
+
response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
|
|
200
|
+
temperature: 0
|
|
199
201
|
});
|
|
200
202
|
|
|
201
203
|
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
202
204
|
const parsedResponse = JSON.parse(assistantResponse);
|
|
203
205
|
|
|
204
|
-
const { change_type } = parsedResponse;
|
|
205
|
-
console.log(`
|
|
206
|
+
const { change_type, summary } = parsedResponse;
|
|
207
|
+
console.log(`Change type: ${change_type}`);
|
|
208
|
+
console.log(`Release note: ${summary}`);
|
|
206
209
|
|
|
207
210
|
// Step 5: Create a changeset using pnpm
|
|
208
211
|
const changesetContent = `---
|
|
209
|
-
"${
|
|
212
|
+
"${componentName}": ${change_type}
|
|
210
213
|
---
|
|
211
214
|
|
|
212
|
-
${summary}
|
|
215
|
+
${summary} [${jiraTicketId}]
|
|
213
216
|
`;
|
|
214
217
|
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
215
218
|
|
|
216
219
|
await $`mkdir -p ./.changeset`;
|
|
217
|
-
await
|
|
220
|
+
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
218
221
|
console.log(`Created changeset file at ${changesetFile}`);
|
|
219
222
|
|
|
220
223
|
console.log('Done!');
|
package/src/next/copy.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { $ } from 'zx';
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
TARGET_ENV
|
|
6
|
+
PUBLISH_TAG
|
|
7
|
+
REPOSITORY_NAME
|
|
8
|
+
*/
|
|
3
9
|
export async function copy() {
|
|
4
10
|
const JF_REGISTRY_URL = 'registry.paperout.com';
|
|
5
|
-
const SOURCE_REGISTRY = `${JF_REGISTRY_URL}/${process.env.
|
|
6
|
-
const TARGET_REGISTRY = `${JF_REGISTRY_URL}/${process.env.
|
|
7
|
-
const IMAGE_NAME = `${process.env.
|
|
11
|
+
const SOURCE_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-dev-docker-local`;
|
|
12
|
+
const TARGET_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-${process.env.TARGET_ENV}-docker-local`;
|
|
13
|
+
const IMAGE_NAME = `${process.env.REPOSITORY_NAME}:${process.env.PUBLISH_TAG}`;
|
|
8
14
|
const SOURCE_FULL_IMAGE_NAME = `${SOURCE_REGISTRY}/${IMAGE_NAME}`;
|
|
9
15
|
const TARGET_FULL_IMAGE_NAME = `${TARGET_REGISTRY}/${IMAGE_NAME}`;
|
|
10
16
|
|