All files / src/views sidebarConfigPersistence.js

100% Statements 135/135
100% Branches 61/61
100% Functions 3/3
100% Lines 135/135

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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 13611x 11x 11x 11x 11x 11x 20x 11x 11x 9x 20x 7x 7x 2x 2x 5x 5x 2x 2x 11x 11x 11x 11x 11x 10x 11x 10x 11x 10x 11x 10x 11x 1x 1x 1x 1x 10x 11x 10x 11x 1x 1x 1x 1x 10x 11x 10x 11x 10x 11x 1x 1x 1x 1x 10x 10x 11x 10x 10x 11x 1x 1x 1x 1x 10x 11x 1x 1x 1x 1x 10x 11x 1x 1x 1x 1x 10x 11x 1x 1x 1x 1x 10x 10x 11x 1x 1x 1x 1x 10x 10x 11x 3x 3x 3x 3x 10x 11x 4x 4x 2x 2x 2x 2x 2x 2x 4x 10x 11x 4x 4x 2x 2x 2x 2x 2x 2x 4x 10x 10x 11x 10x 11x 10x 11x 10x 11x 11x 1x 1x 11x 2x 2x 2x 2x  
async function persistSidebarConfig(
  config,
  configData = {},
  isMaskedValue = () => false,
) {
  const shouldPersistSecret = (value) => {
    if (value === undefined || value === null) {
      return false;
    }
 
    if (typeof value === "string") {
      const trimmed = value.trim();
      if (trimmed.length === 0) {
        return false;
      }
      return !isMaskedValue(trimmed);
    }
 
    return !isMaskedValue(value);
  };
 
  try {
    if (configData.azureOrg)
      await config.update("azure.organization", configData.azureOrg, true);
    if (shouldPersistSecret(configData.azurePat))
      await config.update("azure.pat", configData.azurePat, true);
    if (configData.devopsOrg)
      await config.update("devops.organization", configData.devopsOrg, true);
    if (shouldPersistSecret(configData.devopsPat))
      await config.update("devops.pat", configData.devopsPat, true);
    if (configData.sharePointPath)
      await config.update(
        "sharepoint.localPath",
        configData.sharePointPath,
        true,
      );
    if (configData.sharePointUrl)
      await config.update("sharepoint.baseUrl", configData.sharePointUrl, true);
    if (configData.subdirectories !== undefined)
      await config.update(
        "sharepoint.subdirectories",
        configData.subdirectories,
        true,
      );
    if (configData.outputDir)
      await config.update("template.outputDir", configData.outputDir, true);
    if (configData.summaryMethod)
      await config.update("summary.method", configData.summaryMethod, true);
    if (configData.docxConversionMode !== undefined)
      await config.update(
        "docxConversionMode",
        configData.docxConversionMode,
        true,
      );
 
    if (configData.aiModel !== undefined)
      await config.update("prReview.aiModel", configData.aiModel, true);
 
    if (configData.standardsSqlPath !== undefined)
      await config.update(
        "standards.sqlPath",
        configData.standardsSqlPath,
        true,
      );
    if (configData.standardsAngularPath !== undefined)
      await config.update(
        "standards.angularPath",
        configData.standardsAngularPath,
        true,
      );
    if (configData.standardsDotnetPath !== undefined)
      await config.update(
        "standards.dotnetPath",
        configData.standardsDotnetPath,
        true,
      );
    if (configData.standardsSsisPath !== undefined)
      await config.update(
        "standards.ssisPath",
        configData.standardsSsisPath,
        true,
      );
 
    if (configData.ignoredFilePatterns !== undefined)
      await config.update(
        "prReview.ignoredFilePatterns",
        configData.ignoredFilePatterns,
        true,
      );
 
    if (configData.autoLiteModeEnabled !== undefined)
      await config.update(
        "prReview.autoLiteMode.enabled",
        configData.autoLiteModeEnabled !== false,
        true,
      );
 
    if (configData.autoLiteModeFilesThreshold !== undefined) {
      const filesThreshold = Number(configData.autoLiteModeFilesThreshold);
      if (Number.isFinite(filesThreshold) && filesThreshold > 0) {
        await config.update(
          "prReview.autoLiteMode.filesThreshold",
          Math.floor(filesThreshold),
          true,
        );
      }
    }
 
    if (configData.autoLiteModeBlocksThreshold !== undefined) {
      const blocksThreshold = Number(configData.autoLiteModeBlocksThreshold);
      if (Number.isFinite(blocksThreshold) && blocksThreshold > 0) {
        await config.update(
          "prReview.autoLiteMode.blocksThreshold",
          Math.floor(blocksThreshold),
          true,
        );
      }
    }
 
    if (configData.paseNumber !== undefined)
      await config.update("lastPaseNumber", configData.paseNumber, true);
    if (configData.paseTitle !== undefined)
      await config.update("lastTitle", configData.paseTitle, true);
    if (configData.paseObjective !== undefined)
      await config.update("lastObjective", configData.paseObjective, true);
    if (configData.areaAfectada !== undefined)
      await config.update("lastAreaAfectada", configData.areaAfectada, true);
  } catch (error) {
    throw new Error(`No se pudo persistir la configuración: ${error.message}`);
  }
}
 
module.exports = {
  persistSidebarConfig,
};