Skip to content

Conditional isn't behaving as expected #14

@mikebryant

Description

@mikebryant

https://github.com/NarrativeScience/circleci-orb-ghpr/blob/67bcfe9e201cd79470d7d775f0dc7c4669a30a44/src/commands/get-pr-info.yml#L58

isn't doing the right thing.

If I just use:

- ghpr/get-pr-info

This resolves as:

#!/bin/bash -eo pipefail
# Check `jq` dependency
if ! (command -v jq >/dev/null 2>&1); then
  echo "This command requires jq to be installed"
  exit 1
fi

PR_NUMBER=$(echo "$CIRCLE_PULL_REQUEST" | sed "s/.*\/pull\///")
echo "PR_NUMBER: $PR_NUMBER"
echo "export GITHUB_PR_NUMBER=$PR_NUMBER" >> $BASH_ENV

API_GITHUB="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
PR_REQUEST_URL="$API_GITHUB/pulls/$PR_NUMBER"
PR_RESPONSE=$(curl -H "Authorization: token $GITHUB_TOKEN" "$PR_REQUEST_URL")

PR_TITLE=$(echo $PR_RESPONSE | jq -e '.title' | tr -d '"')
echo "PR_TITLE: $PR_TITLE"
echo "export GITHUB_PR_TITLE='$PR_TITLE'" >> $BASH_ENV

PR_BASE_BRANCH=$(echo $PR_RESPONSE | jq -e '.base.ref' | tr -d '"')
echo "PR_BASE_BRANCH: $PR_BASE_BRANCH"
echo "export GITHUB_PR_BASE_BRANCH='$PR_BASE_BRANCH'" >> $BASH_ENV

PR_AUTHOR_USERNAME=$(echo $PR_RESPONSE | jq -e '.user.login' | tr -d '"')
echo "PR_AUTHOR_USERNAME: $PR_AUTHOR_USERNAME"
echo "export GITHUB_PR_AUTHOR_USERNAME='$PR_AUTHOR_USERNAME'" >> $BASH_ENV

if [[ false == true || false ]]; then
  # We need to use the email address associated with the merge_commit_sha since
  # CIRCLE_SHA1 may have been authored by someone who is not the PR author.
  # Sadly, PR_RESPONSE doesn't include the email associated with the merge_commit_sha.
  # So we have to get that from the commit information.

  PR_MERGE_COMMIT_SHA=$(echo $PR_RESPONSE | jq -e '.merge_commit_sha' | tr -d '"')
  COMMIT_REQUEST_URL="$API_GITHUB/commits/$PR_MERGE_COMMIT_SHA"
  COMMIT_RESPONSE=$(curl -H "Authorization: token $GITHUB_TOKEN" "$COMMIT_REQUEST_URL")
fi

The last section always runs - even though it looks like it shouldn't.

e.g.

circleci@63cb6556884b:~$ if [[ false == true || false ]]; then echo hi; fi
hi

It looks like the second section is being parsed as "is this string, which happens to be false, non-empty"

Possibly change that line to:

if << parameters.get_pr_author_email >> || << parameters.get_pr_author_name >>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions