@khala/jira-ai
Version:
Interactive CLI tool for JIRA issue management with Gemini AI
59 lines (50 loc) • 2.23 kB
JavaScript
import { input } from '@inquirer/prompts';
import { processBatches } from '../helpers/batchProcessing.js';
import { prepareIssuesForGemini, cleanGeminiResponse } from '../helpers/dataProcessing.js';
import { saveRawResponse } from '../helpers/fileOperations.js';
import { validateEditInstructions } from '../cli/prompts.js';
import { displayAiResponse } from '../cli/display.js';
/**
* Handle edit issues action
* @param {Array} issues - JIRA issues to edit
* @param {Object} gemini - Gemini bot instance
* @returns {Array} Processed issues
*/
export async function handleEditIssues(issues, gemini) {
const editInstructions = await input({
message: 'Enter instructions for editing the issues:',
validate: validateEditInstructions,
});
return await processBatches(issues, async (batch, batchNumber) => {
const sanitizedBatch = prepareIssuesForGemini(batch);
const prompt = `Please edit these JIRA issues according to the following instructions: ${editInstructions}
Instructions:
- Return the modified issues in the same JSON format
- Only modify fields that need to be changed according to the instructions
- Preserve the original structure and any unchanged fields
- For each modification made, add an "aiEdit" field with the following structure:
{
"modified": true,
"confidence": "85%",
"changes": ["field1", "field2"],
"reasoning": "Brief explanation of why these changes were made"
}
Note: Use percentage values for confidence (e.g., "95%", "80%", "65%") based on how certain you are about the modifications.
Issues to edit:
${JSON.stringify(sanitizedBatch, null, 2)}`;
const response = await gemini.generateText(prompt);
displayAiResponse(response, '📝 AI Response for this batch');
// Save raw response for debugging
saveRawResponse(response, batchNumber, 'edit');
try {
// Clean and parse the response as JSON
const cleanedResponse = cleanGeminiResponse(response);
const editedIssues = JSON.parse(cleanedResponse);
return Array.isArray(editedIssues) ? editedIssues : batch;
} catch (e) {
console.log('JSON Parse Error:', e.message);
// If parsing fails, return original batch
return batch;
}
});
}