11import { CheckRepoActions , GitConfigScope , simpleGit , SimpleGitProgressEvent } from 'simple-git' ;
22import { mkdir } from 'node:fs/promises' ;
3+ import { env } from './env.js' ;
34
45type onProgressFn = ( event : SimpleGitProgressEvent ) => void ;
56
@@ -26,10 +27,15 @@ export const cloneRepository = async (
2627 "--progress" ,
2728 ] ) ;
2829 } catch ( error : unknown ) {
29- if ( error instanceof Error ) {
30- throw new Error ( `Failed to clone repository: ${ error . message } ` ) ;
30+ const baseLog = `Failed to clone repository: ${ path } ` ;
31+
32+ if ( env . SOURCEBOT_LOG_LEVEL !== "debug" ) {
33+ // Avoid printing the remote URL (that may contain credentials) to logs by default.
34+ throw new Error ( `${ baseLog } . Set environment variable SOURCEBOT_LOG_LEVEL=debug to see the full error message.` ) ;
35+ } else if ( error instanceof Error ) {
36+ throw new Error ( `${ baseLog } . Reason: ${ error . message } ` ) ;
3137 } else {
32- throw new Error ( `Failed to clone repository : ${ error } ` ) ;
38+ throw new Error ( `${ baseLog } . Error : ${ error } ` ) ;
3339 }
3440 }
3541} ;
@@ -53,10 +59,14 @@ export const fetchRepository = async (
5359 "--progress"
5460 ] ) ;
5561 } catch ( error : unknown ) {
56- if ( error instanceof Error ) {
57- throw new Error ( `Failed to fetch repository ${ path } : ${ error . message } ` ) ;
62+ const baseLog = `Failed to fetch repository: ${ path } ` ;
63+ if ( env . SOURCEBOT_LOG_LEVEL !== "debug" ) {
64+ // Avoid printing the remote URL (that may contain credentials) to logs by default.
65+ throw new Error ( `${ baseLog } . Set environment variable SOURCEBOT_LOG_LEVEL=debug to see the full error message.` ) ;
66+ } else if ( error instanceof Error ) {
67+ throw new Error ( `${ baseLog } . Reason: ${ error . message } ` ) ;
5868 } else {
59- throw new Error ( `Failed to fetch repository ${ path } : ${ error } ` ) ;
69+ throw new Error ( `${ baseLog } . Error : ${ error } ` ) ;
6070 }
6171 }
6272}
0 commit comments