Skip to content

Commit

Permalink
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
Browse files Browse the repository at this point in the history
…n/terraform-change-summary into minimize-prev-comment
  • Loading branch information
DeWildeDaan committed Aug 30, 2024
2 parents acd2f6e + 6ca28e7 commit 5b46d6e
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12831,7 +12831,7 @@ const includeLinkToWorkflow = core.getBooleanInput('include-workflow-link');
const hidePreviousComments = core.getBooleanInput('hide-previous-comments');

const workflowLink = includeLinkToWorkflow ? `
[Workflow: ${context.workflow}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})
[Workflow: ${context.workflow}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId })
` : "";

var hasNoChanges = false;
Expand Down Expand Up @@ -12862,53 +12862,53 @@ const commentsQuery = /* GraphQL */ `
`;

const output = () => {
let body = '';
// for each file
for (const file of inputFilenames) {
const resource_changes = JSON.parse(fs.readFileSync(file)).resource_changes;
try {
let changed_resources = resource_changes.filter((resource) => {
return resource.change.actions != ["no-op"];
})
let body = '';
// for each file
for (const file of inputFilenames) {
const resource_changes = JSON.parse(fs.readFileSync(file)).resource_changes;
try {
let changed_resources = resource_changes.filter((resource) => {
return resource.change.actions != ["no-op"];
})

console.log("changed_resources", changed_resources)
if (Array.isArray(resource_changes) && resource_changes.length > 0) {
const resources_to_create = [],
resources_to_update = [],
resources_to_delete = [],
resources_to_replace = [],
resources_unchanged = [];

// for each resource changes
for (const resource of resource_changes) {
const change = resource.change;
const address = resource.address;

switch (change.actions[0]) {
default:
break;
case "no-op":
resources_unchanged.push(address);
break;
case "create":
resources_to_create.push(address);
break;
case "delete":
if (change.actions.length > 1) {
resources_to_replace.push(address);
} else {
resources_to_delete.push(address);
}
break;
case "update":
resources_to_update.push(address);
break;
}
console.log("changed_resources", changed_resources)
if (Array.isArray(resource_changes) && resource_changes.length > 0) {
const resources_to_create = [],
resources_to_update = [],
resources_to_delete = [],
resources_to_replace = [],
resources_unchanged = [];

// for each resource changes
for (const resource of resource_changes) {
const change = resource.change;
const address = resource.address;

switch (change.actions[0]) {
default:
break;
case "no-op":
resources_unchanged.push(address);
break;
case "create":
resources_to_create.push(address);
break;
case "delete":
if (change.actions.length > 1) {
resources_to_replace.push(address);
} else {
resources_to_delete.push(address);
}
break;
case "update":
resources_to_update.push(address);
break;
}
// the body must be indented at the start otherwise
// there will be formatting error when comment is
// showed on GitHub
body += `
}
// the body must be indented at the start otherwise
// there will be formatting error when comment is
// showed on GitHub
body += `
${commentHeader}
<details ${expandDetailsComment ? "open" : ""}>
<summary>
Expand All @@ -12922,44 +12922,44 @@ ${details("replace", resources_to_replace, "+")}
${commentFooter.map(a => a == '' ? '\n' : a).join('\n')}
${workflowLink}
`
if (resources_to_create + resources_to_delete + resources_to_update + resources_to_replace == []) {
hasNoChanges = true;
}
} else {
if (resources_to_create + resources_to_delete + resources_to_update + resources_to_replace == []) {
hasNoChanges = true;
console.log("No changes found in the plan. setting hasNoChanges to true.")
body += `
}
} else {
hasNoChanges = true;
console.log("No changes found in the plan. setting hasNoChanges to true.")
body += `
<p>There were no changes done to the infrastructure.</p>
`
core.info(`"The content of ${file} did not result in a valid array or the array is empty... Skipping."`)
}
} catch (error) {
core.error(`${file} is not a valid JSON file. error: ${error}`);
core.info(`"The content of ${file} did not result in a valid array or the array is empty... Skipping."`)
}
} catch (error) {
core.error(`${file} is not a valid JSON file. error: ${error}`);
}
return body;
}
return body;
}

const details = (action, resources, operator) => {
let str = "";
let str = "";

if (resources.length !== 0) {
str = `
if (resources.length !== 0) {
str = `
#### Resources to ${action}\n
\`\`\`diff\n
`;
for (const el of resources) {
// In the replace block, we show delete (-) and then create (+)
if (action === "replace") {
str += `- ${el}\n`
}
str += `${operator} ${el}\n`
for (const el of resources) {
// In the replace block, we show delete (-) and then create (+)
if (action === "replace") {
str += `- ${el}\n`
}

str += "```\n"
str += `${operator} ${el}\n`
}

return str;
str += "```\n"
}

return str;
}

const queryComments = (variables) => {
Expand Down

0 comments on commit 5b46d6e

Please sign in to comment.