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

Improve comment formatting #67

Closed
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ Provide a token to use, if you set `add_pr_comment` to "Yes".

Default `"Not set"`.

### `add_pr_comment_footer`

Add a footer which reads 'Automatically generated by octodns-sync' to the comment, if you set `add_pr_comment` to "Yes". The footer will be hidden if set `add_pr_comment_footer` to anything but `"Yes"`

Default `"Yes"`.

### `octodns_ref`

Select a release tag or a branch of octodns to use. For example "v0.9.12" or "awesome-feature".
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
description: 'Provide a token to use, if you set add_pr_comment to Yes.'
required: true
default: 'Not set'
add_pr_comment_footer:
description: 'Include footer in PR comment? Defaults to Yes'
required: true
default: 'Yes'

runs:
using: 'composite'
Expand All @@ -49,6 +53,8 @@ runs:
env:
ADD_PR_COMMENT: ${{ inputs.add_pr_comment }}
PR_COMMENT_TOKEN: ${{ inputs.pr_comment_token }}
ADD_PR_COMMENT_FOOTER: ${{ inputs.add_pr_comment_footer }}
DOIT: ${{ inputs.doit }}
run: ${{ github.action_path }}/scripts/comment.sh
shell: bash
branding:
Expand Down
15 changes: 9 additions & 6 deletions scripts/comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
# Add pull request comment

_planfile="${GITHUB_WORKSPACE}/octodns-sync.plan"
_doit=$DOIT
_add_footer=$ADD_PR_COMMENT_FOOTER

if [ "${ADD_PR_COMMENT}" = "Yes" ]; then
echo "INFO: \$ADD_PR_COMMENT is 'Yes'."
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
if [[ "${GITHUB_EVENT_NAME}" = "pull_request" || "${GITHUB_EVENT_NAME}" = "pull_request_target" ]]; then
if [ -z "${PR_COMMENT_TOKEN}" ]; then
echo "FAIL: \$PR_COMMENT_TOKEN is not set."
exit 1
fi
else
echo "SKIP: \$GITHUB_EVENT_NAME is not 'pull_request'."
echo "SKIP: \$GITHUB_EVENT_NAME is not 'pull_request or 'pull_request_target'."
exit 0
fi
# Construct the comment body
_sha="$(git log -1 --format='%h')"
_header="## octoDNS Plan for ${_sha}"
_footer="Automatically generated by octodns-sync"
_emoji=$([ "$_doit" == "--doit" ] && echo ":shipit:" || echo ":test_tube:")
_jobtype=$([ "$_doit" == "--doit" ] && echo "**deployment**" || echo "dry-run")
_header="## ${_emoji} octoDNS ${_jobtype} for ${_sha}"
_footer="\nAutomatically generated by octodns-sync"
_body="${_header}

$(cat "${_planfile}")

${_footer}"
$([ "$_add_footer" == "Yes" ] && echo -e "$_footer")"
# Post the comment
# TODO: Rewrite post to use gh rather than python3
_user="github-actions" \
Expand Down