Skip to content
Permalink
Browse files

feature: refactoring - #0008712: User Contribution - kaiten integration

  • Loading branch information...
fmancardi committed Jul 2, 2019
1 parent cd7e4f2 commit 6da5dffd65f3c5248a62a4508f5988aa52e61c70
Showing with 46 additions and 61 deletions.
  1. +12 −0 lib/functions/exec.inc.php
  2. +34 −61 lib/issuetrackerintegration/kaitenrestInterface.class.php
@@ -686,9 +686,14 @@ function addIssue($dbHandler,$argsObj,$itsObj,$opt=null) {
}
}
$opt->execContext = $issueText->execContext;
$opt->execSignature = $issueText->execSignature;
// Management of Dynamic Values From XML Configuration
// (@20180120 only works for redmine)
$opt->tagValue = $issueText->tagValue;
$rs = $itsObj->addIssue($issueText->summary,$issueText->description,$opt);
@@ -788,6 +793,13 @@ function generateIssueText($dbHandler,$argsObj,$itsObj,$opt=null) {
$exec['build_name'],$exec['execution_ts'],
$exec['statusVerbose']);
$ret->execContext = array('testplan_name' => $exec['testplan_name'],
'platform_name' => $platform_identity,
'build_name' => $exec['build_name']);
$ret->execSignature = array('id' => $argsObj->exec_id,
'timestamp' => $exec['execution_ts'],
'status' => $exec['statusVerbose']);
if(property_exists($argsObj, 'bug_notes')) {
$lblKeys = array('issue_exec_id','issue_tester','issue_tplan','issue_build',
@@ -3,13 +3,13 @@
* TestLink Open Source Project - http://testlink.sourceforge.net/
*
* @filesource kaitenrestInterface.class.php
* @author Francisco Mancardi
* @author
*
*
**/
require_once(TL_ABS_PATH . "/third_party/kaiten-php-api/lib/kaiten-rest-api.php");
class kaitenrestInterface extends issueTrackerInterface
{
class kaitenrestInterface extends issueTrackerInterface {
private $APIClient;
private $options = [];
private $conditionMap = [
@@ -54,14 +54,11 @@ function __construct($type,$config,$name) {
/**
*
**/
function completeCfg()
{
$this->cfg->uribase = trim($this->cfg->uribase,"/"); // be sure no / at end
if( property_exists($this->cfg,'options') )
{
function completeCfg() {
$this->cfg->uribase = trim($this->cfg->uribase,"/");
if( property_exists($this->cfg,'options') ) {
$option = get_object_vars($this->cfg->options);
foreach ($option as $name => $elem)
{
foreach ($option as $name => $elem) {
$name = (string)$name;
$this->options[$name] = (string)$elem;
}
@@ -73,8 +70,7 @@ function completeCfg()
*
*
**/
function getAPIClient()
{
function getAPIClient() {
return $this->APIClient;
}
@@ -85,8 +81,7 @@ function getAPIClient()
*
* @return bool returns true if the bugid has the right format, false else
**/
function checkBugIDSyntax($issueID)
{
function checkBugIDSyntax($issueID) {
return $this->checkBugIDSyntaxNumeric($issueID);
}
@@ -96,17 +91,14 @@ function checkBugIDSyntax($issueID)
* @return bool
*
**/
function connect()
{
function connect() {
$processCatch = false;
try
{
try {
// CRITIC NOTICE for developers
// $this->cfg is a simpleXML Object, then seems very conservative and safe
// to cast properties BEFORE using it.
$url = (string)trim($this->cfg->uribase);
// $apiKey = (string)trim($this->cfg->apikey);
$login = (string)trim($this->cfg->login);
$password = (string)trim($this->cfg->password);
$boardId = (string)trim($this->cfg->boardid);
@@ -116,27 +108,22 @@ function connect()
$pxy->proxy = config_get('proxy');
$this->APIClient = new kaiten($url,$login,$password,$boardId,$options,$pxy);
// to undestand if connection is OK, I will ask for users.
try
{
try {
$items = $this->APIClient->getUsers();
$this->connected = count($items) > 0 ? true : false;
unset($items);
}
catch(Exception $e)
{
catch(Exception $e) {
$processCatch = true;
}
}
catch(Exception $e)
{
catch(Exception $e) {
$processCatch = true;
}
if($processCatch)
{
if($processCatch) {
$logDetails = '';
foreach(['uribase','login'] as $v)
{
foreach(['uribase','login'] as $v) {
$logDetails .= "$v={$this->cfg->$v} / ";
}
$logDetails = trim($logDetails,'/ ');
@@ -149,39 +136,33 @@ function connect()
*
*
**/
function isConnected()
{
function isConnected() {
return $this->connected;
}
/**
*
*
**/
function buildViewBugURL($issueID)
{
function buildViewBugURL($issueID) {
return $this->APIClient->getIssueURL($issueID);
}
/**
*
*
**/
public function getIssue($issueID)
{
if (!$this->isConnected())
{
public function getIssue($issueID) {
if (!$this->isConnected()) {
tLog(__METHOD__ . '/Not Connected ', 'ERROR');
return false;
}
$issue = null;
try
{
try {
$jsonObj = $this->APIClient->getIssue($issueID);
if( !is_null($jsonObj) && is_object($jsonObj))
{
if( !is_null($jsonObj) && is_object($jsonObj)) {
$conditionData = isset($this->conditionMap[$jsonObj->condition]) ? ' / '.$this->conditionMap[$jsonObj->condition] : '';
$issue = new stdClass();
$issue->IDHTMLString = "<b>{$issueID} : </b>";
@@ -192,8 +173,7 @@ public function getIssue($issueID)
$issue->isResolved = (int)$jsonObj->state == 3;
}
}
catch(Exception $e)
{
catch(Exception $e) {
tLog(__METHOD__ . '/' . $e->getMessage(),'ERROR');
$issue = null;
}
@@ -208,8 +188,7 @@ public function getIssue($issueID)
*
* @return
**/
function getIssueStatusCode($issueID)
{
function getIssueStatusCode($issueID) {
$issue = $this->getIssue($issueID);
return !is_null($issue) ? $issue->state : false;
}
@@ -222,8 +201,7 @@ function getIssueStatusCode($issueID)
* @return string
*
**/
function getIssueStatusVerbose($issueID)
{
function getIssueStatusVerbose($issueID) {
$state = $this->getIssueStatusCode($issueID);
if ($state) {
return $this->resolvedStatus->byCode[$state];
@@ -238,8 +216,7 @@ function getIssueStatusVerbose($issueID)
* @return string
*
**/
function getIssueSummaryHTMLString($issueID)
{
function getIssueSummaryHTMLString($issueID) {
$issue = $this->getIssue($issueID);
return $issue->summaryHTMLString;
}
@@ -249,10 +226,8 @@ function getIssueSummaryHTMLString($issueID)
*
* @return bool true if issue exists on BTS
**/
function checkBugIDExistence($issueID)
{
if(($status_ok = $this->checkBugIDSyntax($issueID)))
{
function checkBugIDExistence($issueID) {
if(($status_ok = $this->checkBugIDSyntax($issueID))) {
$issue = $this->getIssue($issueID);
$status_ok = is_object($issue) && !is_null($issue);
}
@@ -297,12 +272,11 @@ public function addIssue($summary,$description,$opt=null) {
$tags = null;
if (!empty($opt)) {
$tags = [
['name' => $opt->tagValue->value[2]], // plan
['name' => $opt->tagValue->value[4]] // build
['name' => $opt->execContext['testplan_name']],
['name' => $opt->execContext['build_name']]
];
}
try
{
try {
$op = $this->APIClient->addIssue($summary, $descriptionData['description']);
if(is_null($op)){
throw new Exception("Error creating issue", 1);
@@ -316,11 +290,10 @@ public function addIssue($summary,$description,$opt=null) {
}
$ret = ['status_ok' => true, 'id' => (string)$op->id,
'msg' => sprintf(lang_get('kaiten_bug_created'),
$summary, (string)$op->board_id)];
'msg' => sprintf(lang_get('kaiten_bug_created'),
$summary, (string)$op->board_id)];
}
catch (Exception $e)
{
catch (Exception $e) {
$msg = "Create KAITEN Card FAILURE => " . $e->getMessage();
tLog($msg, 'WARNING');
$ret = ['status_ok' => false, 'id' => -1, 'msg' => $msg];

0 comments on commit 6da5dff

Please sign in to comment.
You can’t perform that action at this time.