@@ -25712,6 +25712,29 @@ function buildUrl(baseUrl, endpoint, environment) {
2571225712 return `${baseUrl}${endpoint}${envParam}`;
2571325713}
2571425714
25715+ function getFileFormat(filePath) {
25716+ const ext = path.extname(filePath).toLowerCase();
25717+ if (ext === '.json') return 'json';
25718+ return 'yaml'; // .yaml, .yml, or any other extension defaults to yaml
25719+ }
25720+
25721+ function buildYamlPayload(content, variables) {
25722+ // Indent each line of the changeset content for YAML block scalar
25723+ const indentedContent = content.split('\n').map(line => ' ' + line).join('\n');
25724+ let yaml = `changeset: |\n${indentedContent}`;
25725+
25726+ if (variables && Object.keys(variables).length > 0) {
25727+ yaml += '\nvariables:';
25728+ for (const [key, value] of Object.entries(variables)) {
25729+ // Quote values to safely handle special YAML characters
25730+ const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
25731+ yaml += `\n ${key}: "${escaped}"`;
25732+ }
25733+ }
25734+
25735+ return yaml;
25736+ }
25737+
2571525738function isGlobPattern(pattern) {
2571625739 return /[*?[\]{}]/.test(pattern);
2571725740}
@@ -25747,15 +25770,27 @@ function resolveFiles(changesetFile) {
2574725770async function validateFile(filePath, options) {
2574825771 const { apiKey, baseUrl, environment, pollingTimeoutSeconds, changesetVariables } = options;
2574925772 const content = fs.readFileSync(filePath, 'utf8');
25750- const validateUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/validate_yaml/', environment);
25751-
25752- core.debug(`Validate URL: ${validateUrl}`);
25753-
25754- // Prepare request payload with changeset and variables
25755- const requestPayload = {
25756- changeset: content,
25757- ...(changesetVariables && { variables: changesetVariables })
25758- };
25773+ const format = getFileFormat(filePath);
25774+ const endpoint = format === 'json'
25775+ ? '/api/v1/change-set/change-set/validate_json/'
25776+ : '/api/v1/change-set/change-set/validate_yaml/';
25777+ const validateUrl = buildUrl(baseUrl, endpoint, environment);
25778+
25779+ core.debug(`Validate URL: ${validateUrl} (format: ${format})`);
25780+
25781+ // Build request body and content type based on file format
25782+ let body, contentType;
25783+ if (format === 'json') {
25784+ contentType = 'application/json';
25785+ const requestPayload = {
25786+ changeset: content,
25787+ ...(changesetVariables && { variables: changesetVariables })
25788+ };
25789+ body = JSON.stringify(requestPayload);
25790+ } else {
25791+ contentType = 'text/yaml';
25792+ body = buildYamlPayload(content, changesetVariables);
25793+ }
2575925794
2576025795 core.debug(`Sending validation request to: ${validateUrl}`);
2576125796 let validateResponse;
@@ -25764,9 +25799,9 @@ async function validateFile(filePath, options) {
2576425799 method: 'POST',
2576525800 headers: {
2576625801 'Authorization': `Api-Key ${apiKey}`,
25767- 'Content-Type': 'application/json'
25802+ 'Content-Type': contentType
2576825803 },
25769- body: JSON.stringify(requestPayload)
25804+ body
2577025805 });
2577125806 core.debug(`API response status: ${validateResponse.status}`);
2577225807 } catch (error) {
@@ -25832,15 +25867,27 @@ async function validateFile(filePath, options) {
2583225867async function executeFile(filePath, options) {
2583325868 const { apiKey, baseUrl, environment, pollingTimeoutSeconds, changesetVariables } = options;
2583425869 const content = fs.readFileSync(filePath, 'utf8');
25835- const executeUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/execute_yaml/', environment);
25836-
25837- core.debug(`Execute URL: ${executeUrl}`);
25838-
25839- // Prepare request payload with changeset and variables
25840- const requestPayload = {
25841- changeset: content,
25842- ...(changesetVariables && { variables: changesetVariables })
25843- };
25870+ const format = getFileFormat(filePath);
25871+ const endpoint = format === 'json'
25872+ ? '/api/v1/change-set/change-set/execute_json/'
25873+ : '/api/v1/change-set/change-set/execute_yaml/';
25874+ const executeUrl = buildUrl(baseUrl, endpoint, environment);
25875+
25876+ core.debug(`Execute URL: ${executeUrl} (format: ${format})`);
25877+
25878+ // Build request body and content type based on file format
25879+ let body, contentType;
25880+ if (format === 'json') {
25881+ contentType = 'application/json';
25882+ const requestPayload = {
25883+ changeset: content,
25884+ ...(changesetVariables && { variables: changesetVariables })
25885+ };
25886+ body = JSON.stringify(requestPayload);
25887+ } else {
25888+ contentType = 'text/yaml';
25889+ body = buildYamlPayload(content, changesetVariables);
25890+ }
2584425891
2584525892 core.debug(`Sending API request to: ${executeUrl}`);
2584625893 let executeResponse;
@@ -25849,9 +25896,9 @@ async function executeFile(filePath, options) {
2584925896 method: 'POST',
2585025897 headers: {
2585125898 'Authorization': `Api-Key ${apiKey}`,
25852- 'Content-Type': 'application/json'
25899+ 'Content-Type': contentType
2585325900 },
25854- body: JSON.stringify(requestPayload)
25901+ body
2585525902 });
2585625903 core.debug(`API response status: ${executeResponse.status}`);
2585725904 } catch (error) {
@@ -26150,7 +26197,7 @@ async function run() {
2615026197 }
2615126198}
2615226199
26153- module.exports = { run, pollTask, buildUrl, isGlobPattern, resolveFiles, worstStatus };
26200+ module.exports = { run, pollTask, buildUrl, isGlobPattern, resolveFiles, worstStatus, getFileFormat, buildYamlPayload };
2615426201
2615526202/* istanbul ignore next */
2615626203if (require.main === require.cache[eval('__filename')]) {
0 commit comments