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

Not possible to update an existing issue? #100

Closed
endymion opened this issue Feb 10, 2015 · 7 comments
Closed

Not possible to update an existing issue? #100

endymion opened this issue Feb 10, 2015 · 7 comments
Labels
Bug Broken functionality

Comments

@endymion
Copy link

I've spent about the last six hours trying to figure out how to use the JIRA API from Ruby, using this gem, to create, update, and comment on an issue in JIRA. Simple, right? NO. This gem is so poorly documented that it took hours just to log into our JIRA account with it because the secret of using :context => '' is not mentioned anywhere and I had to figure it out myself. Then I had to figure out how to find the IDs for projects and issue types by inspecting the HTML from atlassian.net and I was finally able to post an issue.

Updating an existing issue, however, is a complete mystery. I'm guessing that it will be like the other issues: that it will work if I can find some sample code somewhere. The sample code in the documentation for updating records absolutely does not work. Now I'm just throwing things against the wall to see if anything sticks. I seriously think that I would have been better off pulling out Capybara and writing a web bot to do this instead of trying to use this terrible API gem.

Here are a few examples of failed attempts to post an update to an existing issue. I get a 400 response and no error messages in the issue's data structure.

client = JIRA::Client.new(options)
issue = client.Issue.find('ENG-23')
begin
  issue.save!(
      {
        'fields' =>
          {
            'description' => 'This story was posted by a bot.'
          }      
      }
    )
rescue JIRA::HTTPError => e
  puts e.response.code
  puts e.response.message
  puts e.response.body  
end 

Result:

$ bundle exec ruby jira.rb 
400
Bad Request
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

That mirrors the structure used to create that same issue, with the fields nested under 'fields'. But obviously it doesn't work. And it provides absolutely no hint about why it didn't work.

Another attempt:

client = JIRA::Client.new(options)
issue = client.Issue.find('ENG-23')
begin
  issue.save!(
      {
        'description' => 'This story was posted by a bot.'
      }
    )
rescue JIRA::HTTPError => e
  puts e.response.code
  puts e.response.message
  puts e.response.body  
end 

Result:

$ bundle exec ruby jira.rb 
400
Bad Request
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

Another attempt:

client = JIRA::Client.new(options)
issue = client.Issue.find('ENG-23')
issue.set_attrs(
    {
      'fields'=>
        {
          'summary' => 'Hello, World!',
          'description' => 'This story was posted by a bot.',
          'project' => {'id' => 10207}, # ENG -- Engineering,
          'issuetype' => {'id' => 10206} # Story
        }
    }
  )
begin
  issue.save!({})
rescue JIRA::HTTPError => e
  puts e.response.code
  puts e.response.message
  puts e.response.body  
end 

Result:

$ bundle exec ruby jira.rb 
400
Bad Request
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

Another attempt:

client = JIRA::Client.new(options)
issue = client.Issue.find('ENG-23')
begin
  issue.save!(
      {
        'fields'=>
          {
            'summary' => 'Hello, World!',
            'description' => 'This story was posted by a bot.',
            'project' => {'id' => 10207}, # ENG -- Engineering,
            'issuetype' => {'id' => 10206} # Story
          }
      }
    )
rescue JIRA::HTTPError => e
  puts e.response.code
  puts e.response.message
  puts e.response.body  
end 

Same result.

The real issue here is that I'm an idiot for wasting so much of my time on trying to make this work when it's obviously never going to work. Is that correct? Or can this gem actually update issues in JIRA?

If this gem can't update issues in JIRA then why is it wasting space on GitHub?

@endymion
Copy link
Author

I should mention that I'm authenticating with HTTP Basic and that the API user has access to update the record, which I confirmed by logging in as that user and updating the record.

@andrewhavens
Copy link

@endymion I feel your pain. However, your disparaging comments are not productive. The maintainers of this gem volunteer their time to maintain a gem that someone else created, and are under no obligation to help you. I'm sure they don't appreciate your negative tone. If it's so bad, why don't you try using one of the 60 other JIRA gems.

I realize it's not mentioned in the README, but there are two files in the repo which list a lot of examples, including updating issues. Perhaps you did not see these examples?

I agree, the readme needs some improvement. However, docs aren't a replacement for getting your hands dirty and reading through the source code.

@legkvla
Copy link
Contributor

legkvla commented Jun 7, 2015

Good news, guys!
I have fixed it!

The issue was that sometimes url didn't have '/' prefix.

https://github.com/legkvla/jira-ruby/commits/master

legkvla@3508d06

@legkvla legkvla mentioned this issue Jun 7, 2015
@legkvla
Copy link
Contributor

legkvla commented Jun 7, 2015

Have created pull request for you, so you can better understand what's happened and how it could be fixed: #112

legkvla referenced this issue in intere/jira-ruby Jun 7, 2015
…ch that when the 'self' attribute exists, the prefix is added to the base of the url.
@omehegan
Copy link

#119 fixes this issue.

@scottysseus
Copy link

For what it's worth, I also noticed that the request was leaving the '/' off of the beginning of the URL (e.g. 'https:jira.example.comrest/api/2/blablabla' notice the lack of '/' between 'com' and 'rest'), and what fixed this for me was removing the '/' at the end of the host name I gave the Client object.

I changed

client = JIRA::Client.new(
  username: username,
  password: password,
  site: 'https://jira.example.com/', # notice the '/' at the end
  context_path: '', 
  auth_type: :basic)

to

client = JIRA::Client.new(
  username: username,
  password: password,
  site: 'https://jira.example.com', # the '/' has been removed
  context_path: '', 
  auth_type: :basic)

legkvla added a commit to legkvla/jira-ruby that referenced this issue Apr 15, 2016
legkvla added a commit to legkvla/jira-ruby that referenced this issue Apr 15, 2016
@legkvla
Copy link
Contributor

legkvla commented Apr 16, 2016

I found bug in my last fix I made last summer. Since issue is still open - I would like provide a pull request.
Also I found conditions when issue reproduced - for example, when you use Attlassian SDK and your jira instance installed not in root context but in /jira path instead.
If somebody experienced this issue - could you please test my PR too and confirm that it fixes issue. After it will be done - we can close the ticket.

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

No branches or pull requests

6 participants