Skip to content

Commit

Permalink
Merge branch 'getCreateIssueMetadata'
Browse files Browse the repository at this point in the history
  • Loading branch information
fmancardi committed Dec 25, 2016
1 parent c94ec8e commit 5c68f04
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 2 deletions.
50 changes: 50 additions & 0 deletions examples/getCreateIssueMetadata.test.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* TestLink Open Source Project - http://testlink.sourceforge.net/
*
* @filesource getCreateIssueMetadata.test.class.php
* @author Francisco Mancardi ([email protected])
*
* @internal revisions
*
**/
require_once('../src/JiraApi/RestRequest.php');
require_once('../src/JiraApi/Jira.php');

$settings = array('host' => 'https://testlink.atlassian.net/rest/api/latest/',
'username' => 'testlink.forum', 'password' => 'forum');

$api = new JiraApi\Jira($settings);

/*
$out = $api->getCreateIssueMetadata();
echo 'Test - Get Create Issue Metadata for all projects' . '<br>';
echo '<pre>';
var_dump($out);
echo '</pre>';
*/

$tg = 'ZOFF';
$out = $api->getCreateIssueMetadata($tg);
echo 'Test - Get Create Issue Metadata for project: ' . $tg . '<br>';
echo '<pre>';
var_dump($out);
echo '</pre>';

/*
$tg = 'ZOFF,SCRUM20NOV';
$out = $api->getCreateIssueMetadata($tg);
echo 'Test - Get Create Issue Metadata for projects: ' . $tg . '<br>';
echo '<pre>';
var_dump($out);
echo '</pre>';
$tg = 'ZOFF,SCRUM20NOV';
$out = $api->getCreateIssueFields($tg);
echo 'Test - Get Create Issue Fields for project: ' . $tg . '<br>';
echo '<pre>';
var_dump($out);
echo '</pre>';
*/
102 changes: 100 additions & 2 deletions src/JiraApi/Jira.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public function testLogin()
}

/**
*
* https://docs.atlassian.com/jira/REST/latest/#api/2/user-getUser
*/
public function getUser($username)
{
$this->request->openConnect($this->host . 'user/search/?username=' . $username, 'GET');
$this->request->openConnect($this->host . 'user/?username=' . $username, 'GET');
$this->request->execute();
$user = json_decode($this->request->getResponseBody());

Expand Down Expand Up @@ -265,4 +265,102 @@ public function getIssue($issueKey)

return $item;
}

/**
* return a map where main key is projectkey (if call has returned infor
* for this key)
* Each element is an map with issueTypeID as key, and each element inside
* this map has to elements with two keys:
* - issueTypeName
* - fields => array with field names
*
* Here a partial example for project with key ZOFF
* array(1) {
* ["ZOFF"]=>
* array(7) {
* [1]=>
* array(2) {
* ["issueTypeName"]=> "Bug"
* ["fields"]=> array(21) {
* ["summary"] => "summary"
* ["reporter"] => "reporter"
*/
public function getCreateIssueFields($projectKeys=null)
{
$opt = 'expand=projects.issuetypes.fields';
$items = $this->getCreateIssueMetadata($projectKeys,$opt);
$ret = null;
if(!is_null($items) && count($items->projects) > 0)
{
$ro = &$items->projects;
foreach($ro as $ele)
{
$ret[$ele->key] = array();
$rx = &$ele->issuetypes;
foreach($rx as $it)
{
$ret[$ele->key][$it->id]['issueTypeName'] = $it->name;
foreach($it->fields as $field)
{
$ret[$ele->key][$it->id]['fields'][$field->key] = $field->key;
}
}
}
//return $items->projects;
}
return $ret;
}



/**
* https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getCreateIssueMeta
*
* https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/
* jira-rest-api-tutorials/jira-rest-api-example-discovering-meta-data-for-creating-issues
*
*
* curl -D- -u fred:fred -X GET -H "Content-Type: application/json" \
* http://kelpie9:8081/rest/api/2/issue/createmeta
*
* curl -D- -u fred:fred -X GET -H "Content-Type: application/json" \
* http://kelpie9:8081/rest/api/2/issue/createmeta?projectKeys=QA
*
* curl -D- -u fred:fred -X GET -H "Content-Type: application/json" \
* http://kelpie9:8081/rest/api/2/issue/createmeta?projectKeys=QA,XSS
*
* From Atlassian documentation
* projectKeys string
* lists the projects with which to filter the results.
* If absent, all projects are returned.
* This parameter can be comma-separated list.
* Specifiying a project that does not exist
* (or that you cannot create issues in) is not an error,
* but it will not be in the results.
*
* opt can contain issuetypeIds, issuetypeNames, expand=projects.issuetypes.fields.
* Fields will only be returned if expand=projects.issuetypes.fields.
*/
public function getCreateIssueMetadata($projectKeys=null,$opt=null)
{
$cmd = $this->host . 'issue/createmeta';
$ope = '?';
if( !is_null($projectKeys) )
{
$cmd .= $ope . 'projectKeys=' . $projectKeys;
$ope = '&';
}

if( !is_null($opt) )
{
$cmd .= $ope . $opt;
}

$this->request->openConnect($cmd, 'GET');
$this->request->execute();
$items = json_decode($this->request->getResponseBody());

return $items;
}

}

0 comments on commit 5c68f04

Please sign in to comment.