我有以下代码(来自jira-ruby-gem-api-doc)。它成功地更新了Jira中的"Comments",但没有更新customfield值。我确保json转储中自定义字段的名称是正确的。建议其他选择吗?
非常感谢您的帮助
output = File.new("jira_dump2.json","w+")
issue = client.Issue.find("DEV-XXXXX")
output.puts issue.to_json
#this throws no errors and does not work
issue.save({"fields"=>{"customfield_11530"=>"a0x40000000PHet"}})
#this following code works
comment = issue.comments.build
comment.save!(:body => "This is a comment added from REST API newer" )
一个好的开始是使用curl进行类似的调用:
curl -D- -u user:password -X PUT --data @request.txt -H "Content-Type: application/json" http://jira-server:port/rest/api/2/issue/DEV-XXXXX
(替换用户、密码、jira服务器和端口)
文件request.txt应该包含json请求:
{"fields":{"customfield_11530":"a0x40000000PHet"}}
然而,在我的案例中,jira-ruby-gem发出了一个不同的请求:它使用了一个类似于/rest/api/2/issue/22241的路径,导致了一个400 Bad request错误,其中包含正文消息
"Field 'customfield_11530' cannot be set. It is not on the appropriate screen, or unknown."
为了修复宝石,我在宝石的base.rb中更改了这些行
417 if @attrs['self']
418 @attrs['self'].sub(@client.options[:site],'')
419 elsif key_value
420 self.class.singular_path(client, key_value.to_s, prefix)
到此:
417 if key_value
418 self.class.singular_path(client, key_value.to_s, prefix)
419 elsif @attrs['self']
420 @attrs['self'].sub(@client.options[:site],'')
(在我的机器上,位于"/usr/local/lib/ruby/gems/2.0.0/gems/jira-ruby-0.1.2/lib/jira"中)
成功了。希望它也适用于你。在这里,您可以在维护人员的JIRA系统中检查问题的状态:http://jira.sumoheavylabs.com/browse/JR-3。
如果你想在你的代码中获得更多的错误信息,可以这样做:
begin
issue.save!( updateHash )
rescue JIRA::HTTPError => e
puts e.response.code
puts e.response.message
puts e.response.body
end