Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding bool flag to add comment instead of exiting early #5

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}