1

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' }
  }
)
0

1 Answer 1

0

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 (as suggested by keegangroth in the github issue linked above):
require 'jira-ruby'
require 'active_support/core_ext/object'

Context: As noted by Ghoti in the comments, the presence method, which is called within the jira-ruby gem's class HTTPError, is provided by Active Support Core Extensions (see the docs here). That's why loading the extensions is needed to fix the issue.

Sign up to request clarification or add additional context in comments.

2 Comments

presence is a Rails extension, so what this fix does is include the Rails extensions, fwiw.
Good call, thanks for pointing this out, I'll update the answer to include this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.