8
8
getAllTypeSpecPaths ,
9
9
resetGitRepo ,
10
10
} from "./utils.js" ;
11
- import { LogLevel , logMessage , vsoAddAttachment } from "./log.js" ;
12
- import { SpecGenSdkCmdInput } from "./types.js" ;
11
+ import { LogLevel , logMessage , vsoAddAttachment , vsoLogIssue } from "./log.js" ;
12
+ import { CommandLog , SpecGenSdkCmdInput } from "./types.js" ;
13
13
import { detectChangedSpecConfigFiles } from "./change-files.js" ;
14
14
15
15
export async function generateSdkForSingleSpec ( ) : Promise < number > {
@@ -43,6 +43,9 @@ export async function generateSdkForSingleSpec(): Promise<number> {
43
43
statusCode = 1 ;
44
44
}
45
45
logMessage ( "ending group logging" , LogLevel . EndGroup ) ;
46
+
47
+ logIssuesToADO ( commandInput , specConfigPath || '' ) ;
48
+
46
49
return statusCode ;
47
50
}
48
51
@@ -105,6 +108,8 @@ export async function generateSdkForSpecPr(): Promise<number> {
105
108
statusCode = 1 ;
106
109
}
107
110
logMessage ( "ending group logging" , LogLevel . EndGroup ) ;
111
+
112
+ logIssuesToADO ( commandInput , changedSpecPath || '' ) ;
108
113
}
109
114
return statusCode ;
110
115
}
@@ -180,6 +185,8 @@ export async function generateSdkForBatchSpecs(runMode: string): Promise<number>
180
185
statusCode = 1 ;
181
186
}
182
187
logMessage ( "ending group logging" , LogLevel . EndGroup ) ;
188
+
189
+ logIssuesToADO ( commandInput , specConfigPath || '' ) ;
183
190
}
184
191
if ( failedCount > 0 ) {
185
192
markdownContent += `${ failedContent } \n` ;
@@ -325,3 +332,65 @@ function getSpecPaths(runMode: string, specRepoPath: string): string[] {
325
332
}
326
333
return specConfigPaths ;
327
334
}
335
+
336
+ /**
337
+ * Extract and format the prefix from tspConfigPath or readmePath.
338
+ * @param {string | undefined } tspConfigPath The tspConfigPath to extract the prefix from.
339
+ * @param {string | undefined } readmePath The readmePath to extract the prefix from.
340
+ * @returns {string } The formatted prefix.
341
+ */
342
+ function extractPathFromSpecConfig ( tspConfigPath : string | undefined , readmePath : string | undefined ) : string {
343
+ let prefix = '' ;
344
+ if ( tspConfigPath ) {
345
+ const match = tspConfigPath . match ( / s p e c i f i c a t i o n \/ ( .+ ) \/ t s p c o n f i g \. y a m l $ / ) ;
346
+ if ( match ) {
347
+ const segments = match [ 1 ] . split ( '/' ) ;
348
+ prefix = segments . join ( '-' ) . toLowerCase ( ) . replace ( / \. / g, '-' ) ;
349
+ }
350
+ } else if ( readmePath ) {
351
+ const match = readmePath . match ( / s p e c i f i c a t i o n \/ ( .+ ?) \/ r e a d m e \. m d $ / i) ;
352
+ if ( match ) {
353
+ const segments = match [ 1 ] . split ( '/' ) ;
354
+ prefix = segments . join ( '-' ) . toLowerCase ( ) . replace ( / \. / g, '-' ) ;
355
+ }
356
+ }
357
+ return prefix ;
358
+ }
359
+
360
+ /**
361
+ * Generates file paths for different log files based on the given command input.
362
+ * @param {SpecGenSdkCmdInput } commandInput
363
+ * @returns An object containing the full log file path, filtered log file path, and HTML log file path.
364
+ */
365
+ function getLogsPath ( commandInput : SpecGenSdkCmdInput ) : { fullLogFileName : string , filteredLogFileName : string , htmlLogFileName : string } {
366
+ const fileNamePrefix = extractPathFromSpecConfig ( commandInput . tspConfigPath , commandInput . readmePath )
367
+ const logFolder = path . join ( commandInput . workingFolder , 'out/logs' ) ;
368
+ const fullLogFileName = path . join ( logFolder , `${ fileNamePrefix } -full.log` ) ;
369
+ const filteredLogFileName = path . join ( logFolder , `${ fileNamePrefix } -filtered.log` ) ;
370
+ const htmlLogFileName = path . join ( logFolder , `${ fileNamePrefix } -${ commandInput . sdkRepoName . substring ( "azure-sdk-for-" . length ) } -gen-result.html` ) ;
371
+ return { fullLogFileName, filteredLogFileName, htmlLogFileName } ;
372
+ }
373
+
374
+ /**
375
+ * Logs SDK generation issues to Azure DevOps (ADO)
376
+ * @param commandInput
377
+ * @param specConfigPath
378
+ */
379
+ function logIssuesToADO ( commandInput : SpecGenSdkCmdInput , specConfigPath : string ) : void {
380
+ const logPath = getLogsPath ( commandInput ) . filteredLogFileName ;
381
+ let logIssues :CommandLog [ ] = [ ]
382
+ try {
383
+ const log = JSON . parse ( fs . readFileSync ( logPath , "utf8" ) ) ;
384
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
385
+ logIssues = log . logIssues ;
386
+ } catch ( error ) {
387
+ logMessage ( `Error reading log at ${ logPath } :${ error } ` , LogLevel . Error ) ;
388
+ }
389
+
390
+ if ( logIssues . length > 0 ) {
391
+ logMessage ( `Error generating SDK from ${ specConfigPath } ` , LogLevel . Group ) ;
392
+ const logIssuesList = logIssues . flatMap ( entry => [ `Get log issues from script ${ entry . command } ` , ...entry . logIssues ] ) ; ;
393
+ vsoLogIssue ( logIssuesList . join ( '%0D%0A' ) ) ;
394
+ logMessage ( "ending group logging" , LogLevel . EndGroup ) ;
395
+ }
396
+ }
0 commit comments