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

Fix Bitbucket pull request selection broken due to a different response #179

Merged

Conversation

konradstrack
Copy link

This pull request ensures correct PR selection based on Bitbucket's API, which in turn fixes submitting comments on Bitbucket PRs.

When run with the bitbucket_pr formatter: pronto run -f bitbucket_pr -r rubocop, pronto 0.7.1 fails with

/Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:68:in `block in pull': undefined method `[]' for nil:NilClass (NoMethodError)
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:68:in `each'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:68:in `find'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:68:in `pull'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:57:in `pull_id'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/bitbucket.rb:11:in `pull_comments'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/formatter/pull_request_formatter.rb:5:in `existing_comments'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/formatter/git_formatter.rb:7:in `format'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto.rb:59:in `block in run'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto.rb:58:in `each'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto.rb:58:in `run'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/cli.rb:54:in `block in run'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/cli.rb:53:in `chdir'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/lib/pronto/cli.rb:53:in `run'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/konradstrack/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/pronto-0.7.1/bin/pronto:6:in `<top (required)>'
    from /Users/konradstrack/.rbenv/versions/2.2.4/bin/pronto:23:in `load'
    from /Users/konradstrack/.rbenv/versions/2.2.4/bin/pronto:23:in `<main>'

The actual response from Bitbucket's API is different than the current implementation expects:

table:
  :description: ''
  :links:
    ...
  :destination:
    ...
  ...
  :source:
    commit:
      hash: 7b2e2948bf645
      links:
        self:
          href: https://api.bitbucket.org/2.0/repositories/AAA/BBB/commit/CCC
    repository:
      links:
        self:
          href: https://api.bitbucket.org/2.0/repositories/AAA/BBB
        html:
          href: https://bitbucket.org/AAA/BBB
        avatar:
          href: https://bitbucket.org/AAA/BBB/avatar/333/
      type: repository
      name: Bbb
      full_name: AAA/BBB
      uuid: "{aa2485b9-53e1-4978-882b-bf645094f734}"
    branch:
      name: feature/my-branch
  ...

even though it's not properly documented (https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D).

This change selects the correct source branch for comparison with @repo.branch.

@mmozuras mmozuras merged commit 924da5b into prontolabs:master Oct 2, 2016
@mmozuras
Copy link
Member

mmozuras commented Oct 2, 2016

@konradstrack thanks 🙇!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants