@@ -123,37 +123,82 @@ async function run() {
123
123
124
124
//if (tags && tags.includes("VSCUSE")) {
125
125
const steps = workItem . fields ?. [ "Microsoft.VSTS.TCM.Steps" ] ;
126
+ const stepOrComprefRegex =
127
+ / ( < s t e p \s [ \s \S ] * ?< \/ s t e p > | < c o m p r e f i d = " \d + " r e f = " \d + " > ) / gi;
126
128
if ( typeof steps === "string" ) {
127
- const stepBlocks = steps . match ( / < s t e p [ \s \S ] * ?< \/ s t e p > / gi) || [ ] ;
128
-
129
- stepBlocks . forEach ( ( stepBlock , idx ) => {
130
- const paramMatch = stepBlock . match (
131
- / < p a r a m e t e r i z e d S t r i n g [ ^ > ] * > ( [ \s \S ] * ?) < \/ p a r a m e t e r i z e d S t r i n g > / i
132
- ) ;
133
- let text = "" ;
134
- if ( paramMatch && paramMatch [ 1 ] ) {
135
- const html = paramMatch [ 1 ]
136
- . replace ( / & l t ; / g, "<" )
137
- . replace ( / & g t ; / g, ">" ) ;
138
- const pMatch =
139
- html . match ( / < p > ( [ \s \S ] * ?) < \/ p > / i) ||
140
- html . match ( / < P > ( [ \s \S ] * ?) < \/ P > / i) ;
141
- if ( pMatch && pMatch [ 1 ] ) {
142
- text = pMatch [ 1 ] . replace ( / < [ ^ > ] + > / g, "" ) . trim ( ) ;
129
+ const stepBlocks = steps . match ( stepOrComprefRegex ) || [ ] ;
130
+
131
+ const getStepDetails = async (
132
+ stepBlocks : string [ ] ,
133
+ outputLines : string [ ]
134
+ ) => {
135
+ for ( const stepBlock of stepBlocks ) {
136
+ const paramMatch = stepBlock . match (
137
+ / < p a r a m e t e r i z e d S t r i n g [ ^ > ] * > ( [ \s \S ] * ?) < \/ p a r a m e t e r i z e d S t r i n g > / i
138
+ ) ;
139
+ let text = "" ;
140
+ if ( paramMatch && paramMatch [ 1 ] ) {
141
+ const html = paramMatch [ 1 ]
142
+ . replace ( / & l t ; / g, "<" )
143
+ . replace ( / & g t ; / g, ">" ) ;
144
+ const pMatch =
145
+ html . match ( / < p > ( [ \s \S ] * ?) < \/ p > / i) ||
146
+ html . match ( / < P > ( [ \s \S ] * ?) < \/ P > / i) ;
147
+ if ( pMatch && pMatch [ 1 ] ) {
148
+ text = pMatch [ 1 ] . replace ( / < [ ^ > ] + > / g, "" ) . trim ( ) ;
149
+ }
150
+ if ( ! text ) {
151
+ const match =
152
+ stepBlock . match ( / < p > ( [ \s \S ] * ?) < \/ p > / i) ||
153
+ stepBlock . match ( / < P > ( [ \s \S ] * ?) < \/ P > / i) ;
154
+ if ( match && match [ 1 ] ) {
155
+ text = match [ 1 ] . replace ( / < [ ^ > ] + > / g, "" ) . trim ( ) ;
156
+ }
157
+ }
158
+ if ( text ) {
159
+ outputLines . push ( text ) ;
160
+ }
161
+ continue ;
143
162
}
144
- }
145
- if ( ! text ) {
146
- const match =
147
- stepBlock . match ( / < p > ( [ \s \S ] * ?) < \/ p > / i) ||
148
- stepBlock . match ( / < P > ( [ \s \S ] * ?) < \/ P > / i) ;
149
- if ( match && match [ 1 ] ) {
150
- text = match [ 1 ] . replace ( / < [ ^ > ] + > / g, "" ) . trim ( ) ;
163
+
164
+ const comprefMatch = stepBlock . match (
165
+ / < c o m p r e f i d = " \d + " r e f = " ( \d + ) " > / i
166
+ ) ;
167
+ if ( comprefMatch && comprefMatch [ 1 ] ) {
168
+ const url = `https://msazure.visualstudio.com/_apis/wit/workItems/${ comprefMatch [ 1 ] } ` ;
169
+ console . log (
170
+ `Fetching shared step work item from URL: ${ url } `
171
+ ) ;
172
+ try {
173
+ // Use the Azure AD token for authentication
174
+ const response = await fetch ( url , {
175
+ headers : {
176
+ Authorization : `Bearer ${ token . token } ` ,
177
+ "Content-Type" : "application/json" ,
178
+ } ,
179
+ } ) ;
180
+ if ( ! response . ok ) {
181
+ console . error (
182
+ `Failed to fetch work item: shared step ${ comprefMatch [ 1 ] } , status: ${ response . status } `
183
+ ) ;
184
+ continue ;
185
+ }
186
+ const workItem = ( await response . json ( ) ) as WorkItem ;
187
+ const steps =
188
+ workItem . fields ?. [ "Microsoft.VSTS.TCM.Steps" ] ;
189
+ const stepBlocksChild =
190
+ steps . match ( stepOrComprefRegex ) || [ ] ;
191
+ await getStepDetails ( stepBlocksChild , outputLines ) ;
192
+ } catch ( err ) {
193
+ console . error (
194
+ `Error fetching shared step work item ${ comprefMatch [ 1 ] } :` ,
195
+ err
196
+ ) ;
197
+ }
151
198
}
152
199
}
153
- if ( text ) {
154
- outputLines . push ( text ) ;
155
- }
156
- } ) ;
200
+ } ;
201
+ await getStepDetails ( stepBlocks , outputLines ) ;
157
202
const filePath = path . join ( outputDir , `${ tc . testCase . id } .txt` ) ;
158
203
fs . writeFileSync ( filePath , outputLines . join ( "\n" ) , {
159
204
encoding : "utf8" ,
0 commit comments