* Read the configured `target-repo` for a given safe-output tool from the * safe-outputs config file (GH_AW_SAFE_OUTPUTS_CONFIG_PATH). Returns an empty * string when no config is available or no target-repo is configured. * @param {string} tool * @returns {string}
(tool)
| 263 | * @returns {string} |
| 264 | */ |
| 265 | function readConfiguredTargetRepo(tool) { |
| 266 | const configPath = process.env.GH_AW_SAFE_OUTPUTS_CONFIG_PATH; |
| 267 | if (!configPath || !configPath.trim()) { |
| 268 | return ""; |
| 269 | } |
| 270 | |
| 271 | const toolKey = typeof tool === "string" ? tool.replace(/-/g, "_") : ""; |
| 272 | |
| 273 | try { |
| 274 | const raw = fs.readFileSync(configPath, "utf8"); |
| 275 | const parsed = JSON.parse(raw); |
| 276 | |
| 277 | // Mirror safe_outputs_config.cjs behavior: normalize top-level keys by replacing '-' with '_'. |
| 278 | const config = parsed && typeof parsed === "object" ? Object.fromEntries(Object.entries(parsed).map(([k, v]) => [String(k).replace(/-/g, "_"), v])) : {}; |
| 279 | |
| 280 | const toolConfig = toolKey && config && typeof config === "object" ? config[toolKey] : null; |
| 281 | const target = toolConfig && typeof toolConfig === "object" ? toolConfig["target-repo"] || toolConfig["target_repo"] : null; |
| 282 | if (typeof target === "string") { |
| 283 | return target.trim(); |
| 284 | } |
| 285 | } catch (err) { |
| 286 | core.debug(`apply_samples: could not read target-repo from ${configPath}: ${getErrorMessage(err)}`); |
| 287 | } |
| 288 | return ""; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Resolve the on-disk working directory in which a sample's patch should be |
no test coverage detected