简体   繁体   English

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

[英]Add comment to issue using php and JIRA SOAP API

How do I add a comment to a JIRA Issue using PHP and Jura's SOAP API? 如何使用PHP和Jura的SOAP API在JIRA问题中添加评论? I have the connection and tested it retrieving an existing issue, all runs good, but when I try the addComment method it returns this: 我已连接并测试了该连接以检索一个现有问题,所有连接运行良好,但是当我尝试使用addComment方法时,它将返回以下内容:

Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] org.xml.sax.SAXException: Bad types (class java.util.HashMap -> class com.atlassian.jira.rpc.soap.beans.RemoteComment) in /home/a7348186/public_html/jira.php:46 Stack trace: 致命错误:未捕获的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) #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', Array) #1 /home/a7348186/public_html/jira.php(46):SoapClient-> addComment('16VGN3ohoo','NTP-> 29',Array)
#2 {main} thrown in /home/a7348186/public_html/jira.php on line 46 #2 {main}在第46行的/home/a7348186/public_html/jira.php中抛出

This is my code: 这是我的代码:

<?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'));
?>

If you notice, the last line contains the code to execute what I want, but with no luck. 如果您注意到,最后一行包含执行我想要的代码,但是没有运气。 Any ideas folks? 大家有什么想法吗?

Change the way you create the Soap client object, change : 更改创建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
        ));

to: 至:

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

This should work. 这应该工作。

Full add comment code: 全加注释代码:

$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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM