Skip to content
Snippets Groups Projects
Unverified Commit 66f35c95 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix(git): log gitPrivateKey events (#18335)

parent 6fef1d16
No related branches found
No related tags found
No related merge requests found
import os from 'os'; import os from 'os';
import is from '@sindresorhus/is';
import fs from 'fs-extra'; import fs from 'fs-extra';
import upath from 'upath'; import upath from 'upath';
import { PLATFORM_GPG_FAILED } from '../../constants/error-messages'; import { PLATFORM_GPG_FAILED } from '../../constants/error-messages';
...@@ -10,7 +11,13 @@ let gitPrivateKey: string | undefined; ...@@ -10,7 +11,13 @@ let gitPrivateKey: string | undefined;
let keyId: string | undefined; let keyId: string | undefined;
export function setPrivateKey(key: string | undefined): void { 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> { async function importKey(): Promise<void> {
...@@ -34,11 +41,11 @@ export async function writePrivateKey(): Promise<void> { ...@@ -34,11 +41,11 @@ export async function writePrivateKey(): Promise<void> {
if (!gitPrivateKey) { if (!gitPrivateKey) {
return; return;
} }
logger.debug('Setting git private key');
try { try {
await importKey(); await importKey();
logger.debug('gitPrivateKey: imported');
} catch (err) { } catch (err) {
logger.warn({ err }, 'Error writing git private key'); logger.warn({ err }, 'gitPrivateKey: error importing');
throw new Error(PLATFORM_GPG_FAILED); throw new Error(PLATFORM_GPG_FAILED);
} }
} }
...@@ -47,7 +54,7 @@ export async function configSigningKey(cwd: string): Promise<void> { ...@@ -47,7 +54,7 @@ export async function configSigningKey(cwd: string): Promise<void> {
if (!gitPrivateKey) { if (!gitPrivateKey) {
return; return;
} }
logger.debug('Configuring commits signing'); logger.debug('gitPrivateKey: configuring commit signing');
// TODO: types (#7154) // TODO: types (#7154)
await exec(`git config user.signingkey ${keyId!}`, { cwd }); await exec(`git config user.signingkey ${keyId!}`, { cwd });
await exec(`git config commit.gpgsign true`, { cwd }); await exec(`git config commit.gpgsign true`, { cwd });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment