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

跟風遠走 提交于 2019-12-07 07:05:03

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23262558/how-to-change-transitions-to-a-issue-in-ruby-using-jira-ruby-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!