File tree Expand file tree Collapse file tree 2 files changed +45
-5
lines changed
Expand file tree Collapse file tree 2 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,46 @@ describe("API", () => {
281281 `"fetchWorkflowId: An unexpected error has occurred: Unable to find ID for Workflow: slice"` ,
282282 ) ;
283283 } ) ;
284+
285+ it ( "should return the workflow ID when the name is a substring of another workflow name" , async ( ) => {
286+ const mockData = [
287+ {
288+ id : 0 ,
289+ path : ".github/workflows/small-cake.yml" ,
290+ } ,
291+ {
292+ id : 1 ,
293+ path : ".github/workflows/big-cake.yml" ,
294+ } ,
295+ {
296+ id : 2 ,
297+ path : ".github/workflows/cake.yml" ,
298+ } ,
299+ ] ;
300+ vi . spyOn ( mockOctokit . rest . actions , "listRepoWorkflows" ) . mockReturnValue (
301+ Promise . resolve ( {
302+ data : mockData ,
303+ status : 200 ,
304+ } ) ,
305+ ) ;
306+
307+ // Behaviour
308+ expect ( await fetchWorkflowId ( "cake.yml" ) ) . toStrictEqual ( mockData [ 2 ] ! . id ) ;
309+
310+ // Logging
311+ assertOnlyCalled ( coreInfoLogMock ) ;
312+ expect ( coreInfoLogMock ) . toHaveBeenCalledOnce ( ) ;
313+ expect ( coreInfoLogMock . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchInlineSnapshot (
314+ `
315+ "Fetched Workflow ID:
316+ Repository: owner/repo
317+ Workflow ID: '2'
318+ Input Filename: 'cake.yml'
319+ Sanitised Filename: 'cake\\.yml'
320+ URL: undefined"
321+ ` ,
322+ ) ;
323+ } ) ;
284324 } ) ;
285325
286326 describe ( "fetchWorkflowRunIds" , ( ) => {
Original file line number Diff line number Diff line change @@ -61,10 +61,10 @@ export async function fetchWorkflowId(
6161 workflowFilename : string ,
6262) : Promise < number > {
6363 try {
64- const sanitisedFilename = workflowFilename . replace (
65- / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g,
66- "\\$&" ,
67- ) ;
64+ const sanitisedFilename = workflowFilename
65+ . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" )
66+ . trim ( ) ;
67+ const filenameRegex = new RegExp ( `/ ${ sanitisedFilename } ` ) ;
6868
6969 // https://docs.github.com/en/rest/actions/workflows#list-repository-workflows
7070 const workflowIterator = octokit . paginate . iterator (
@@ -85,7 +85,7 @@ export async function fetchWorkflowId(
8585 }
8686
8787 const workflowData = response . data . find ( ( workflow ) =>
88- new RegExp ( sanitisedFilename ) . test ( workflow . path ) ,
88+ filenameRegex . test ( workflow . path ) ,
8989 ) ;
9090 workflowId = workflowData ?. id ;
9191
You can’t perform that action at this time.
0 commit comments