mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Revert "Allow logging functions to accept string[] directly"
This reverts commit 909fda1468.
This commit is contained in:
20
lib/entry-points.js
generated
20
lib/entry-points.js
generated
@@ -170475,24 +170475,12 @@ function fixCodeQualityCategory(logger2, category, env = getEnv()) {
|
||||
|
||||
// src/logging.ts
|
||||
var core5 = __toESM(require_core());
|
||||
var joinMessageStrings = (message) => {
|
||||
if (Array.isArray(message)) {
|
||||
return message.join(" ");
|
||||
} else {
|
||||
return message;
|
||||
}
|
||||
};
|
||||
var autoJoinMessageStrings = (fn) => {
|
||||
return (message) => {
|
||||
return fn(joinMessageStrings(message));
|
||||
};
|
||||
};
|
||||
function getActionsLogger() {
|
||||
return {
|
||||
debug: autoJoinMessageStrings(core5.debug),
|
||||
info: autoJoinMessageStrings(core5.info),
|
||||
warning: autoJoinMessageStrings(core5.warning),
|
||||
error: autoJoinMessageStrings(core5.error),
|
||||
debug: core5.debug,
|
||||
info: core5.info,
|
||||
warning: core5.warning,
|
||||
error: core5.error,
|
||||
isDebug: core5.isDebug,
|
||||
startGroup: core5.startGroup,
|
||||
endGroup: core5.endGroup
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import test from "ava";
|
||||
|
||||
import { joinMessageStrings } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
test("joinMessageStrings", async (t) => {
|
||||
// For strings and errors, it is the identity function.
|
||||
t.deepEqual(joinMessageStrings("Hello"), "Hello");
|
||||
|
||||
const error = new Error("Some error");
|
||||
t.deepEqual(joinMessageStrings(error), error);
|
||||
|
||||
// For arrays of strings, we get a join-ed string.
|
||||
t.deepEqual(joinMessageStrings(["foo", "bar"]), "foo bar");
|
||||
});
|
||||
@@ -1,16 +1,10 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
/** Types that all of our logging functions accept. */
|
||||
export type Loggable = string | string[];
|
||||
|
||||
/** Some logging functions also accept errors directly. */
|
||||
export type LoggableError = Loggable | Error;
|
||||
|
||||
export interface Logger {
|
||||
debug: (message: Loggable) => void;
|
||||
info: (message: Loggable) => void;
|
||||
warning: (message: LoggableError) => void;
|
||||
error: (message: LoggableError) => void;
|
||||
debug: (message: string) => void;
|
||||
info: (message: string) => void;
|
||||
warning: (message: string | Error) => void;
|
||||
error: (message: string | Error) => void;
|
||||
|
||||
isDebug: () => boolean;
|
||||
|
||||
@@ -18,33 +12,12 @@ export interface Logger {
|
||||
endGroup: () => void;
|
||||
}
|
||||
|
||||
/** If `message` is an array of strings, the array is `join`-ed into one string separated by spaces. */
|
||||
export const joinMessageStrings = <T>(
|
||||
message: string[] | string | T,
|
||||
): string | T => {
|
||||
if (Array.isArray(message)) {
|
||||
return message.join(" ");
|
||||
} else {
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Wraps a logging function so that `joinMessageStrings` is applied to the input before
|
||||
* calling the wrapped logging function.
|
||||
*/
|
||||
const autoJoinMessageStrings = <T>(fn: (msg: string | T) => void) => {
|
||||
return (message: string[] | string | T) => {
|
||||
return fn(joinMessageStrings(message));
|
||||
};
|
||||
};
|
||||
|
||||
export function getActionsLogger(): Logger {
|
||||
return {
|
||||
debug: autoJoinMessageStrings(core.debug),
|
||||
info: autoJoinMessageStrings(core.info),
|
||||
warning: autoJoinMessageStrings(core.warning),
|
||||
error: autoJoinMessageStrings(core.error),
|
||||
debug: core.debug,
|
||||
info: core.info,
|
||||
warning: core.warning,
|
||||
error: core.error,
|
||||
isDebug: core.isDebug,
|
||||
startGroup: core.startGroup,
|
||||
endGroup: core.endGroup,
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
featureConfig,
|
||||
FeatureEnablement,
|
||||
} from "./feature-flags";
|
||||
import { joinMessageStrings, Loggable, LoggableError, Logger } from "./logging";
|
||||
import { Logger } from "./logging";
|
||||
import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
|
||||
import { getBundlePlatform } from "./platform";
|
||||
import { ActionName } from "./status-report";
|
||||
@@ -658,8 +658,8 @@ export class RecordingLogger implements Logger {
|
||||
|
||||
constructor(private readonly logToConsole: boolean = true) {}
|
||||
|
||||
private addMessage(level: LogLevel, message: LoggableError): void {
|
||||
this.messages.push({ type: level, message: joinMessageStrings(message) });
|
||||
private addMessage(level: LogLevel, message: string | Error): void {
|
||||
this.messages.push({ type: level, message });
|
||||
|
||||
if (this.logToConsole) {
|
||||
// eslint-disable-next-line no-console
|
||||
@@ -684,19 +684,19 @@ export class RecordingLogger implements Logger {
|
||||
return true;
|
||||
}
|
||||
|
||||
debug(message: Loggable) {
|
||||
debug(message: string) {
|
||||
this.addMessage("debug", message);
|
||||
}
|
||||
|
||||
info(message: Loggable) {
|
||||
info(message: string) {
|
||||
this.addMessage("info", message);
|
||||
}
|
||||
|
||||
warning(message: LoggableError) {
|
||||
warning(message: string | Error) {
|
||||
this.addMessage("warning", message);
|
||||
}
|
||||
|
||||
error(message: LoggableError) {
|
||||
error(message: string | Error) {
|
||||
this.addMessage("error", message);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user