@@ -6,6 +6,8 @@ import chalk from "chalk";
66import tempy from "tempy" ;
77
88import { cache as octokitCachePlugin } from "./lib/octokit-plugin-cache.js" ;
9+ import { requestLog } from "./lib/octokit-plugin-request-log.js" ;
10+ import { requestConfirm } from "./lib/octokit-plugin-request-confirm.js" ;
911import { resolveRepositories } from "./lib/resolve-repositories.js" ;
1012import { VERSION } from "./version.js" ;
1113
@@ -37,23 +39,36 @@ export async function octoherd(
3739 octoherdDebug,
3840 octoherdScript,
3941 octoherdRepos,
42+ octoherdBypassConfirms,
4043 ...userOptions
4144 } = options ;
45+
4246 const tmpLogFile = tempy . file ( { extension : "ndjson.log" } ) ;
4347
44- const CliOctokit = octoherdCache
45- ? Octokit . plugin ( octokitCachePlugin )
46- : Octokit ;
48+ const plugins = [ requestLog , requestConfirm ] ;
49+ if ( typeof octoherdCache === "string" ) plugins . push ( octokitCachePlugin ) ;
50+ const CliOctokit = Octokit . plugin ( ...plugins ) ;
51+
4752 const octokit = new CliOctokit ( {
4853 auth : octoherdToken ,
4954 userAgent : [ "octoherd-cli" , VERSION ] . join ( "/" ) ,
5055 octoherd : {
5156 debug : octoherdDebug ,
57+ cache : octoherdCache ,
58+ bypassConfirms : octoherdBypassConfirms ,
5259 onLogMessage ( level , message , additionalData ) {
60+ // ignore the `octoherd` property in meta data
61+ const { octoherd, ...meta } = additionalData ;
62+ let additionalDataString = JSON . stringify ( meta ) ;
63+
64+ if ( additionalDataString . length > 300 ) {
65+ additionalDataString = additionalDataString . slice ( 0 , 295 ) + " … }" ;
66+ }
67+
5368 console . log (
5469 levelColor [ level ] ( " " + level . toUpperCase ( ) + " " ) ,
55- Object . keys ( additionalData ) . length
56- ? `${ message } ${ chalk . gray ( JSON . stringify ( additionalData ) ) } `
70+ Object . keys ( meta ) . length
71+ ? `${ message } ${ chalk . gray ( additionalDataString ) } `
5772 : message
5873 ) ;
5974 } ,
@@ -78,7 +93,7 @@ export async function octoherd(
7893 throw new Error ( `[octoherd] no "script" exported at ${ path } ` ) ;
7994 }
8095
81- if ( octoherdCache . length === 0 ) {
96+ if ( octoherdRepos . length === 0 ) {
8297 throw new Error ( "[octoherd] No repositories provided" ) ;
8398 }
8499
@@ -93,22 +108,33 @@ export async function octoherd(
93108
94109 for ( const repository of repositories ) {
95110 octokit . log . info (
111+ { octoherd : true } ,
96112 "Running %s on %s..." ,
97113 octoherdScript ,
98114 repository . full_name
99115 ) ;
100- await userScript ( octokit , repository , userOptions ) ;
101- }
102116
103- console . log ( "" ) ;
104- console . log ( levelColor . info ( " DONE " ) , `Log file written to ${ tmpLogFile } ` ) ;
117+ try {
118+ await userScript ( octokit , repository , userOptions ) ;
119+ } catch ( error ) {
120+ if ( ! error . cancel ) throw error ;
121+ octokit . log . debug ( error . message ) ;
122+ }
123+ }
105124 } catch ( error ) {
106125 octokit . log . error ( error ) ;
107- console . log ( "" ) ;
126+ process . exitCode = 1 ;
127+ }
128+
129+ console . log ( "" ) ;
130+ console . log ( chalk . gray ( "-" . repeat ( 80 ) ) ) ;
131+ console . log ( "" ) ;
132+ console . log ( `Log file written to ${ tmpLogFile } ` ) ;
133+
134+ if ( "octoherdCache" in options ) {
108135 console . log (
109- levelColor . error ( " DONE " ) ,
110- `Log file written to ${ tmpLogFile } `
136+ "Request cache written to %s" ,
137+ options . octoherdCache || "./cache"
111138 ) ;
112- process . exit ( 1 ) ;
113139 }
114140}
0 commit comments