From 8c52147a531e0c0a53e79f33d90395bc915da538 Mon Sep 17 00:00:00 2001 From: Mike Urbanski Date: Wed, 17 May 2023 09:54:25 -0500 Subject: [PATCH] fix: add additional environment detail to debug logs (#75) --- src/commands/azuredevops.ts | 2 +- src/commands/bitbucket-server.ts | 2 +- src/commands/bitbucket.ts | 2 +- src/commands/github-server.ts | 2 +- src/commands/github.ts | 3 +-- src/commands/gitlab-server.ts | 2 +- src/commands/gitlab.ts | 2 +- src/commands/local.ts | 2 +- src/common/utils.ts | 14 +++++++++++--- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/commands/azuredevops.ts b/src/commands/azuredevops.ts index 32477e7..ff6fd92 100644 --- a/src/commands/azuredevops.ts +++ b/src/commands/azuredevops.ts @@ -53,7 +53,7 @@ export default class AzureDevOps extends Command { async run(): Promise { const { flags } = await this.parse(AzureDevOps); - init(flags); + init(flags, this.config); const sourceInfo = AzureDevOps.getSourceInfo(':' + flags.token, flags['include-public']); diff --git a/src/commands/bitbucket-server.ts b/src/commands/bitbucket-server.ts index 4a4deb2..d25f26c 100644 --- a/src/commands/bitbucket-server.ts +++ b/src/commands/bitbucket-server.ts @@ -38,7 +38,7 @@ export default class BitbucketServer extends Bitbucket { async run(): Promise { const { flags } = await this.parse(BitbucketServer); - init(flags); + init(flags, this.config); const serverUrl = getServerUrl(flags.hostname, flags.port, flags.protocol); const baseUrl = `${serverUrl}/rest/api/1.0`; diff --git a/src/commands/bitbucket.ts b/src/commands/bitbucket.ts index 219e520..9750cfc 100644 --- a/src/commands/bitbucket.ts +++ b/src/commands/bitbucket.ts @@ -49,7 +49,7 @@ export default class Bitbucket extends Command { async run(): Promise { const { flags } = await this.parse(Bitbucket); - init(flags); + init(flags, this.config); const sourceInfo = Bitbucket.getSourceInfo(`${flags.username}:${flags.token}`, flags['include-public']); diff --git a/src/commands/github-server.ts b/src/commands/github-server.ts index 70badbc..1e9ec91 100644 --- a/src/commands/github-server.ts +++ b/src/commands/github-server.ts @@ -26,7 +26,7 @@ export default class GithubServer extends Github { async run(): Promise { const { flags } = await this.parse(GithubServer); - init(flags); + init(flags, this.config); const serverUrl = getServerUrl(flags.hostname, flags.port, flags.protocol); const baseUrl = `${serverUrl}/api/v3`; diff --git a/src/commands/github.ts b/src/commands/github.ts index 16f2747..0028f4b 100644 --- a/src/commands/github.ts +++ b/src/commands/github.ts @@ -42,8 +42,7 @@ export default class Github extends Command { async run(): Promise { const { flags } = await this.parse(Github); - init(flags); - + init(flags, this.config); const sourceInfo = Github.getSourceInfo(flags.token, flags['include-public']); const apiManager = new GithubApiManager(sourceInfo, flags['ca-cert']); diff --git a/src/commands/gitlab-server.ts b/src/commands/gitlab-server.ts index a847c73..16a29a3 100644 --- a/src/commands/gitlab-server.ts +++ b/src/commands/gitlab-server.ts @@ -26,7 +26,7 @@ export default class GitlabServer extends Gitlab { async run(): Promise { const { flags } = await this.parse(GitlabServer); - init(flags); + init(flags, this.config); const serverUrl = getServerUrl(flags.hostname, flags.port, flags.protocol); const baseUrl = `${serverUrl}/api/v4`; diff --git a/src/commands/gitlab.ts b/src/commands/gitlab.ts index 81558e7..c0f70c5 100644 --- a/src/commands/gitlab.ts +++ b/src/commands/gitlab.ts @@ -37,7 +37,7 @@ export default class Gitlab extends Command { async run(): Promise { const { flags } = await this.parse(Gitlab); - init(flags); + init(flags, this.config); const sourceInfo = Gitlab.getSourceInfo(flags.token, flags['include-public']); diff --git a/src/commands/local.ts b/src/commands/local.ts index 73cc7f6..faf91d0 100644 --- a/src/commands/local.ts +++ b/src/commands/local.ts @@ -52,7 +52,7 @@ export default class Local extends Command { async run(): Promise { const { flags } = await this.parse(Local); - init(flags); + init(flags, this.config); if (!(flags.directories || flags['directory-file'])) { throw new CLIError('At least one of --directories or --directory-file is required for running locally.'); diff --git a/src/common/utils.ts b/src/common/utils.ts index bc1a2bc..4b9b20d 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -2,11 +2,13 @@ import { AxiosError, AxiosResponse } from 'axios'; import { readFileSync } from 'node:fs'; import { Protocol, Repo, VcsSourceInfo } from './types'; import * as winston from 'winston'; +import * as os from 'node:os'; import { FlagBase } from '@oclif/core/lib/interfaces'; import { spawn, SpawnOptionsWithoutStdio } from 'node:child_process'; import { EOL } from 'node:os'; import { MAX_REQUESTS_PER_SECOND_VAR } from './throttled-vcs-api-manager'; import { LOG_API_RESPONSES_ENV } from './api-manager'; +import { Config } from '@oclif/core'; export const DEFAULT_DAYS = 90; export const DEFAULT_LOG_LEVEL = 'warn'; @@ -356,14 +358,20 @@ export const exec = (command: string, args: string[], options: SpawnOptionsWitho }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const init = (flags: any): void => { +export const init = (flags: any, config: Config): void => { // performs common, command-independent initialization setLogLevel(flags['log-level'].toLowerCase()); - logParams(flags); + logParams(flags, config); }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const logParams = (flags: any): void => { +export const logParams = (flags: any, config: Config): void => { + LOGGER.debug('Environment details:'); + LOGGER.debug(`Redshirts version: ${config.version}`); + LOGGER.debug(`Node version: ${process.version}`); + LOGGER.debug(`OS: ${os.type} - ${process.platform} - ${os.release}`); + LOGGER.debug(`CPU arch: ${process.arch}`); + const tokenParams = new Set(['-t', '--token']); const tokenFlags = new Set(['token']);