From da31679e85adb73be4620c36caa1ec903d0feffc Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Wed, 18 Sep 2024 21:40:39 +0530 Subject: [PATCH 1/4] update extraction of alias from sql file --- adapters/integrations/gitlab-integration.js | 74 ++++++++++++++++----- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/adapters/integrations/gitlab-integration.js b/adapters/integrations/gitlab-integration.js index af59dc9..b048a60 100644 --- a/adapters/integrations/gitlab-integration.js +++ b/adapters/integrations/gitlab-integration.js @@ -779,23 +779,67 @@ ${content}`; CI_COMMIT_SHA, "getAssetName" ); - var matches = regExp.exec(fileContents); + const startRegex = + /{{\s*config\s*\(/im; + const startMatch = fileContent.match(startRegex); + let configSection = '' + if (startMatch) { + const startIndex = startMatch.index; + const openParensIndex = fileContent.indexOf('(', startIndex) + 1; + let openParensCount = 1; + let endIndex = openParensIndex; + + while (openParensCount > 0 && endIndex < fileContent.length) { + const char = fileContent[endIndex]; + + if (char === '(') { + openParensCount++; + } else if (char === ')') { + openParensCount--; + } + + endIndex++; + } - logger.withInfo( - "Successfully executed regex matching", - integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); + const endMarker = '}}'; + const finalEndIndex = fileContent.indexOf(endMarker, endIndex) + endMarker.length; - if (matches) { - logger.withInfo( - `Found a match: ${matches[1].trim()}`, - integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); - return matches[1].trim(); + configSection = fileContent.substring(startIndex, finalEndIndex); + logger.withInfo( + "Extracted config section", + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + if (configSection){ + logger.withInfo( + "Executing final regex", + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + var matches = regExp.exec(configSection); + + logger.withInfo( + "Successfully executed regex matching", + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + } + if (matches) { + logger.withInfo( + `Found a match: ${matches[1].trim()}`, + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + return matches[1].trim(); + } } } From 9990423dad37c0c787f4238f092e823de467b432 Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Thu, 19 Sep 2024 15:48:14 +0530 Subject: [PATCH 2/4] fix variable name --- adapters/integrations/gitlab-integration.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adapters/integrations/gitlab-integration.js b/adapters/integrations/gitlab-integration.js index b048a60..dcdeb45 100644 --- a/adapters/integrations/gitlab-integration.js +++ b/adapters/integrations/gitlab-integration.js @@ -781,16 +781,16 @@ ${content}`; ); const startRegex = /{{\s*config\s*\(/im; - const startMatch = fileContent.match(startRegex); + const startMatch = fileContents.match(startRegex); let configSection = '' if (startMatch) { const startIndex = startMatch.index; - const openParensIndex = fileContent.indexOf('(', startIndex) + 1; + const openParensIndex = fileContents.indexOf('(', startIndex) + 1; let openParensCount = 1; let endIndex = openParensIndex; - while (openParensCount > 0 && endIndex < fileContent.length) { - const char = fileContent[endIndex]; + while (openParensCount > 0 && endIndex < fileContents.length) { + const char = fileContents[endIndex]; if (char === '(') { openParensCount++; @@ -802,9 +802,9 @@ ${content}`; } const endMarker = '}}'; - const finalEndIndex = fileContent.indexOf(endMarker, endIndex) + endMarker.length; + const finalEndIndex = fileContents.indexOf(endMarker, endIndex) + endMarker.length; - configSection = fileContent.substring(startIndex, finalEndIndex); + configSection = fileContents.substring(startIndex, finalEndIndex); logger.withInfo( "Extracted config section", integrationName, From 991b6aac6428985e0a2ed3d7a06aa20112f1613a Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Fri, 20 Sep 2024 15:28:25 +0530 Subject: [PATCH 3/4] fix indent --- adapters/integrations/gitlab-integration.js | 61 ++++++++++----------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/adapters/integrations/gitlab-integration.js b/adapters/integrations/gitlab-integration.js index dcdeb45..8a7478b 100644 --- a/adapters/integrations/gitlab-integration.js +++ b/adapters/integrations/gitlab-integration.js @@ -784,23 +784,22 @@ ${content}`; 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 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; @@ -813,21 +812,21 @@ ${content}`; ); if (configSection){ - logger.withInfo( - "Executing final regex", - integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); - - var matches = regExp.exec(configSection); - - logger.withInfo( - "Successfully executed regex matching", - integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); + logger.withInfo( + "Executing final regex", + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + var matches = regExp.exec(configSection); + + logger.withInfo( + "Successfully executed regex matching", + integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); } if (matches) { From 2f4583b8929b694eaee20bdc7c1e9cc4ea77e470 Mon Sep 17 00:00:00 2001 From: sharma-shreyas Date: Tue, 24 Sep 2024 14:21:45 +0530 Subject: [PATCH 4/4] update dist file --- dist/index.js | 73 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index e684f9b..5a16acb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34803,23 +34803,66 @@ ${content}`; CI_COMMIT_SHA, "getAssetName" ); - var matches = regExp.exec(fileContents); + 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; - logger_logger.withInfo( - "Successfully executed regex matching", - gitlab_integration_integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); + configSection = fileContents.substring(startIndex, finalEndIndex); + logger_logger.withInfo( + "Extracted config section", + gitlab_integration_integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); - if (matches) { - logger_logger.withInfo( - `Found a match: ${matches[1].trim()}`, - gitlab_integration_integrationName, - CI_COMMIT_SHA, - "getAssetName" - ); - return matches[1].trim(); + if (configSection){ + logger_logger.withInfo( + "Executing final regex", + gitlab_integration_integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + var matches = regExp.exec(configSection); + + logger_logger.withInfo( + "Successfully executed regex matching", + gitlab_integration_integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + } + if (matches) { + logger_logger.withInfo( + `Found a match: ${matches[1].trim()}`, + gitlab_integration_integrationName, + CI_COMMIT_SHA, + "getAssetName" + ); + + return matches[1].trim(); + } } }