refactor: move logger into separate module (#4581)

* refactor: move logger into separate module

* Update api/status/pat-info.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Alexandr Garbuzov
2025-10-25 19:28:11 +02:00
committed by martin-mfg
co-authored by Copilot Alexandr
parent 81046114ff
commit c6c26c533f
9 changed files with 27 additions and 16 deletions
+2 -1
View File
@@ -8,7 +8,8 @@
*/
import { request } from "../../src/common/http.js";
import { logger, dateDiff } from "../../src/common/utils.js";
import { logger } from "../../src/common/log.js";
import { dateDiff } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 3; // 1 request per 3 minutes
+1 -1
View File
@@ -9,7 +9,7 @@
import { request } from "../../src/common/http.js";
import retryer from "../../src/common/retryer.js";
import { logger } from "../../src/common/utils.js";
import { logger } from "../../src/common/log.js";
export const RATE_LIMIT_SECONDS = 60 * 3; // 1 request per 3 minutes
-1
View File
@@ -14,7 +14,6 @@ export {
parseArray,
clampValue,
flexLayout,
logger,
measureText,
lowercaseTrim,
chunkArray,
+14
View File
@@ -0,0 +1,14 @@
// @ts-check
const noop = () => {};
/**
* Return console instance based on the environment.
*
* @type {Console | {log: () => void, error: () => void}}
*/
const logger =
process.env.NODE_ENV === "test" ? { log: noop, error: noop } : console;
export { logger };
export default logger;
+1 -1
View File
@@ -1,7 +1,7 @@
// @ts-check
import { CustomError } from "./error.js";
import { logger } from "./utils.js";
import { logger } from "./log.js";
// Script variables.
-6
View File
@@ -225,11 +225,6 @@ const renderError = ({
`;
};
const noop = () => {};
// return console instance based on the environment
const logger =
process.env.NODE_ENV === "test" ? { log: noop, error: noop } : console;
/**
* Retrieve text length.
*
@@ -374,7 +369,6 @@ export {
clampValue,
buildSearchFilter,
flexLayout,
logger,
OWNER_AFFILIATIONS,
measureText,
lowercaseTrim,
+1 -1
View File
@@ -7,9 +7,9 @@ import { calculateRank } from "../calculateRank.js";
import { retryer } from "../common/retryer.js";
import {
buildSearchFilter,
logger,
parseOwnerAffiliations,
} from "../common/utils.js";
import { logger } from "../common/log.js";
import { excludeRepositories } from "../common/envs.js";
import { CustomError, MissingParamError } from "../common/error.js";
import { wrapTextMultiline } from "../common/fmt.js";
+2 -4
View File
@@ -1,10 +1,8 @@
// @ts-check
import { retryer } from "../common/retryer.js";
import {
logger,
parseOwnerAffiliations,
} from "../common/utils.js";
import { parseOwnerAffiliations } from "../common/utils.js";
import { logger } from "../common/log.js";
import { excludeRepositories } from "../common/envs.js";
import { CustomError, MissingParamError } from "../common/error.js";
import { wrapTextMultiline } from "../common/fmt.js";
+6 -1
View File
@@ -1,7 +1,9 @@
// @ts-check
import { describe, expect, it, jest } from "@jest/globals";
import "@testing-library/jest-dom";
import { RETRIES, retryer } from "../src/common/retryer.js";
import { logger } from "../src/common/utils.js";
import { logger } from "../src/common/log.js";
const fetcher = jest.fn((variables, token) => {
logger.log(variables, token);
@@ -17,6 +19,7 @@ const fetcherFail = jest.fn(() => {
const fetcherFailOnSecondTry = jest.fn((_vars, _token, retries) => {
return new Promise((res) => {
// faking rate limit
// @ts-ignore
if (retries < 1) {
return res({ data: { errors: [{ type: "RATE_LIMITED" }] } });
}
@@ -28,6 +31,7 @@ const fetcherFailWithMessageBasedRateLimitErr = jest.fn(
(_vars, _token, retries) => {
return new Promise((res) => {
// faking rate limit
// @ts-ignore
if (retries < 1) {
return res({
data: {
@@ -72,6 +76,7 @@ describe("Test Retryer", () => {
await retryer(fetcherFail, {});
} catch (err) {
expect(fetcherFail).toHaveBeenCalledTimes(RETRIES + 1);
// @ts-ignore
expect(err.message).toBe("Downtime due to GitHub API rate limiting");
}
});