1

Ruby 経由で Jira に認証し、ZAPI (Zephyr API) 経由で変更を投稿する

私がやろうとしていること: Ruby 経由で Jira に認証してから、Zephyr (Jira プラグイン w/Z(ephyr)API) の問題に変更を加えようとしています。

このコードを実行しようとしています ( 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) これは機能すると思います(これは機能しますが、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 を試しました)

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

「curl」を使用して Jira に認証できれば、Ruby 経由でも機能するはずですが、何が間違っているのかわかりません...

4

1 に答える 1