Fix a bug where changes were added to the change map via callback (#35966)

This commit is contained in:
Sam Seay 2022-12-15 11:55:52 +13:00 committed by GitHub
parent 31e6f90e74
commit df3687a79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 30 deletions

View File

@ -24,7 +24,7 @@ export type HookChangeDescription = {
ghLink: string;
};
export const scanForHookChanges = (
export const scanForHookChanges = async (
content: string,
version: string,
tmpRepoPath: string
@ -51,6 +51,7 @@ export const scanForHookChanges = (
if ( ! patchWithHook ) {
continue;
}
const results = patchWithHook.match( newRegEx );
if ( ! results ) {
@ -81,37 +82,39 @@ export const scanForHookChanges = (
if ( ! hookName[ 2 ].startsWith( '-' ) ) {
let ghLink = '';
fs.readFile(
tmpRepoPath + filePath,
'utf-8',
function ( err, data ) {
if ( err ) {
console.error( err );
try {
const data = await fs.promises.readFile(
tmpRepoPath + filePath,
'utf-8'
);
const reg = new RegExp( name );
data.split( '\n' ).forEach( ( line, index ) => {
if ( line.match( reg ) ) {
const lineNum = index + 1;
ghLink = `https://github.com/woocommerce/woocommerce/blob/${ version }/${ filePath.replace(
/(^\/)/,
''
) }#L${ lineNum }`;
}
} );
const reg = new RegExp( name );
data.split( '\n' ).forEach( ( line, index ) => {
if ( line.match( reg ) ) {
const lineNum = index + 1;
ghLink = `https://github.com/woocommerce/woocommerce/blob/${ version }/${ filePath.replace(
/(^\/)/,
''
) }#L${ lineNum }`;
}
} );
changes.set( filePath, {
filePath,
name,
hookType,
description,
changeType,
version,
ghLink,
} );
changes.set( filePath, {
filePath,
name,
hookType,
description,
changeType,
version,
ghLink,
} );
} catch ( error ) {
if ( error ) {
console.error( error );
}
);
}
}
}
}

View File

@ -50,7 +50,11 @@ export const scanForChanges = async (
const pluginPath = join( tmpRepoPath, 'plugins/woocommerce' );
Logger.startTask( 'Detecting hook changes...' );
const hookChanges = scanForHookChanges( diff, sinceVersion, tmpRepoPath );
const hookChanges = await scanForHookChanges(
diff,
sinceVersion,
tmpRepoPath
);
Logger.endTask();
Logger.startTask( 'Detecting template changes...' );