Split the card header into separate blocks for readability and keep reporter only in the footer instead of details. Co-authored-by: Cursor <cursoragent@cursor.com>
192 lines
6.7 KiB
JavaScript
192 lines
6.7 KiB
JavaScript
import { buildDetailLinesForRequestType } from '../lib/requestTypeFields.js';
|
|
|
|
const PORTAL_BASE_URL = 'https://aeo.atlassian.net/servicedesk/customer/portal/135';
|
|
|
|
function appendDetailLines(detailText, lines) {
|
|
for (const line of lines) {
|
|
detailText += ` - **${line.label}:** ${line.value}\n`;
|
|
}
|
|
return detailText;
|
|
}
|
|
|
|
function getRequestTypeId(jiraTicket) {
|
|
return jiraTicket.issue.fields?.customfield_10010?.requestType?.id;
|
|
}
|
|
|
|
function getRequestTypeLabel(jiraTicket) {
|
|
const requestTypeField = jiraTicket.issue.fields?.customfield_10010;
|
|
if (!requestTypeField) {
|
|
return null;
|
|
}
|
|
return requestTypeField.errorMessage || requestTypeField.requestType?.name || null;
|
|
}
|
|
|
|
function buildHeaderBlocks(jiraTicket) {
|
|
const issueKey = jiraTicket.issue.key;
|
|
const blocks = [
|
|
{
|
|
type: 'TextBlock',
|
|
text: `[${issueKey}](${PORTAL_BASE_URL}/${issueKey})`,
|
|
wrap: true,
|
|
weight: 'Bolder',
|
|
size: 'Medium',
|
|
},
|
|
{
|
|
type: 'TextBlock',
|
|
text: jiraTicket.issue.fields.status.name,
|
|
wrap: true,
|
|
isSubtle: true,
|
|
spacing: 'None',
|
|
},
|
|
];
|
|
|
|
const requestTypeLabel = getRequestTypeLabel(jiraTicket);
|
|
if (requestTypeLabel) {
|
|
blocks.push({
|
|
type: 'TextBlock',
|
|
text: `**Request Type:** ${requestTypeLabel}`,
|
|
wrap: true,
|
|
spacing: 'Medium',
|
|
});
|
|
}
|
|
|
|
if (jiraTicket.issue.fields.summary) {
|
|
blocks.push({
|
|
type: 'TextBlock',
|
|
text: `**Summary:** ${jiraTicket.issue.fields.summary}`,
|
|
wrap: true,
|
|
spacing: 'Small',
|
|
});
|
|
}
|
|
|
|
return blocks;
|
|
}
|
|
|
|
function buildPlainTextHeader(jiraTicket) {
|
|
const issueKey = jiraTicket.issue.key;
|
|
let text = `[${issueKey}](${PORTAL_BASE_URL}/${issueKey})\n`;
|
|
text += `${jiraTicket.issue.fields.status.name}\n`;
|
|
|
|
const requestTypeLabel = getRequestTypeLabel(jiraTicket);
|
|
if (requestTypeLabel) {
|
|
text += `\n**Request Type:** ${requestTypeLabel}\n`;
|
|
}
|
|
if (jiraTicket.issue.fields.summary) {
|
|
text += `**Summary:** ${jiraTicket.issue.fields.summary}\n`;
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
function buildCardPayload({ jiraTicket, detailText, assignmentText = '' }) {
|
|
const body = [...buildHeaderBlocks(jiraTicket)];
|
|
|
|
if (detailText.trim()) {
|
|
body.push({
|
|
type: 'TextBlock',
|
|
wrap: true,
|
|
text: detailText.trim(),
|
|
separator: true,
|
|
spacing: 'Medium',
|
|
});
|
|
}
|
|
|
|
if (assignmentText.trim()) {
|
|
body.push({
|
|
type: 'TextBlock',
|
|
text: assignmentText.trim(),
|
|
wrap: true,
|
|
separator: true,
|
|
spacing: 'Medium',
|
|
});
|
|
}
|
|
|
|
const requestCard = {
|
|
type: 'AdaptiveCard',
|
|
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
|
|
version: '1.2',
|
|
body,
|
|
actions: [
|
|
{
|
|
type: 'Action.OpenUrl',
|
|
title: 'Open Request',
|
|
url: `${PORTAL_BASE_URL}/${jiraTicket.issue.key}`,
|
|
},
|
|
{
|
|
type: 'Action.Submit',
|
|
title: 'Remove Card',
|
|
style: 'destructive',
|
|
data: { cardType: 'requestApproval', action: 'removeCard' },
|
|
},
|
|
],
|
|
};
|
|
|
|
let requestText = buildPlainTextHeader(jiraTicket);
|
|
if (detailText.trim()) {
|
|
requestText += `---\n${detailText}`;
|
|
}
|
|
if (assignmentText.trim()) {
|
|
requestText += `---\n${assignmentText}`;
|
|
}
|
|
|
|
return { card: requestCard, message: requestText };
|
|
}
|
|
|
|
export function buildChangeApproval(jiraTicket, log) {
|
|
return new Promise(function (resolve) {
|
|
let detailText = '**Details:**\n';
|
|
if (jiraTicket.issue.fields.description) {
|
|
detailText += `**Description:** ${jiraTicket.issue.fields.description}\n`;
|
|
}
|
|
|
|
const requestTypeId = getRequestTypeId(jiraTicket);
|
|
if (requestTypeId) {
|
|
detailText = appendDetailLines(detailText, buildDetailLinesForRequestType(jiraTicket, requestTypeId));
|
|
} else {
|
|
if (jiraTicket.issue.fields.customfield_10080) { detailText += ` - **Risk:** ${jiraTicket.issue.fields.customfield_10080.value}\n`; }
|
|
if (jiraTicket.issue.fields.customfield_10004) { detailText += ` - **Impact:** ${jiraTicket.issue.fields.customfield_10004.value}\n`; }
|
|
if (jiraTicket.issue.fields.customfield_10256) { detailText += ` - **Business Impact:** ${jiraTicket.issue.fields.customfield_10256}\n`; }
|
|
if (jiraTicket.issue.fields.customfield_10252) { detailText += ` - **Business Justification:** ${jiraTicket.issue.fields.customfield_10252}\n`; }
|
|
if (jiraTicket.issue.fields.customfield_10257) {
|
|
const changeDate = new Date(jiraTicket.issue.fields.customfield_10257).toLocaleDateString();
|
|
const changeTime = new Date(jiraTicket.issue.fields.customfield_10257).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true });
|
|
detailText += ` - **Implementation Date:** ${changeDate} ${changeTime}\n`;
|
|
}
|
|
}
|
|
|
|
const hasDetails = detailText.replace('**Details:**\n', '').trim().length > 0;
|
|
log.logDebug('buildChangeApproval', `Built card for ${jiraTicket.issue.key}`);
|
|
resolve(buildCardPayload({
|
|
jiraTicket,
|
|
detailText: hasDetails ? detailText : '',
|
|
}));
|
|
});
|
|
}
|
|
|
|
export function buildRequestApproval(jiraTicket) {
|
|
return new Promise(function (resolve) {
|
|
let detailText = '**Details:**\n';
|
|
const requestTypeId = getRequestTypeId(jiraTicket);
|
|
if (requestTypeId) {
|
|
detailText = appendDetailLines(detailText, buildDetailLinesForRequestType(jiraTicket, requestTypeId));
|
|
} else if (jiraTicket.issue.fields.customfield_10314) {
|
|
detailText += ` - **Person:** ${jiraTicket.issue.fields.customfield_10346}, ${jiraTicket.issue.fields.customfield_10314}`;
|
|
if (jiraTicket.issue.fields.customfield_10310) { detailText += ` (${jiraTicket.issue.fields.customfield_10310.value})`; }
|
|
detailText += '\n';
|
|
if (jiraTicket.issue.fields.customfield_10318) { detailText += ` - **Position:** ${jiraTicket.issue.fields.customfield_10318}\n`; }
|
|
}
|
|
|
|
const hasDetails = detailText.replace('**Details:**\n', '').trim().length > 0;
|
|
|
|
let assignmentText = '';
|
|
if (jiraTicket.issue.fields.reporter) {
|
|
assignmentText += `**Reporter:** ${jiraTicket.issue.fields.reporter.displayName}\n`;
|
|
}
|
|
|
|
resolve(buildCardPayload({
|
|
jiraTicket,
|
|
detailText: hasDetails ? detailText : '',
|
|
assignmentText,
|
|
}));
|
|
});
|
|
}
|