From e61894666a06f3cf7027f9a10f8ba3a64cd5220c Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Tue, 15 Oct 2024 20:32:15 +0530 Subject: [PATCH 1/2] extract config before running complex regex --- adapters/integrations/github-integration.js | 84 ++++++++++++++++++--- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/adapters/integrations/github-integration.js b/adapters/integrations/github-integration.js index e7729e5..0f227ec 100644 --- a/adapters/integrations/github-integration.js +++ b/adapters/integrations/github-integration.js @@ -683,24 +683,90 @@ export default class GitHubIntegration extends IntegrationInterface { filePath, }); + logger.withInfo( + `Successfully fetched file contents. File size: ${fileContents.length} bytes`, + integrationName, + headSHA, + "getAssetName" + ); + if (fileContents) { - var matches = regExp.exec(fileContents); - if (matches) { - logger.withInfo( - `Found a match: ${matches[1].trim()}`, - integrationName, - headSHA, - "getAssetName" - ); - return matches[1].trim(); + logger.withInfo( + "Starting regex matching", + integrationName, + headSHA, + "getAssetName" + ); + const startRegex = + /{{\s*config\s*\(/im; + const startMatch = fileContents.match(startRegex); + let configSection = '' + if (startMatch) { + const startIndex = startMatch.index; + const openParensIndex = fileContents.indexOf('(', startIndex) + 1; + let openParensCount = 1; + let endIndex = openParensIndex; + + while (openParensCount > 0 && endIndex < fileContents.length) { + const char = fileContents[endIndex]; + + if (char === '(') { + openParensCount++; + } else if (char === ')') { + openParensCount--; + } + endIndex++; + } + + const endMarker = '}}'; + const finalEndIndex = fileContents.indexOf(endMarker, endIndex) + endMarker.length; + + configSection = fileContents.substring(startIndex, finalEndIndex); + logger.withInfo( + "Extracted config section", + integrationName, + headSHA, + "getAssetName" + ); + + if (configSection){ + logger.withInfo( + "Executing final regex", + integrationName, + headSHA, + "getAssetName" + ); + + var matches = regExp.exec(configSection); + + logger.withInfo( + "Successfully executed regex matching", + integrationName, + headSHA, + "getAssetName" + ); + + } + if (matches) { + logger.withInfo( + `Found a match: ${matches[1].trim()}`, + integrationName, + headSHA, + "getAssetName" + ); + + return matches[1].trim(); + } } } + logger.withInfo( `Using filename as asset name: ${fileName}`, integrationName, headSHA, "getAssetName" ); + return fileName; } catch (error) { logger.withError( From d0b2a13f8bf35cbe694693cf5323cc87f080ef61 Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Tue, 15 Oct 2024 20:34:24 +0530 Subject: [PATCH 2/2] update dist/index file --- dist/index.js | 84 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5a16acb..fcff381 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26179,24 +26179,90 @@ class GitHubIntegration extends IntegrationInterface { filePath, }); + logger_logger.withInfo( + `Successfully fetched file contents. File size: ${fileContents.length} bytes`, + integrationName, + headSHA, + "getAssetName" + ); + if (fileContents) { - var matches = regExp.exec(fileContents); - if (matches) { - logger_logger.withInfo( - `Found a match: ${matches[1].trim()}`, - integrationName, - headSHA, - "getAssetName" - ); - return matches[1].trim(); + logger_logger.withInfo( + "Starting regex matching", + integrationName, + headSHA, + "getAssetName" + ); + const startRegex = + /{{\s*config\s*\(/im; + const startMatch = fileContents.match(startRegex); + let configSection = '' + if (startMatch) { + const startIndex = startMatch.index; + const openParensIndex = fileContents.indexOf('(', startIndex) + 1; + let openParensCount = 1; + let endIndex = openParensIndex; + + while (openParensCount > 0 && endIndex < fileContents.length) { + const char = fileContents[endIndex]; + + if (char === '(') { + openParensCount++; + } else if (char === ')') { + openParensCount--; + } + endIndex++; + } + + const endMarker = '}}'; + const finalEndIndex = fileContents.indexOf(endMarker, endIndex) + endMarker.length; + + configSection = fileContents.substring(startIndex, finalEndIndex); + logger_logger.withInfo( + "Extracted config section", + integrationName, + headSHA, + "getAssetName" + ); + + if (configSection){ + logger_logger.withInfo( + "Executing final regex", + integrationName, + headSHA, + "getAssetName" + ); + + var matches = regExp.exec(configSection); + + logger_logger.withInfo( + "Successfully executed regex matching", + integrationName, + headSHA, + "getAssetName" + ); + + } + if (matches) { + logger_logger.withInfo( + `Found a match: ${matches[1].trim()}`, + integrationName, + headSHA, + "getAssetName" + ); + + return matches[1].trim(); + } } } + logger_logger.withInfo( `Using filename as asset name: ${fileName}`, integrationName, headSHA, "getAssetName" ); + return fileName; } catch (error) { logger_logger.withError(