Search code examples
ruby-on-railsrubyrubygemsjirajira-rest-api

Problem creating Issue with jira-ruby Gem


I am testing out using jira-ruby and creating an Issue in Jira. However, when I attempt to create an issue, I receive this error:

/Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/http_error.rb:11:in `initialize': undefined method `presence' for "":String (NoMethodError)

      @message = response.try(:message).presence || response.try(:body)
                                       ^^^^^^^^^
Did you mean?  presence_in
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/request_client.rb:13:in `exception'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/request_client.rb:13:in `raise'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/request_client.rb:13:in `request'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/client.rb:306:in `request'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/client.rb:289:in `post'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/base.rb:347:in `save!'
        from /Users/xxx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/jira-ruby-2.3.0/lib/jira/base.rb:361:in `save'
        from test.rb:23:in `<main>'

Not exactly sure what this means and I am not finding anything helpful researching online. I am able to connect to Jira and pull back issues, comments, etc.

Here is the code:

require 'jira-ruby'

api_token = 'xxxx'

options = {
  :site => 'https://jira3.com',
  :context_path => '',
  :default_headers => { 'Authorization' => "Bearer #{api_token}" },
  :auth_type => :basic
}

client = JIRA::Client.new(options)

issue = client.Issue.build
issue.save(
  'fields' => {
    'summary' => 'Test using Jira-ruby',
    'project' => { 'id' => '15112' },
    'issuetype' => { 'id' => '3' },
    'priority' => { 'id' => '3' },
    'components' => { 'id' => '85201' }
  }
)

Solution

  • This was a known issue in jira-ruby 2.3.0 (which is the one you're using) in case of HTTP errors and it is fixed in the latest release (3.0.0.beta1).

    Therefore, I believe you have 2 options to move forward:

    1. Update jira-ruby to 3.0.0.beta1

    or

    1. Add a similar fix as the one added by them:
    require 'jira-ruby'
    require 'active_support/core_ext/object'