@docupace/pipeline 1.0.0-alpha.57 → 1.0.0-alpha.58

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.0-alpha.57",
3
+ "version": "1.0.0-alpha.58",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -106,5 +106,93 @@ 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 jiraResponse = await fetch(`${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`, {
130
+ headers: {
131
+ Authorization: `Basic ${Buffer.from(jiraApiKey).toString('base64')}`,
132
+ 'Content-Type': 'application/json',
133
+ },
134
+ });
135
+
136
+ if (!jiraResponse.ok) {
137
+ throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
138
+ }
139
+ const jiraTicketData = await jiraResponse.json();
140
+ const summary = jiraTicketData.fields.summary;
141
+ console.log(`Jira ticket summary: ${summary}`);
142
+
143
+ // Step 4: Call OpenAI to determine change type
144
+ const openAiApiKey = process.env.OPENAI_API_KEY;
145
+ const openAiResponse = await fetch('https://api.openai.com/v1/assistants/asst_ronjCuCINK5pjLusTB9XCGYG/completions', {
146
+ method: 'POST',
147
+ headers: {
148
+ Authorization: `Bearer ${openAiApiKey}`,
149
+ 'Content-Type': 'application/json',
150
+ },
151
+ body: JSON.stringify({
152
+ schema: {
153
+ name: 'change_request',
154
+ strict: true,
155
+ schema: {
156
+ type: 'object',
157
+ properties: {
158
+ change_type: { type: 'string', enum: ['patch', 'minor'] },
159
+ summary: { type: 'string' },
160
+ jira_ticket_id: { type: 'string' },
161
+ },
162
+ required: ['change_type', 'summary', 'jira_ticket_id'],
163
+ additionalProperties: false,
164
+ },
165
+ },
166
+ data: jiraTicketData,
167
+ }),
168
+ });
169
+
170
+ if (!openAiResponse.ok) {
171
+ throw new Error(`Failed to call OpenAI assistant. Status: ${openAiResponse.status}`);
172
+ }
173
+ const openAiData = await openAiResponse.json();
174
+ const { change_type } = openAiData.result;
175
+ console.log(`Determined change type: ${change_type}`);
176
+
177
+ // Step 5: Create a changeset using pnpm
178
+ const changesetContent = `---
179
+ "${jiraTicketId}": ${change_type}
180
+ ---
181
+
182
+ ${summary}
183
+ `;
184
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
185
+
186
+ await $`mkdir -p ./.changeset`;
187
+ await $`echo ${JSON.stringify(changesetContent)} > ${changesetFile}`;
188
+ console.log(`Created changeset file at ${changesetFile}`);
189
+
190
+ console.log('Done!');
191
+ } catch (err) {
192
+ console.error(`Error: ${err.message}`);
193
+ }
194
+ });
195
+
196
+
109
197
  // Parse arguments
110
198
  program.parse(args);