-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcreateQuestionsAndAssignForReview.js
More file actions
96 lines (81 loc) · 3.24 KB
/
Copy pathcreateQuestionsAndAssignForReview.js
File metadata and controls
96 lines (81 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Create Questions and Assign For Review Action
* Creates subtasks based on AI-generated questions and assigns parent ticket for review
*/
// Import common helper functions
const { assignForReview, extractTicketKey } = require('./common/jiraHelpers.js');
const { parseQuestionsResponse, buildSummary, buildDescription } = require('./common/aiResponseParser.js');
function processQuestionTickets(response, parentKey) {
const questions = parseQuestionsResponse(response);
if (questions.length === 0) {
console.log('No follow-up questions detected, skipping ticket creation.');
return [];
}
const projectKey = parentKey.split('-')[0];
const createdTickets = [];
questions.forEach(function(question, index) {
const summary = buildSummary(question.summary, index);
const description = buildDescription(question);
try {
// Create ticket with priority set directly
const fieldsJson = {
summary: summary,
description: description,
issuetype: { name: 'Subtask' },
parent: { key: parentKey }
};
// Add priority if provided
if (question.priority) {
fieldsJson.priority = { name: question.priority };
}
const result = jira_create_ticket_with_json({
project: projectKey,
fieldsJson: fieldsJson
});
const createdKey = extractTicketKey(result);
createdTickets.push({
summary: summary,
priority: question.priority,
key: createdKey
});
console.log('Created question subtask ' + (createdKey || '(unknown key)') + ' with priority ' + (question.priority || 'default') + ' for summary "' + summary + '"');
} catch (error) {
console.error('Failed to create question subtask for summary "' + summary + '":', error);
createdTickets.push({
summary: summary,
priority: question.priority,
error: error.toString()
});
}
});
return createdTickets;
}
function action(params) {
try {
const ticketKey = params.ticket.key;
const initiatorId = params.initiator;
console.log("Processing ticket:", ticketKey);
const createdQuestionTickets = processQuestionTickets(params.response, ticketKey);
// Add AI-generated label
jira_add_label({
key: ticketKey,
label: 'ai_questions_asked'
});
// Use common assignForReview function for post-processing
const assignResult = assignForReview(ticketKey, initiatorId);
if (!assignResult.success) {
return assignResult;
}
return {
success: true,
message: `Ticket ${ticketKey} assigned, moved to In Review, created ${createdQuestionTickets.length} question subtasks`,
createdQuestions: createdQuestionTickets
};
} catch (error) {
console.error("❌ Error:", error);
return {
success: false,
error: error.toString()
};
}
}