mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Refactor writeTemporaryDiagnosticFile out of add[NoLanguage]Diagnostic
This commit is contained in:
29
lib/entry-points.js
generated
29
lib/entry-points.js
generated
@@ -173023,12 +173023,10 @@ function addDiagnostic(config, language, diagnostic, logger2 = getActionsLogger(
|
||||
logger2.debug(
|
||||
`Writing a diagnostic for ${language}, but the database at ${databasePath} does not exist yet.`
|
||||
);
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(config.tempDir, language);
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
temporaryDiagnostics.push({ path: diagnosticPath, language });
|
||||
writeTemporaryDiagnosticFile(logger2, config.tempDir, language, diagnostic);
|
||||
}
|
||||
}
|
||||
function addNoLanguageDiagnostic(config, diagnostic) {
|
||||
function addNoLanguageDiagnostic(config, diagnostic, logger2 = getActionsLogger()) {
|
||||
if (config !== void 0) {
|
||||
addDiagnostic(
|
||||
config,
|
||||
@@ -173038,9 +173036,28 @@ function addNoLanguageDiagnostic(config, diagnostic) {
|
||||
diagnostic
|
||||
);
|
||||
} else {
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(getTemporaryDirectory());
|
||||
logger2.debug(
|
||||
`Writing a diagnostic not associated with any language, but we have no configuration to tell us where the database is yet.`
|
||||
);
|
||||
writeTemporaryDiagnosticFile(
|
||||
logger2,
|
||||
getTemporaryDirectory(),
|
||||
void 0,
|
||||
diagnostic
|
||||
);
|
||||
}
|
||||
}
|
||||
function writeTemporaryDiagnosticFile(logger2, tempDir, language, diagnostic) {
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(tempDir, language);
|
||||
try {
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
temporaryDiagnostics.push({ path: diagnosticPath });
|
||||
temporaryDiagnostics.push({ path: diagnosticPath, language });
|
||||
} catch (err) {
|
||||
logger2.warning(
|
||||
`Unable to write temporary diagnostic to '${tempDiagnosticsPath}': ${getErrorMessage(err)}
|
||||
|
||||
${JSON.stringify(diagnostic)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
function writeDiagnosticFile(diagnosticsPath, diagnostic) {
|
||||
|
||||
@@ -179,11 +179,7 @@ export function addDiagnostic(
|
||||
);
|
||||
|
||||
// Write the diagnostic to a temporary location.
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(config.tempDir, language);
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
|
||||
// Track the temporary file.
|
||||
temporaryDiagnostics.push({ path: diagnosticPath, language });
|
||||
writeTemporaryDiagnosticFile(logger, config.tempDir, language, diagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +187,7 @@ export function addDiagnostic(
|
||||
export function addNoLanguageDiagnostic(
|
||||
config: Config | undefined,
|
||||
diagnostic: DiagnosticMessage,
|
||||
logger: Logger = getActionsLogger(),
|
||||
) {
|
||||
if (config !== undefined) {
|
||||
addDiagnostic(
|
||||
@@ -201,11 +198,42 @@ export function addNoLanguageDiagnostic(
|
||||
diagnostic,
|
||||
);
|
||||
} else {
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(getTemporaryDirectory());
|
||||
logger.debug(
|
||||
`Writing a diagnostic not associated with any language, but we have no configuration to tell us where the database is yet.`,
|
||||
);
|
||||
|
||||
// Write the diagnostic to a temporary location.
|
||||
writeTemporaryDiagnosticFile(
|
||||
logger,
|
||||
getTemporaryDirectory(),
|
||||
undefined,
|
||||
diagnostic,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes {@link diagnostic} for an optional {@link language} to a subdirectory of {@link tempDir}
|
||||
* and tracks it as a diagnostic that was written to a temporary location.
|
||||
*/
|
||||
function writeTemporaryDiagnosticFile(
|
||||
logger: Logger,
|
||||
tempDir: string,
|
||||
language: Language | undefined,
|
||||
diagnostic: DiagnosticMessage,
|
||||
) {
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(tempDir, language);
|
||||
|
||||
try {
|
||||
// Write the diagnostic to a temporary location.
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
|
||||
// Track the temporary file.
|
||||
temporaryDiagnostics.push({ path: diagnosticPath });
|
||||
temporaryDiagnostics.push({ path: diagnosticPath, language });
|
||||
} catch (err) {
|
||||
logger.warning(
|
||||
`Unable to write temporary diagnostic to '${tempDiagnosticsPath}': ${getErrorMessage(err)}\n\n${JSON.stringify(diagnostic)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user