Skip to content

Commit

Permalink
fix: add additional environment detail to debug logs (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeurbanski1 authored May 17, 2023
1 parent cd6fb63 commit 8c52147
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/commands/azuredevops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class AzureDevOps extends Command {

async run(): Promise<void> {
const { flags } = await this.parse(AzureDevOps);
init(flags);
init(flags, this.config);

const sourceInfo = AzureDevOps.getSourceInfo(':' + flags.token, flags['include-public']);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/bitbucket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class BitbucketServer extends Bitbucket {

async run(): Promise<void> {
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`;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Bitbucket extends Command {

async run(): Promise<void> {
const { flags } = await this.parse(Bitbucket);
init(flags);
init(flags, this.config);

const sourceInfo = Bitbucket.getSourceInfo(`${flags.username}:${flags.token}`, flags['include-public']);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/github-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class GithubServer extends Github {

async run(): Promise<void> {
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`;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export default class Github extends Command {

async run(): Promise<void> {
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']);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gitlab-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class GitlabServer extends Gitlab {

async run(): Promise<void> {
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`;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Gitlab extends Command {

async run(): Promise<void> {
const { flags } = await this.parse(Gitlab);
init(flags);
init(flags, this.config);

const sourceInfo = Gitlab.getSourceInfo(flags.token, flags['include-public']);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Local extends Command {

async run(): Promise<void> {
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.');
Expand Down
14 changes: 11 additions & 3 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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']);

Expand Down

0 comments on commit 8c52147

Please sign in to comment.