hirakiuc / tinybucket

A Ruby client library for Bitbucket REST API v2 with OAuth Authentication.
MIT License
33 stars 36 forks source link

Please add support for Bitbucket Teams #128

Closed npadgen closed 7 years ago

npadgen commented 7 years ago

Please add support for Bitbucket Teams (https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams).

Our Bitbucket instance has lots of repos which we organise by Team. I would like to iterate through each project's repos for reports, e.g. number of open pull requests per team.

To do this I'd like to be able to:

hirakiuc commented 7 years ago

Please add support for Bitbucket Teams

Oh, I think that I forgot to implement part of teams API. 🙇

I try to implement the rest of teams API in next weekend. 💪

hirakiuc commented 7 years ago

I released version 1.5.0 😃

This version includes the features what you want.

bucket = Tinybucket.new

bucket.teams(role).each do |team|
  team.repos.each do |repo|
    # Do something with Tinybucket::Model::Repository
    puts repo.name
  end
end

And also you can iterate repositories by projects, like this. ✨

bucket = Tinybucket.new

bucket.teams(role).each do |team|
  team.projects.each do |project|
    project.repos.each do |repo|
      # Do something with Tinybucket::Model::Repository
      puts repo.name
    end
  end
end

Check the bitbucket document about role.

Please enjoy version 1.5.0. 👍

npadgen commented 7 years ago

Looks very good, but now I'm getting a problem iterating through repos.

  b.teams('admin').each do |team|
    team.projects.each do |project|
      next unless project.name == 'DevOps'
      project.repos.each do |repo|
        puts repo
      end
    end
  end

gives:

#<Tinybucket::Model::Repository:0x007fe051a9eb68>
#<Tinybucket::Model::Repository:0x007fe051a97bd8>
#<Tinybucket::Model::Repository:0x007fe051a8f208>
#<Tinybucket::Model::Repository:0x007fe051a8dc78>
#<Tinybucket::Model::Repository:0x007fe051a8c328>
#<Tinybucket::Model::Repository:0x007fe05320e848>
#<Tinybucket::Model::Repository:0x007fe053207408>
#<Tinybucket::Model::Repository:0x007fe0532044d8>
#<Tinybucket::Model::Repository:0x007fe0531fd1b0>
#<Tinybucket::Model::Repository:0x007fe05316a540>
ArgumentError: odd number of arguments for Hash
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/iterator.rb:72:in `[]'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/iterator.rb:72:in `next_params'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/iterator.rb:60:in `load_next'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/iterator.rb:46:in `next_value'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/iterator.rb:25:in `next'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/enumerator.rb:19:in `block (2 levels) in initialize'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/enumerator.rb:18:in `loop'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/enumerator.rb:18:in `block in initialize'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/resource/base.rb:14:in `each'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/resource/base.rb:14:in `each'
    from /Users/neilp/lib/gems/gems/tinybucket-1.5.0/lib/tinybucket/resource/base.rb:14:in `method_missing'
    from (irb):301
    from /usr/local/bin/irb:11:in `<main>'

There should be 71 repos listed for this project.

hirakiuc commented 7 years ago

Oh, Sorry about that. 🙇

I'll investigate.

npadgen commented 7 years ago

Seems to happen for every project with more than 10 repos. It throws the ArgumentError after the tenth repo.

hirakiuc commented 7 years ago

Thank you for your report 😃

Yes, it looks like a bug on iterating any resource with the specific query params. I'll fix that soon. 👍

hirakiuc commented 7 years ago

Please try with v1.5.1 which includes the bug fix about your problem. 😃

npadgen commented 7 years ago

It works perfectly! Thank you so much for this.