Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change transitions to a issue in ruby, using jira-ruby gem?

I'm trying to access jira in ruby with the Jira-ruby gem (https://rubygems.org/gems/jira-ruby), but i can't find how to change the transitions. I can only change it using the REST-api?

There is a Transition class (http://rubydoc.info/gems/jira-ruby/0.1.8/JIRA/Resource/Transition), but i don't know how to deal with it.

like image 342
edwise Avatar asked Apr 24 '14 07:04

edwise


1 Answers

The REST API docs say that you POST to /issue/{issueIdOrKey}/transitions to transition an issue from one status to another.

First fetch the available transitions for an issue:

client = JIRA::Client.new( ... )
issue = client.Issue.find("PROJECT-123")
available_transitions = client.Transition.all(:issue => issue)
available_transitions.each {|ea| puts "#{ea.name} (id #{ea.id})" }

Now you have the names and ids of possible transitions. Store the id of the transition you want to make. Then use it to save a new transition for the issue:

transition_id = ...
transition = issue.transitions.build
transition.save!("transition" => {"id" => transition_id})

I had to check the docs a few times to understand the expected payload was for the POST transition call and then fiddle with the Ruby client syntax to get that payload. Using a tool like net-http-spy made it easier.

like image 50
Ryan Avatar answered Oct 10 '22 00:10

Ryan