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

add_pr_comment is skipped when pull request is from fork #70

Closed
solvaholic opened this issue Jul 6, 2021 · 1 comment · Fixed by #74
Closed

add_pr_comment is skipped when pull request is from fork #70

solvaholic opened this issue Jul 6, 2021 · 1 comment · Fixed by #74
Labels
bug Something isn't working

Comments

@solvaholic
Copy link
Owner

Description

When contributors submit DNS configuration changes via pull requests from forks, GitHub Actions workflows that run on the pull_request run with a read-only GitHub.token and do not have access to secrets.

To run a test-and-comment workflow with write permission (to add a comment) and secrets access (to run octodns-sync), the workflow can run on the pull_request_target event. In this case, however, comment.sh exits early without adding a comment.

Expected Behavior

add_pr_comment should add a pull request comment, even if the head of the pull request is a fork.

Actual Behavior

Currently scripts/comment.sh exits early if GitHub.event_type is not pull_request:

if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; 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'."
exit 0
fi

Possible Fix

In #67 @travislikestocode proposed adding the pull_request_target event to the check in comment.sh, changing it from:

  if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then

to:

  if [[ "${GITHUB_EVENT_NAME}" = "pull_request" || "${GITHUB_EVENT_NAME}" = "pull_request_target" ]]; then

Steps to Reproduce

  1. Store DNS config in a repo
  2. Use solvaholic/octodns-sync with add_pr_comment enabled
  3. Configure the test-and-comment workflow to run on the pull_request_target event
  4. Have another user fork the repo and submit DNS changes from it via pull request

Context

See prior discussion in #41 and #67.

Your Environment

  • Version used: n/a
  • Link to your project: n/a
@solvaholic solvaholic added the bug Something isn't working label Jul 6, 2021
@solvaholic
Copy link
Owner Author

How would it be if comment.sh didn't check GITHUB_EVENT_NAME at all?

For example:

  if [ -z "${PR_COMMENT_TOKEN}" ]; then
    echo "FAIL: \$PR_COMMENT_TOKEN is not set."
    exit 1
  fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant