danger: danger pr [pr] fails but gives no good message how to fix it

Report

What did you do?

$ export DANGER_GITHUB_API_TOKEN=XXXXXXXXXXXX
$ danger pr https://github.com/org/repo/pull/42

Repo is private and token has the right scope for private. Also PR is currently open.

What did you expect to happen?

That it would allow me to test danger locally against a remote PR

What happened instead?

Could not set up API to Code Review site for Danger

For Danger to run on this project, you need to expose a set of following the ENV vars:
 - GitHub: DANGER_GITHUB_API_TOKEN
 - GitLab: DANGER_GITLAB_API_TOKEN
 - BitbucketServer: DANGER_BITBUCKETSERVER_USERNAME, DANGER_BITBUCKETSERVER_PASSWORD, DANGER_BITBUCKETSERVER_HOST
 - BitbucketCloud: DANGER_BITBUCKETCLOUD_USERNAME, DANGER_BITBUCKETCLOUD_PASSWORD


Found these keys in your ENV: RBENV_VERSION, DANGER_GITHUB_API_TOKEN, ...

the env var is there and danger even tells me that it saw it but still fails

Your Environment

  • Which CI are you running on? My Local machine
  • Are you running the latest version of Danger? YES

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 6
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Hit the same thing as others above when trying to run locally on macOS & providing a GitHub URL (“bundle exec danger pr <GITHUB_PR_URL>”). Despite echo for the environment variable providing the token, danger believes it isn’t there, but then lists the environment keys which includes the key it claims is missing.

Running with verbose on, I saw an exception due to a plugin have a conflicting gem version & uninstalled the conflicting version via gem uninstall, but that just led to the same issue still but now without any sort of exception or clue of what to do next.

---------------------------------------------
Error loading the plugin `danger-xcov-0.4.1`.

Gem::ConflictError - Unable to activate fastlane-2.127.1, because public_suffix-3.0.3 conflicts with public_suffix (~> 2.0.0)
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:2302:in `raise_if_conflicts'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1418:in `activate'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1452:in `block in activate_dependencies'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1452:in `block in activate_dependencies'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command/plugin_manager.rb:93:in `safe_activate_and_require'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command/plugin_manager.rb:31:in `block in load_plugins'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command/plugin_manager.rb:30:in `map'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command/plugin_manager.rb:30:in `load_plugins'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command.rb:326:in `block in run'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command.rb:325:in `each'
/usr/local/lib/ruby/gems/2.6.0/gems/claide-1.0.2/lib/claide/command.rb:325:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/danger-6.0.9/bin/danger:5:in `<top (required)>'
/usr/local/lib/ruby/gems/2.6.0/bin/danger:23:in `load'
/usr/local/lib/ruby/gems/2.6.0/bin/danger:23:in `<main>'
---------------------------------------------


Could not set up API to Code Review site for Danger

For Danger to run on this project, you need to expose a set of following the ENV vars:
 - GitHub: DANGER_GITHUB_API_TOKEN
 - GitLab: DANGER_GITLAB_API_TOKEN
 - BitbucketServer: DANGER_BITBUCKETSERVER_USERNAME, DANGER_BITBUCKETSERVER_PASSWORD, DANGER_BITBUCKETSERVER_HOST
 - BitbucketCloud: DANGER_BITBUCKETCLOUD_USERNAME, DANGER_BITBUCKETCLOUD_PASSWORD
 - LocalOnly: DANGER_LOCAL_ONLY
 - VSTS: DANGER_VSTS_API_TOKEN, DANGER_VSTS_HOST


Found these keys in your ENV: LDFLAGS, DANGER_GITHUB_API_TOKEN

So now I just get this:

Could not set up API to Code Review site for Danger

For Danger to run on this project, you need to expose a set of following the ENV vars:
 - GitHub: DANGER_GITHUB_API_TOKEN
 - GitLab: DANGER_GITLAB_API_TOKEN
 - BitbucketServer: DANGER_BITBUCKETSERVER_USERNAME, DANGER_BITBUCKETSERVER_PASSWORD, DANGER_BITBUCKETSERVER_HOST
 - BitbucketCloud: DANGER_BITBUCKETCLOUD_USERNAME, DANGER_BITBUCKETCLOUD_PASSWORD
 - LocalOnly: DANGER_LOCAL_ONLY
 - VSTS: DANGER_VSTS_API_TOKEN, DANGER_VSTS_HOST


Found these keys in your ENV: LDFLAGS, DANGER_GITHUB_API_TOKEN

An interesting thing to note is Danger is obviously picking up the value as when I changed out the token with a brand new, never used token from GitHub, GitHub reports it attempting to access as it changes from “Never used” to “Used within the last week” after running the command.

Running an echo $DANGER_GITHUB_API_TOKEN does spit out the token so unless ruby is using a weird set of environment vars it should be able to see it. It even says in the error message that it sees the DANGER_GITHUB_API_TOKEN in the list of available environment vars…🤔

I am also getting this error when trying to connect to my GitHub enterprise instance.
My environment variable ‘DANGER_GITHUB_HOST’ is a custom URL to my GitHub enterprise server (xxxghub.xxx.com). It looks like this piece of code is inferring which source code repository you’re using by using a regular expression to match on the string ‘github’, -which I don’t have-.

def get_repo_source(repo_url) if repo_url =~ /github/i RequestSources::GitHub elsif repo_url =~ /gitlab/i RequestSources::GitLab elsif repo_url =~ /bitbucket\.(org|com)/i RequestSources::BitbucketCloud end end

Still without any luck:

+ bundle exec danger
Could not set up API to Code Review site for Danger

For your GitHub repo, you need to expose: DANGER_GITHUB_API_TOKEN
You may also need: DANGER_GITHUB_HOST, DANGER_GITHUB_API_BASE_URL

Found these keys in your ENV: DANGER_GITHUB_API_TOKEN.....