diff --git a/src/debug.ts b/src/debug.ts index 960f472..eff73b6 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -3,6 +3,6 @@ import { Forge } from './forge.js'; config(); Forge.token(process.env.FORGE_TOKEN!); -Forge.debug(); +Forge.debug(1); // diff --git a/src/forge.ts b/src/forge.ts index 9c46243..667feee 100644 --- a/src/forge.ts +++ b/src/forge.ts @@ -57,7 +57,7 @@ export class ForgeError extends Error { export class Forge { static #token: string; - static #debug: boolean; + static #debug: number = 0; static #client?: AxiosInstance; static async listServers() { @@ -216,7 +216,7 @@ export class Forge { this.#token = token; } - static debug(debug: boolean = true) { + static debug(debug: number = 1) { this.#debug = debug; } @@ -230,9 +230,9 @@ export class Forge { }, }); this.#client.interceptors.request.use((config) => { - if (this.#debug) { + if (this.#debug > 0) { console.log(`> ${config.method?.toUpperCase()} /${config.url}`); - if (config.data) { + if (this.#debug > 1 && config.data) { console.log(JSON.stringify(config.data, null, 2)); } } @@ -240,13 +240,13 @@ export class Forge { }); this.#client.interceptors.response.use( (response) => { - if (this.#debug) { + if (this.#debug > 0) { console.log( `< ${response.config.method?.toUpperCase()} /${response.config.url} ${response.status} ${ response.statusText }`, ); - if (response.data) { + if (this.#debug > 1 && response.data) { console.log(JSON.stringify(response.data, null, 2)); } } @@ -254,7 +254,7 @@ export class Forge { }, async (error) => { if (error.response?.status === 429) { - if (this.#debug) { + if (this.#debug > 0) { console.warn('Rate-limited by Forge API, retrying in one second...'); } await sleep(1); diff --git a/src/main.ts b/src/main.ts index b904f63..d9bcf2f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,7 +89,7 @@ export async function run() { const pr = github.context.payload as PullRequestEvent; Forge.token(forgeToken); - Forge.debug(core.isDebug()); + Forge.debug(core.isDebug() ? 2 : 0); if (pr.action === 'opened' || pr.action === 'reopened') { const preview = await createPreview({ diff --git a/tests/integration/forge.test.ts b/tests/integration/forge.test.ts index 9be156e..33dbdb2 100644 --- a/tests/integration/forge.test.ts +++ b/tests/integration/forge.test.ts @@ -6,7 +6,7 @@ import { normalizeDatabaseName, until, updateDotEnvString } from '../../src/lib' // @ts-expect-error import.meta not set up Forge.token(import.meta.env.VITE_FORGE_TOKEN); // @ts-expect-error import.meta not set up -Forge.debug(!!import.meta.env.VITE_FORGE_DEBUG); +Forge.debug(import.meta.env.VITE_FORGE_DEBUG); // @ts-expect-error import.meta not set up const server = Number(import.meta.env.VITE_FORGE_SERVER); @@ -17,7 +17,7 @@ function id() { describe('sites', () => { afterAll(async () => { - Forge.debug(false); + Forge.debug(0); const sites = await Forge.listSites(server); const databases = await Forge.listDatabases(server); await Promise.all([