Skip to content

Commit 44961be

Browse files
Merge pull request #129 from atlanhq/pes-3334
PES-3334 : fix: update extraction of alias from sql file
2 parents 5dc164b + 2f4583b commit 44961be

File tree

2 files changed

+116
-30
lines changed

2 files changed

+116
-30
lines changed

adapters/integrations/gitlab-integration.js

+58-15
Original file line numberDiff line numberDiff line change
@@ -779,23 +779,66 @@ ${content}`;
779779
CI_COMMIT_SHA,
780780
"getAssetName"
781781
);
782-
var matches = regExp.exec(fileContents);
782+
const startRegex =
783+
/{{\s*config\s*\(/im;
784+
const startMatch = fileContents.match(startRegex);
785+
let configSection = ''
786+
if (startMatch) {
787+
const startIndex = startMatch.index;
788+
const openParensIndex = fileContents.indexOf('(', startIndex) + 1;
789+
let openParensCount = 1;
790+
let endIndex = openParensIndex;
791+
792+
while (openParensCount > 0 && endIndex < fileContents.length) {
793+
const char = fileContents[endIndex];
794+
795+
if (char === '(') {
796+
openParensCount++;
797+
} else if (char === ')') {
798+
openParensCount--;
799+
}
800+
endIndex++;
801+
}
802+
803+
const endMarker = '}}';
804+
const finalEndIndex = fileContents.indexOf(endMarker, endIndex) + endMarker.length;
783805

784-
logger.withInfo(
785-
"Successfully executed regex matching",
786-
integrationName,
787-
CI_COMMIT_SHA,
788-
"getAssetName"
789-
);
806+
configSection = fileContents.substring(startIndex, finalEndIndex);
807+
logger.withInfo(
808+
"Extracted config section",
809+
integrationName,
810+
CI_COMMIT_SHA,
811+
"getAssetName"
812+
);
790813

791-
if (matches) {
792-
logger.withInfo(
793-
`Found a match: ${matches[1].trim()}`,
794-
integrationName,
795-
CI_COMMIT_SHA,
796-
"getAssetName"
797-
);
798-
return matches[1].trim();
814+
if (configSection){
815+
logger.withInfo(
816+
"Executing final regex",
817+
integrationName,
818+
CI_COMMIT_SHA,
819+
"getAssetName"
820+
);
821+
822+
var matches = regExp.exec(configSection);
823+
824+
logger.withInfo(
825+
"Successfully executed regex matching",
826+
integrationName,
827+
CI_COMMIT_SHA,
828+
"getAssetName"
829+
);
830+
831+
}
832+
if (matches) {
833+
logger.withInfo(
834+
`Found a match: ${matches[1].trim()}`,
835+
integrationName,
836+
CI_COMMIT_SHA,
837+
"getAssetName"
838+
);
839+
840+
return matches[1].trim();
841+
}
799842
}
800843
}
801844

dist/index.js

+58-15
Original file line numberDiff line numberDiff line change
@@ -34803,23 +34803,66 @@ ${content}`;
3480334803
CI_COMMIT_SHA,
3480434804
"getAssetName"
3480534805
);
34806-
var matches = regExp.exec(fileContents);
34806+
const startRegex =
34807+
/{{\s*config\s*\(/im;
34808+
const startMatch = fileContents.match(startRegex);
34809+
let configSection = ''
34810+
if (startMatch) {
34811+
const startIndex = startMatch.index;
34812+
const openParensIndex = fileContents.indexOf('(', startIndex) + 1;
34813+
let openParensCount = 1;
34814+
let endIndex = openParensIndex;
34815+
34816+
while (openParensCount > 0 && endIndex < fileContents.length) {
34817+
const char = fileContents[endIndex];
34818+
34819+
if (char === '(') {
34820+
openParensCount++;
34821+
} else if (char === ')') {
34822+
openParensCount--;
34823+
}
34824+
endIndex++;
34825+
}
34826+
34827+
const endMarker = '}}';
34828+
const finalEndIndex = fileContents.indexOf(endMarker, endIndex) + endMarker.length;
3480734829

34808-
logger_logger.withInfo(
34809-
"Successfully executed regex matching",
34810-
gitlab_integration_integrationName,
34811-
CI_COMMIT_SHA,
34812-
"getAssetName"
34813-
);
34830+
configSection = fileContents.substring(startIndex, finalEndIndex);
34831+
logger_logger.withInfo(
34832+
"Extracted config section",
34833+
gitlab_integration_integrationName,
34834+
CI_COMMIT_SHA,
34835+
"getAssetName"
34836+
);
3481434837

34815-
if (matches) {
34816-
logger_logger.withInfo(
34817-
`Found a match: ${matches[1].trim()}`,
34818-
gitlab_integration_integrationName,
34819-
CI_COMMIT_SHA,
34820-
"getAssetName"
34821-
);
34822-
return matches[1].trim();
34838+
if (configSection){
34839+
logger_logger.withInfo(
34840+
"Executing final regex",
34841+
gitlab_integration_integrationName,
34842+
CI_COMMIT_SHA,
34843+
"getAssetName"
34844+
);
34845+
34846+
var matches = regExp.exec(configSection);
34847+
34848+
logger_logger.withInfo(
34849+
"Successfully executed regex matching",
34850+
gitlab_integration_integrationName,
34851+
CI_COMMIT_SHA,
34852+
"getAssetName"
34853+
);
34854+
34855+
}
34856+
if (matches) {
34857+
logger_logger.withInfo(
34858+
`Found a match: ${matches[1].trim()}`,
34859+
gitlab_integration_integrationName,
34860+
CI_COMMIT_SHA,
34861+
"getAssetName"
34862+
);
34863+
34864+
return matches[1].trim();
34865+
}
3482334866
}
3482434867
}
3482534868

0 commit comments

Comments
 (0)