通过Ruby验证Jira并通过ZAPI(Zephyr API)发布更改
我正在尝试做什么:我尝试通过Ruby验证Jira,然后更改Zephyr(带有Z(ephyr)API的Jira插件)问题
我试图执行此代码(取自:http://docs.getzephyr.apiary.io/#executionresourceapis)
require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest_client'
values = "{\n \"issueId\": 10600,\n \"versionId\": \"10000\",\n \"cycleId\": \"16\",\n \"projectId\": 10000\n}"
headers = {:content_type => "application/json"}
response = RestClient.post "http://getzephyr.apiary-mock.com/jira_server/rest/zapi/latest/execution", values, headers
puts response
我的主要问题是我无法通过Ruby验证我的Jira实例。我的尝试包括(无数其他人):
A)我认为这有效(即使这有效,我也不认为它会为我的使用而工作b / c我需要传递其他值来改变Jira / Zephyr门票):
curl -D- -u fyousuf:password -X GET -H Content-Type: application/json http://jira.test.local/rest/zapi/latest/execution
(通过https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication尝试卷曲)
A)输出:
curl: (6) Could not resolve host: application; nodename nor servname provided, or not known
HTTP/1.1 200 OK
Server: nginx/1.0.11
Date: Wed, 06 Aug 2014 20:14:35 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-AREQUESTID: 974x1935522x1
Set-Cookie: JSESSIONID=5F5D8411206C9B99054CABAD93AAE715; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=A8NH-S9GW-2ZYX-9R4V|a6024d3cb5c5585d2b6f765001ebfefa67dd5a7a|lin; Path=/
X-ASESSIONID: 1x3gunc
X-AUSERNAME: fyousuf
Cache-Control: no-cache, no-store, no-transform
{"status":{"1":{"id":1,"color":"#75B000","description":"Test was executed and passed successfully.","name":"PASS"},"2":{"id":2,"color":"#CC3300","description":"Test was executed and failed.","name":"FAIL"},"3":{"id":3,"color":"#F2B000","description":"Test execution is a work-in-progress.","name":"WIP"},"4":{"id":4,"color":"#6693B0","description":"The test execution of this test was blocked for some reason.","name":"BLOCKED"},"-1":{"id":-1,"color":"#A0A0A0","description":"The test has not yet been executed.","name":"UNEXECUTED"}},"executions":[],"currentlySelectedExecutionId":""}
B)这不起作用:
values = "{\n \"issueId\": 32640,\n \"versionId\": \"11163\",\n \"cycleId\": \"5\",\n \"projectId\": 10460\n,\n \"status\": \"1\"}"
headers = {:content_type => "application/json"}
auth = 'Basic ' + Base64.encode64( 'fyousuf:password' ).chomp
url = 'http://jira.test.local/rest/zapi/latest/execution'
resource = RestClient::Resource.new( url )
response = resource.post( :Authorization => auth )
#response = resource.post "http://jira.test.local/rest/zapi/latest/execution", values, headers
puts response
puts response.code
B)输出:
{"errorDesc":"You do not have the permission to make this request. Login Required.","errorId":"ERROR"}
200
我想,如果我能够通过“卷曲”来验证Jira。然后通过Ruby也应该工作,但不确定我做错了什么......
答案 0 :(得分:0)
从Ruby访问Jira的API我使用以下构造。 net / http对象完成工作。为了清楚起见,我从示例中删除了错误处理和日志记录。
require 'net/http'
require 'json'
http = Net::HTTP.new(host, port)
resp = nil
http.start do |http|
req = Net::HTTP::Post.new(api call + parameter)
req.add_field('Content-Type', 'application/json') if "POST" == req.method
req.add_field('Accept', 'application/json')
# we make an HTTP basic auth by passing the
# username and password
req.basic_auth username, password
resp = http.request(req)
end
return resp.body