Skip to content

Commit

Permalink
Merge pull request #5 from DeWildeDaan/always-add-to-summary
Browse files Browse the repository at this point in the history
fix: adding bool flag to add comment instead of exiting early
  • Loading branch information
DeWildeDaan authored Aug 30, 2024
2 parents f5ab41f + 65c0db7 commit 2c90bca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
44 changes: 23 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12939,32 +12939,20 @@ const details = (action, resources, operator) => {

try {
let rawOutput = output();

core.info(`Raw Output: ${rawOutput}`);
let commentPr = true;

if (includePlanSummary && rawOutput) {
core.info("Adding plan output to job summary");
core.summary.addHeading('Terraform Plan Results');
core.summary.addRaw(rawOutput);
core.summary.write();
} else if (includePlanSummary) {
core.warning("Include plan summary is true, but rawOutput is empty or undefined.");
if (includePlanSummary) {
core.info("Adding plan output to job summary")
core.summary.addHeading('Terraform Plan Results').addRaw(rawOutput).write()
}

if (context.eventName === 'pull_request') {
core.info(`Found PR # ${context.issue.number} from workflow context - proceeding to comment.`)
core.info("Adding comment to PR");
core.info(`Comment: ${rawOutput}`);

octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: rawOutput
});

} else {
core.warning("Action doesn't seem to be running in a PR workflow context.")
core.warning("Skipping comment creation.")
core.info("Action doesn't seem to be running in a PR workflow context.")
core.info("Skipping comment creation.")
commentPr = false
}

console.log("quietMode", quietMode)
Expand All @@ -12973,7 +12961,21 @@ try {
if (quietMode && hasNoChanges) {
core.info("quiet mode is enabled and there are no changes to the infrastructure.")
core.info("Skipping comment creation.")
}
commentPr = false
}

if (commentPr){
core.info("Adding comment to PR");
core.info(`Comment: ${rawOutput}`);
octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: rawOutput
});
core.info("Comment added successfully.");
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down
46 changes: 24 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,20 @@ const details = (action, resources, operator) => {

try {
let rawOutput = output();

core.info(`Raw Output: ${rawOutput}`);

if (includePlanSummary && rawOutput) {
core.info("Adding plan output to job summary");
core.summary.addHeading('Terraform Plan Results');
core.summary.addRaw(rawOutput);
core.summary.write();
} else if (includePlanSummary) {
core.warning("Include plan summary is true, but rawOutput is empty or undefined.");
let commentPr = true;

if (includePlanSummary) {
core.info("Adding plan output to job summary")
core.summary.addHeading('Terraform Plan Results').addRaw(rawOutput).write()
}

if (context.eventName === 'pull_request') {
core.info(`Found PR # ${context.issue.number} from workflow context - proceeding to comment.`)
core.info("Adding comment to PR");
core.info(`Comment: ${rawOutput}`);

octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: rawOutput
});

} else {
core.warning("Action doesn't seem to be running in a PR workflow context.")
core.warning("Skipping comment creation.")
core.info("Action doesn't seem to be running in a PR workflow context.")
core.info("Skipping comment creation.")
commentPr = false
}

console.log("quietMode", quietMode)
Expand All @@ -157,7 +145,21 @@ try {
if (quietMode && hasNoChanges) {
core.info("quiet mode is enabled and there are no changes to the infrastructure.")
core.info("Skipping comment creation.")
}
commentPr = false
}

if (commentPr){
core.info("Adding comment to PR");
core.info(`Comment: ${rawOutput}`);
octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: rawOutput
});
core.info("Comment added successfully.");
}

} catch (error) {
core.setFailed(error.message);
}

0 comments on commit 2c90bca

Please sign in to comment.