1

通过 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尝试卷曲)

一)输出:

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

我在想,如果我能够使用“curl”向 Jira 进行身份验证,那么通过 Ruby 也应该可以工作,但不确定我做错了什么......

4

1 回答 1

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
于 2014-09-02T08:19:40.877 回答