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( 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(