Fix failure when response does not have nullable fields
These fields are nullable and may not necessarily be included in the response. When these fields are null, trying to access them via method results in a NoMethodError
, which causes the chatops pipeline to fail. Access them via hash-lookup instead in order to solve this case. To reproduce this bug, try using /chatops run namespace find 57955024
irb(main):001> require 'gitlab'
=> true
irb(main):003> Gitlab.private_token = ENV['TOKEN']
irb(main):004> Gitlab.endpoint = 'https://gitlab.com/api/v4'
irb(main):005> client = Gitlab::Client.new
=> #<Gitlab::Client:0x0000000100cea468 ...>
irb(main):013> resp = client.get("/namespaces/57955024")
=> #<Gitlab::ObjectifiedHash:385860 {hash: {"id"=>57955024, "name"=>"sec-sub-department", "path"=>"sec-sub-department", "kind"=>"group", "full_path"=>"gitlab-com/sec...
irb(main):014> resp.seats_in_use
/Users/bwilliams/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/gitlab-4.19.0/lib/gitlab/objectified_hash.rb:43:in `method_missing': undefined method `seats_in_use' for #<Gitlab::ObjectifiedHash:385860 {hash: {"id"=>57955024, "name"=>"sec-sub-department", "path"=>"sec-sub-department", "kind"=>"group", "full_path"=>"gitlab-com/sec-sub-department", "parent_id"=>6543, "avatar_url"=>nil, "web_url"=>"https://gitlab.com/groups/gitlab-com/sec-sub-department", "billable_members_count"=>2}} (NoMethodError)
from (irb):14:in `<main>'
from /Users/bwilliams/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/irb-1.10.1/exe/irb:9:in `<top (required)>'
from /Users/bwilliams/.asdf/installs/ruby/3.1.4/bin/irb:25:in `load'
from /Users/bwilliams/.asdf/installs/ruby/3.1.4/bin/irb:25:in `<main>'
irb(main):015> resp['seats_in_use']
=> nil
irb(main):016> client.get("/namespaces/9970")['seats_in_use']
=> 2358
Edited by Brian Williams