From 66f35c954bc7ca70bfcdd0ced9ac30e11b8a56d0 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Fri, 14 Oct 2022 12:19:37 +0200 Subject: [PATCH] fix(git): log gitPrivateKey events (#18335) --- lib/util/git/private-key.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/util/git/private-key.ts b/lib/util/git/private-key.ts index 3c2b9a5a46..06a15b407c 100644 --- a/lib/util/git/private-key.ts +++ b/lib/util/git/private-key.ts @@ -1,4 +1,5 @@ import os from 'os'; +import is from '@sindresorhus/is'; import fs from 'fs-extra'; import upath from 'upath'; import { PLATFORM_GPG_FAILED } from '../../constants/error-messages'; @@ -10,7 +11,13 @@ let gitPrivateKey: string | undefined; let keyId: string | undefined; export function setPrivateKey(key: string | undefined): void { - gitPrivateKey = key?.trim(); + if (!is.nonEmptyStringAndNotWhitespace(key)) { + return; + } + logger.debug( + 'gitPrivateKey: successfully set (but not yet written/configured)' + ); + gitPrivateKey = key.trim(); } async function importKey(): Promise<void> { @@ -34,11 +41,11 @@ export async function writePrivateKey(): Promise<void> { if (!gitPrivateKey) { return; } - logger.debug('Setting git private key'); try { await importKey(); + logger.debug('gitPrivateKey: imported'); } catch (err) { - logger.warn({ err }, 'Error writing git private key'); + logger.warn({ err }, 'gitPrivateKey: error importing'); throw new Error(PLATFORM_GPG_FAILED); } } @@ -47,7 +54,7 @@ export async function configSigningKey(cwd: string): Promise<void> { if (!gitPrivateKey) { return; } - logger.debug('Configuring commits signing'); + logger.debug('gitPrivateKey: configuring commit signing'); // TODO: types (#7154) await exec(`git config user.signingkey ${keyId!}`, { cwd }); await exec(`git config commit.gpgsign true`, { cwd }); -- GitLab