-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* shellcheck * fix comment pr * better format Signed-off-by: Michele Palazzi <sysdadmin@m1k.cloud>
- Loading branch information
1 parent
351465a
commit e2facc0
Showing
4 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
TERRAFORM_OPTIONS="$1" | ||
|
||
if ! PLAN=$(terraform $TERRAFORM_OPTIONS show -no-color terraform.tfplan); then | ||
echo "Error: Failed to get terraform plan output" | ||
exit 1 | ||
fi | ||
|
||
if ! PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH"); then | ||
echo "Error: Failed to get PR number" | ||
exit 1 | ||
fi | ||
|
||
if ! REPO_OWNER=$(jq --raw-output .repository.owner.login "$GITHUB_EVENT_PATH"); then | ||
echo "Error: Failed to get repo owner" | ||
exit 1 | ||
fi | ||
|
||
if ! REPO_NAME=$(jq --raw-output .repository.name "$GITHUB_EVENT_PATH"); then | ||
echo "Error: Failed to get repo name" | ||
exit 1 | ||
fi | ||
|
||
# Create JSON payload with proper escaping | ||
PAYLOAD=$(jq -n \ | ||
--arg body "$(printf '```\n%s\n```' "$PLAN")" \ | ||
'{"body": $body}') | ||
|
||
if ! curl -s \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d "$PAYLOAD" \ | ||
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments"; then | ||
echo "Error: Failed to post comment" | ||
exit 1 | ||
fi | ||
|
||
echo "Comment posted successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters