Skip to content

Commit da31679

Browse files
update extraction of alias from sql file
1 parent 5dc164b commit da31679

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

adapters/integrations/gitlab-integration.js

+59-15
Original file line numberDiff line numberDiff line change
@@ -779,23 +779,67 @@ ${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 = fileContent.match(startRegex);
785+
let configSection = ''
786+
if (startMatch) {
787+
const startIndex = startMatch.index;
788+
const openParensIndex = fileContent.indexOf('(', startIndex) + 1;
789+
let openParensCount = 1;
790+
let endIndex = openParensIndex;
791+
792+
while (openParensCount > 0 && endIndex < fileContent.length) {
793+
const char = fileContent[endIndex];
794+
795+
if (char === '(') {
796+
openParensCount++;
797+
} else if (char === ')') {
798+
openParensCount--;
799+
}
800+
801+
endIndex++;
802+
}
783803

784-
logger.withInfo(
785-
"Successfully executed regex matching",
786-
integrationName,
787-
CI_COMMIT_SHA,
788-
"getAssetName"
789-
);
804+
const endMarker = '}}';
805+
const finalEndIndex = fileContent.indexOf(endMarker, endIndex) + endMarker.length;
790806

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();
807+
configSection = fileContent.substring(startIndex, finalEndIndex);
808+
logger.withInfo(
809+
"Extracted config section",
810+
integrationName,
811+
CI_COMMIT_SHA,
812+
"getAssetName"
813+
);
814+
815+
if (configSection){
816+
logger.withInfo(
817+
"Executing final regex",
818+
integrationName,
819+
CI_COMMIT_SHA,
820+
"getAssetName"
821+
);
822+
823+
var matches = regExp.exec(configSection);
824+
825+
logger.withInfo(
826+
"Successfully executed regex matching",
827+
integrationName,
828+
CI_COMMIT_SHA,
829+
"getAssetName"
830+
);
831+
832+
}
833+
if (matches) {
834+
logger.withInfo(
835+
`Found a match: ${matches[1].trim()}`,
836+
integrationName,
837+
CI_COMMIT_SHA,
838+
"getAssetName"
839+
);
840+
841+
return matches[1].trim();
842+
}
799843
}
800844
}
801845

0 commit comments

Comments
 (0)