All files / src/views sidebarDocumentGenerationHelpers.js

100% Statements 96/96
100% Branches 27/27
100% Functions 4/4
100% Lines 96/96

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 978x 8x 8x 8x 9x 9x 9x 9x 9x 8x 8x 8x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 10x 11x 1x 1x 9x 9x 9x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 2x 2x 2x 2x 2x 2x 2x  
function buildCommitsByTicket(commitsByPR = {}) {
  const commitsByTicket = {};
 
  for (const [prId, commits] of Object.entries(commitsByPR)) {
    const ticketKey = `PR-${prId}`;
    commitsByTicket[ticketKey] = Array.isArray(commits)
      ? commits.map((c) => c.message)
      : [];
  }
 
  return commitsByTicket;
}
 
function mapSharePointDocuments(spDocuments = {}) {
  return {
    PLAN_MONTAJE: spDocuments.PLANIFICACION || spDocuments.PLAN_MONTAJE || [],
    PPT_CRT: spDocuments.PRESENTACIONES || spDocuments.PPT_CRT || [],
    VB_DB: spDocuments.VISTOS_BUENOS_DB || spDocuments.VB_DB || [],
    VB_CRT: spDocuments.VISTOS_BUENOS_CRT || spDocuments.VB_CRT || [],
    CICLOS_PRUEBA:
      spDocuments.PRUEBAS_USUARIO || spDocuments.CICLOS_PRUEBA || [],
    PRUEBAS_PREPROD: spDocuments.PRUEBAS_PREPROD || [],
  };
}
 
function buildDocumentGenerationPayload({
  paseNumber,
  title,
  objective,
  areaAfectada,
  summary,
  workItems,
  pullRequests,
  azureOrg,
  spDocuments,
  solicitante,
} = {}) {
  const mappedSharePointDocs = mapSharePointDocuments(spDocuments);
 
  return {
    NUMERO_PASE: paseNumber,
    FECHA: new Date().toLocaleDateString("es-ES"),
    PROYECTO: title,
    SOLICITANTE: solicitante || "Equipo de Desarrollo",
    TITULO_PASE: title,
    OBJETIVO_PASE: objective,
    OBJETIVO: objective,
    AREA_AFECTADA: areaAfectada,
    ASPECTOS_IMPORTANTES: summary,
    workItems: workItems,
    pullRequests: pullRequests,
    PR_AZURE: pullRequests,
    azureOrganization: azureOrg,
    ...mappedSharePointDocs,
  };
}
 
function resolveDocumentOutputTarget({
  outputDir,
  requestedFileName,
  paseNumber,
  fileExists,
  joinPath,
} = {}) {
  if (!outputDir) {
    throw new Error(
      "❌ Directorio de salida no configurado. Verifica 'template.outputDir' en settings.",
    );
  }
 
  if (!fileExists(outputDir)) {
    throw new Error(`❌ El directorio de salida no existe: ${outputDir}`);
  }
 
  const filename =
    requestedFileName && requestedFileName.trim()
      ? requestedFileName.trim()
      : `Pase-${paseNumber}.docx`;
 
  const finalFilename = filename.endsWith(".docx")
    ? filename
    : `${filename}.docx`;
  const outputPath = joinPath(outputDir, finalFilename);
 
  return {
    finalFilename,
    outputPath,
  };
}
 
module.exports = {
  buildCommitsByTicket,
  mapSharePointDocuments,
  buildDocumentGenerationPayload,
  resolveDocumentOutputTarget,
};