Danger: Danger Failure Deleting Old Comments on BitBucket Cloud

Created on 10 Apr 2020  路  4Comments  路  Source: danger/danger

Report

In the past couple of days we started seeing CI failures from danger due to this error:
Error fetching json for: https://api.bitbucket.org/2.0/users/***************, status code: 404

From the tiny amount of poking around I did, it seems like this method in bitbucket_cloud_api.rb is getting a 404 because the username path parameter has been deprecated due to privacy changes in the BitBucket API.

In the mean time I was able to downgrade my danger version to v6.2.0, which seems to be working fine on the CI.

What did you do?

Ran bundle exec danger --danger_id=linter

What did you expect to happen?

I expected danger to run normally and comment on our BitBucket Cloud PRs.

What happened instead?

Command failed and reported this error:

bundler: failed to load command: danger (/Library/Ruby/Gems/2.6.0/bin/danger)
RuntimeError: Error fetching json for: https://api.bitbucket.org/2.0/users/***************, status code: 404
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud_api.rb:125:in `fetch_json'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud_api.rb:35:in `my_uuid'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud.rb:119:in `block in delete_old_comments'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud.rb:118:in `each'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud.rb:118:in `delete_old_comments'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/request_sources/bitbucket_cloud.rb:72:in `update_pull_request!'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/danger_core/dangerfile.rb:256:in `post_results'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/danger_core/dangerfile.rb:284:in `run'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/danger_core/executor.rb:29:in `run'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/lib/danger/commands/runner.rb:73:in `run'
  /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
  /Users/distiller/.bundle/ruby/2.6.0/danger-7da261774d02/bin/danger:5:in `<top (required)>'
  /Library/Ruby/Gems/2.6.0/bin/danger:23:in `load'
  /Library/Ruby/Gems/2.6.0/bin/danger:23:in `<top (required)>'

Your Environment

  • Which CI are you running on?

    • Circle CI

  • Are you running the latest version of Danger?

    • I was seeing errors on the latest version, so I downgraded

  • What is your Dangerfile?
###############################################################################
# PR is a work in progress and shouldn't be merged yet
###############################################################################
warn "PR is classed as Work in Progress" if bitbucket_cloud.pr_title.include? "WIP"

###############################################################################
# Warn when there is a big PR
###############################################################################
warn "Big PR, consider splitting into smaller" if git.lines_of_code > 5000

###############################################################################
# Ensure a clean commits history
###############################################################################
if git.commits.any? { |c| c.message =~ /^Merge branch '#{bitbucket_cloud.branch_for_base}'/ || c.message =~ /^Merge commit/ }
  fail "Please rebase to get rid of the merge commits in this PR"
end


###############################################################################
# Mainly to encourage writing up some reasoning about the PR, rather than
# just leaving a title
###############################################################################
if bitbucket_cloud.pr_body.length < 5
  fail "Please provide a summary in the Pull Request description"
end

###############################################################################
# If these are all empty something has gone wrong, better to raise it in a comment
###############################################################################
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
  fail "This PR has no changes at all, this is likely an issue during development."
end

has_app_changes = !git.modified_files.grep(/App/).empty? || !git.added_files.grep(/App/).empty?
has_test_changes = !git.modified_files.grep(/Test/).empty? || !git.added_files.grep(/Test/).empty?

###############################################################################
# If changes are more than 10 lines of code, tests need to be updated too
###############################################################################
if has_app_changes && !has_test_changes && git.lines_of_code > 10
  fail("Tests were not updated", sticky: false)
end


###############################################################################
# Notify about Dependencies Update
###############################################################################
podfile_updated = !git.modified_files.grep(/Podfile/).empty?
cartfile_update = !git.modified_files.grep(/Cartfile/).empty?

if podfile_updated || cartfile_update
  message "Dependencies updated, please check all downstream usages of updated dependencies"
end

###############################################################################
# Check that a JIRA issue is associated with this PR
###############################################################################
jira.check(
  key: ["IOS"],
  url: "https://[redacted].atlassian.net/browse",
  search_title: false,
  search_commits: true,
  fail_on_warning: false,
  report_missing: true,
  skippable: true,
  emoji: ""
)


###############################################################################
# Check if this PR Conflicts with any other open prs
###############################################################################
# conflict_checker.check_conflict_and_comment

###############################################################################
# Warn if any todo messages were left in the code
###############################################################################
# todoist.warn_for_todos

###############################################################################
# Discourage new Objective-C Files
###############################################################################

added_objective_c = !git.added_files.grep(/m$/).empty?

if added_objective_c
  warn "New Objective-C files are discouraged, new development should be in Swift."
end

###############################################################################
# Formatting Rule Checks
###############################################################################
swiftformat.check_format(fail_on_error: true)

###############################################################################
# Lint swift code. Find our config at .swiftlint.yml
###############################################################################
swiftlint.lint_all_files = true
swiftlint.lint_files fail_on_error:true
# swiftlint.lint_files inline_mode:true -- not yet supported by bitbucket cloud. Someday, perhaps

Most helpful comment

^^ As you can see, I have a branch.

I'll be dogfooding this at work now to check I've not broken anything, since I don't have the largest amount of faith in danger's specs around bitbucket.

All 4 comments

I faced this issue too! Downgraded to version 6.2.0 and is working fine now. thanks @oct0f1sh

Probably should be handled like it is for danger-js: https://github.com/danger/danger-js/blob/master/source/platforms/bitbucket_cloud/BitBucketCloudAPI.ts#L39
-> UUID must be set as environment variable

Yeah, absolutely should be according to those docs.
I'll get a PR in later today probably, assuming there isn't already one.

^^ As you can see, I have a branch.

I'll be dogfooding this at work now to check I've not broken anything, since I don't have the largest amount of faith in danger's specs around bitbucket.

Was this page helpful?
0 / 5 - 0 ratings