使用php和JIRA SOAP API添加注释以发布问题

时间:2012-08-19 04:29:39

标签: php jira

如何使用PHP和Jura的SOAP API为JIRA问题添加注释?我有连接并测试它检索现有问题,所有运行良好,但当我尝试addComment方法时,它返回:

  

致命错误:未捕获SoapFault异常:[soapenv:Server.userException] org.xml.sax.SAXException:错误类型(类java.util.HashMap - >类com.atlassian.jira.rpc.soap.beans。 RemoteComment)/home/a7348186/public_html/jira.php:46堆栈跟踪:
  #0 /home/a7348186/public_html/jira.php(46):SoapClient-> __ call(' addComment',Array)
  #1 /home/a7348186/public_html/jira.php(46):   SoapClient-> addComment(' 16VGN3ohoo',' NTP-> 29',数组)
  在第46行的/home/a7348186/public_html/jira.php中抛出#2 {main}

这是我的代码:

<?php
$emailplain = $_REQUEST['plain'];
$emailsubject = $_REQUEST['subject'];
$inputkey = $_REQUEST['key'];
$inputsumm = $_REQUEST['summ'];
$client = new SoapClient(NULL,
    array(
        "location" => "https://server.com/rpc/soap/jirasoapservice-v2?wsdl",
        "uri"      => "urn:xmethods-delayed-quotes",
        "style"    => SOAP_RPC,
        "use"      => SOAP_ENCODED
        ));
$token = $client->login("user", "pass");
$issueId = $inputkey;
$issue = $client->getIssue($token, $issueId);
echo("assignee:".$issue->assignee);
echo(" created:".$issue->created);
echo(" summary:".$issue->summary);
echo(" issueid:".$issue->key);
print $inputsumm;
$stringsummary = $issue->summary;

$string = $issue->summary;
$emailsubjectregexp = preg_replace('/[a-zA-Z]+/', '', $inputsumm);
$stringsumm = ('summary ~ "' . $emailsubjectregexp . '"');
$jqlstring = $stringsumm;

$searchjql = $client->getIssuesFromJqlSearch($token, $jqlstring, 100);
function printArray ($array, $devolver = false) {
    $stringa = '<pre>' . print_r($array, true) . '</pre>';
    if ($devolver) return $stringa;
    else echo $stringa;
}
printArray($searchjql);
print_r ($searchjql);
$key = $searchjql[0]->key;
echo $key;
$client->addComment($token, $key, array('body' => 'your comment'));
?>

如果您注意到,最后一行包含执行我想要的代码,但没有运气。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

更改创建Soap客户端对象的方式,更改:

$client = new SoapClient(NULL,
    array(
        "location" => "https://server.com/rpc/soap/jirasoapservice-v2?wsdl",
        "uri"      => "urn:xmethods-delayed-quotes",
        "style"    => SOAP_RPC,
        "use"      => SOAP_ENCODED
        ));

为:

$client = new SoapClient("https://jira.watchitoo.com/rpc/soap/jirasoapservice-v2?wsdl");

这应该有用。

完全添加评论代码:

$issueKey = "key-123";
$username= "JiraUser";
$password= "JiraPassword";
$jiraAddress = "https://your.jira.com/rpc/soap/jirasoapservice-v2?wsdl";
$myComment = "your comment";

$soapClient = new SoapClient($jiraAddress);
$token = $soapClient->login($username, $password);
$soapClient->addComment($token, $issueKey, array('body' => $myComment));
相关问题