@docupace/pipeline 1.0.0-alpha.57 → 1.0.0-alpha.59
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 +1 -1
- package/src/changeset/cli.js +90 -0
package/package.json
CHANGED
package/src/changeset/cli.js
CHANGED
|
@@ -106,5 +106,95 @@ program
|
|
|
106
106
|
await commitTagCommand();
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
program
|
|
110
|
+
.name('create-changeset')
|
|
111
|
+
.description('Creates a changeset based on the current branch and Jira ticket information')
|
|
112
|
+
.action(async () => {
|
|
113
|
+
try {
|
|
114
|
+
// Step 1: Get the current branch name
|
|
115
|
+
const branchName = (await $`git branch --show-current`).stdout.trim();
|
|
116
|
+
console.log(`Current branch: ${branchName}`);
|
|
117
|
+
|
|
118
|
+
// Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
|
|
119
|
+
const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
|
|
120
|
+
if (!jiraTicketMatch) {
|
|
121
|
+
throw new Error('No Jira ticket found in the branch name.');
|
|
122
|
+
}
|
|
123
|
+
const jiraTicketId = jiraTicketMatch[0];
|
|
124
|
+
console.log(`Extracted Jira ticket ID: ${jiraTicketId}`);
|
|
125
|
+
|
|
126
|
+
// Step 3: Fetch Jira ticket information
|
|
127
|
+
const jiraBaseUrl = process.env.JIRA_BASE_URL;
|
|
128
|
+
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
129
|
+
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
130
|
+
console.log(jiraUrl);
|
|
131
|
+
const jiraResponse = await fetch(jiraUrl, {
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Basic ${Buffer.from(jiraApiKey).toString('base64')}`,
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!jiraResponse.ok) {
|
|
139
|
+
throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
|
|
140
|
+
}
|
|
141
|
+
const jiraTicketData = await jiraResponse.json();
|
|
142
|
+
const summary = jiraTicketData.fields.summary;
|
|
143
|
+
console.log(`Jira ticket summary: ${summary}`);
|
|
144
|
+
|
|
145
|
+
// Step 4: Call OpenAI to determine change type
|
|
146
|
+
const openAiApiKey = process.env.OPENAI_API_KEY;
|
|
147
|
+
const openAiResponse = await fetch('https://api.openai.com/v1/assistants/asst_ronjCuCINK5pjLusTB9XCGYG/completions', {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: {
|
|
150
|
+
Authorization: `Bearer ${openAiApiKey}`,
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
},
|
|
153
|
+
body: JSON.stringify({
|
|
154
|
+
schema: {
|
|
155
|
+
name: 'change_request',
|
|
156
|
+
strict: true,
|
|
157
|
+
schema: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: {
|
|
160
|
+
change_type: { type: 'string', enum: ['patch', 'minor'] },
|
|
161
|
+
summary: { type: 'string' },
|
|
162
|
+
jira_ticket_id: { type: 'string' },
|
|
163
|
+
},
|
|
164
|
+
required: ['change_type', 'summary', 'jira_ticket_id'],
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
data: jiraTicketData,
|
|
169
|
+
}),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (!openAiResponse.ok) {
|
|
173
|
+
throw new Error(`Failed to call OpenAI assistant. Status: ${openAiResponse.status}`);
|
|
174
|
+
}
|
|
175
|
+
const openAiData = await openAiResponse.json();
|
|
176
|
+
const { change_type } = openAiData.result;
|
|
177
|
+
console.log(`Determined change type: ${change_type}`);
|
|
178
|
+
|
|
179
|
+
// Step 5: Create a changeset using pnpm
|
|
180
|
+
const changesetContent = `---
|
|
181
|
+
"${jiraTicketId}": ${change_type}
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
${summary}
|
|
185
|
+
`;
|
|
186
|
+
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
187
|
+
|
|
188
|
+
await $`mkdir -p ./.changeset`;
|
|
189
|
+
await $`echo ${JSON.stringify(changesetContent)} > ${changesetFile}`;
|
|
190
|
+
console.log(`Created changeset file at ${changesetFile}`);
|
|
191
|
+
|
|
192
|
+
console.log('Done!');
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.error(`Error: ${err.message}`);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
|
|
109
199
|
// Parse arguments
|
|
110
200
|
program.parse(args);
|