@docupace/pipeline 1.0.86 → 1.0.87
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/designs/convert-to-canny.md +20 -0
- package/package.json +10 -4
- package/src/auth0/configure.js +1 -3
- package/src/changeset/canny.js +119 -0
- package/src/changeset/changelog-module.cjs +37 -0
- package/src/changeset/changelog.js +210 -0
- package/src/changeset/cli.js +27 -42
- package/src/changeset/config.js +20 -0
- package/src/changeset/convert.js +461 -0
- package/src/changeset/create-canny.js +86 -0
- package/src/changeset/create-simple.js +131 -0
- package/src/changeset/create.js +41 -123
- package/src/changeset/openai.js +567 -0
- package/src/changeset/validate.js +1 -12
- package/src/changeset/version.js +25 -3
- package/src/index.mjs +2 -0
- package/src/lib/merge-driver.js +1 -5
- package/src/merge/cli-merge-all.js +1 -2
- package/src/merge/cli-merge.js +4 -4
- package/src/merge/merge-changelog.js +1 -1
- package/src/merge/pr.js +3 -3
- package/src/next/connect.js +0 -9
- package/src/next/deploy.js +2 -2
- package/src/next/jira.js +51 -0
- package/src/next/util.js +1 -1
- package/testCanny.sh +4 -0
package/src/changeset/create.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
import { zodResponseFormat } from 'openai/helpers/zod';
|
|
4
1
|
import fs from 'fs';
|
|
5
2
|
import path from 'path';
|
|
6
3
|
import inquirer from 'inquirer';
|
|
7
4
|
import { getMainPackage, getPackage, findJiraTicketId } from './util.js';
|
|
8
5
|
import { getPackageNames } from './package-util.js';
|
|
9
6
|
import { execSync } from 'child_process';
|
|
7
|
+
import { createChangesetForPackageSimple } from './create-simple.js';
|
|
8
|
+
import { createChangesetForPackageCanny } from './create-canny.js';
|
|
10
9
|
|
|
11
|
-
async function createChangesetDirectory() {
|
|
10
|
+
export async function createChangesetDirectory() {
|
|
12
11
|
try {
|
|
13
12
|
// Use path.join to build a safe path to `.changeset`
|
|
14
13
|
const targetDir = path.join(process.cwd(), '.changeset');
|
|
@@ -23,7 +22,7 @@ async function createChangesetDirectory() {
|
|
|
23
22
|
/**
|
|
24
23
|
* Gets the current git branch name
|
|
25
24
|
*/
|
|
26
|
-
async function getCurrentBranch() {
|
|
25
|
+
export async function getCurrentBranch() {
|
|
27
26
|
try {
|
|
28
27
|
const branchName = execSync('git branch --show-current', {
|
|
29
28
|
encoding: 'utf8',
|
|
@@ -39,7 +38,7 @@ async function getCurrentBranch() {
|
|
|
39
38
|
/**
|
|
40
39
|
* Extracts a Jira ticket ID from a branch name
|
|
41
40
|
*/
|
|
42
|
-
function extractJiraTicketId(branchName) {
|
|
41
|
+
export function extractJiraTicketId(branchName) {
|
|
43
42
|
const jiraTicketId = findJiraTicketId(branchName);
|
|
44
43
|
if (!jiraTicketId) {
|
|
45
44
|
throw new Error('No Jira ticket found in the branch name.');
|
|
@@ -47,103 +46,11 @@ function extractJiraTicketId(branchName) {
|
|
|
47
46
|
return jiraTicketId;
|
|
48
47
|
}
|
|
49
48
|
|
|
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
49
|
/**
|
|
143
50
|
* Main function to create a changeset
|
|
144
51
|
*/
|
|
145
52
|
|
|
146
|
-
export async function createChangeset() {
|
|
53
|
+
export async function createChangeset(selectedJiraIssueKey) {
|
|
147
54
|
const packages = getPackageNames();
|
|
148
55
|
|
|
149
56
|
if (packages.length > 1) {
|
|
@@ -177,39 +84,50 @@ export async function createChangeset() {
|
|
|
177
84
|
}),
|
|
178
85
|
);
|
|
179
86
|
|
|
180
|
-
await createChangesetForPackage(
|
|
87
|
+
await createChangesetForPackage(
|
|
88
|
+
selectedPackageContents,
|
|
89
|
+
selectedJiraIssueKey,
|
|
90
|
+
);
|
|
181
91
|
} else {
|
|
182
92
|
const mainPackage = await getMainPackage();
|
|
183
|
-
await createChangesetForPackage([mainPackage]);
|
|
93
|
+
await createChangesetForPackage([mainPackage], selectedJiraIssueKey);
|
|
184
94
|
}
|
|
185
95
|
}
|
|
186
96
|
|
|
187
|
-
export async function createChangesetForPackage(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
97
|
+
export async function createChangesetForPackage(
|
|
98
|
+
packages,
|
|
99
|
+
selectedJiraIssueKey,
|
|
100
|
+
) {
|
|
101
|
+
// Check if we should use canny changelog based on config
|
|
102
|
+
const shouldUseCanny = await checkForCannyChangelog();
|
|
191
103
|
|
|
192
|
-
|
|
193
|
-
|
|
104
|
+
if (shouldUseCanny) {
|
|
105
|
+
return await createChangesetForPackageCanny(packages, selectedJiraIssueKey);
|
|
106
|
+
} else {
|
|
107
|
+
return await createChangesetForPackageSimple(packages);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
194
110
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
);
|
|
111
|
+
/**
|
|
112
|
+
* Checks if the changeset config uses the canny changelog generator
|
|
113
|
+
*/
|
|
114
|
+
async function checkForCannyChangelog() {
|
|
115
|
+
try {
|
|
116
|
+
const configPath = path.join(process.cwd(), '.changeset', 'config.json');
|
|
201
117
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
118
|
+
// Check if config file exists
|
|
119
|
+
if (!fs.existsSync(configPath)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
206
122
|
|
|
207
|
-
//
|
|
208
|
-
await
|
|
123
|
+
// Read and parse config
|
|
124
|
+
const configContent = await fs.promises.readFile(configPath, 'utf8');
|
|
125
|
+
const config = JSON.parse(configContent);
|
|
209
126
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
127
|
+
// Check if changelog is set to the canny generator
|
|
128
|
+
return config.changelog === '@docupace/pipeline/changelogCanny';
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Error reading changeset config:', error);
|
|
131
|
+
return false;
|
|
214
132
|
}
|
|
215
133
|
}
|