Skip to content

Commit 0f72305

Browse files
committed
issue class
1 parent ad3749b commit 0f72305

File tree

7 files changed

+154
-19
lines changed

7 files changed

+154
-19
lines changed

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<directory>tests/</directory>
88
-->
99
<file>tests/ProjectTest.php</file>
10+
<file>tests/IssueTest.php</file>
1011
</testsuite>
1112
</testsuites>
1213

src/JiraClient.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct($config, $options = null)
9090
$this->http_response = 200;
9191
}
9292

93-
public function exec($context, $post_data = null) {
93+
public function exec($context, $post_data = null, $custom_request = null) {
9494
$url = $this->host . $this->api_uri . '/' . preg_replace('/\//', '', $context, 1);
9595

9696
$this->log->addDebug("Curl $url JsonData=" . $post_data);
@@ -101,10 +101,20 @@ public function exec($context, $post_data = null) {
101101

102102
// post_data
103103
if (!is_null($post_data)) {
104-
curl_setopt($ch, CURLOPT_POST, true);
105-
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
104+
// PUT REQUEST
105+
if (!is_null($custom_request) && $custom_request == "PUT") {
106+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
107+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
108+
}
109+
if (!is_null($custom_request) && $custom_request == "DELETE") {
110+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
111+
}
112+
else {
113+
curl_setopt($ch, CURLOPT_POST, true);
114+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
115+
}
106116
}
107-
117+
108118
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
109119

110120
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->options[CURLOPT_SSL_VERIFYHOST]);

src/issue/Issue.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
class Issue {
6+
/**
7+
* return only if Project query by key(not id)
8+
* @var string
9+
*/
10+
public $expand;
11+
12+
/* @var string */
13+
public $self;
14+
15+
/* @var string */
16+
public $id;
17+
18+
/* @var string */
19+
public $key;
20+
21+
/* @var \JiraRestApi\Issue\IssueField */
22+
public $fields;
23+
24+
}
25+
26+
?>

src/issue/IssueField.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
4+
namespace JiraRestApi\Issue;
5+
6+
class IssueField {
7+
8+
}
9+
10+
?>

src/issue/IssueService.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
require 'vendor/autoload.php';
6+
7+
class IssueService extends \JiraRestApi\JiraClient {
8+
private $uri = "/issue";
9+
10+
public function __construct($config, $opt_array = null) {
11+
parent::__construct($config, $opt_array);
12+
}
13+
14+
/**
15+
* get all project list
16+
*
17+
* @return Issue class
18+
*/
19+
public function get($issueIdOrKey) {
20+
$ret = $this->exec("$this->uri/$issueIdOrKey", null);
21+
22+
$this->log->addInfo("Result=\n" . $ret );
23+
24+
$issue = $this->json_mapper->map(
25+
json_decode($ret), new Issue()
26+
);
27+
28+
return $issue;
29+
}
30+
31+
/**
32+
* create new issue
33+
*
34+
* @param $issue object of Issue class
35+
*
36+
* @return created issue key
37+
*/
38+
public function create($issue) {
39+
$ret = $this->exec($this->uri, null);
40+
41+
$this->log->addInfo("Result=\n" . $ret );
42+
43+
$prj = $this->json_mapper->map(
44+
json_decode($ret), new Project()
45+
);
46+
47+
return $prj;
48+
}
49+
}
50+
51+
?>
52+

src/project/ProjectService.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,8 @@
55
require 'vendor/autoload.php';
66

77
class ProjectService extends \JiraRestApi\JiraClient {
8-
9-
/**
10-
* Project URI
11-
* @var string
12-
*/
13-
public $self;
14-
15-
/**
16-
* Project id
17-
* @var string
18-
*/
19-
public $id;
20-
218
private $uri = "/project";
9+
2210
public function __construct($config, $opt_array = null) {
2311
parent::__construct($config, $opt_array);
2412
}
@@ -29,7 +17,7 @@ public function __construct($config, $opt_array = null) {
2917
* @return array of Project class
3018
*/
3119
public function getAllProjects() {
32-
$ret = $this->exec('/project', null);
20+
$ret = $this->exec($this->uri, null);
3321

3422
$prjs = $this->json_mapper->mapArray(
3523
json_decode($ret, true), new \ArrayObject(), '\JiraRestApi\Project\Project'
@@ -39,7 +27,7 @@ public function getAllProjects() {
3927
}
4028

4129
public function get($projectIdOrKey) {
42-
$ret = $this->exec("/project/$projectIdOrKey", null);
30+
$ret = $this->exec("$this->uri/$projectIdOrKey", null);
4331

4432
$this->log->addInfo("Result=" . $ret );
4533

tests/IssueTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
use JiraRestApi\Issue\IssueService;
4+
5+
class IssueTest extends PHPUnit_Framework_TestCase
6+
{
7+
public function testIssue()
8+
{
9+
//$this->markTestIncomplete();
10+
try {
11+
$issueService = new IssueService(getHostConfig(), getOptions());
12+
13+
$issue = $issueService->get('TEST-867');
14+
15+
print_r($issue->fields);
16+
/*
17+
foreach ($issue->components as $c) {
18+
echo ("COM : " . $c->name . "\n");
19+
}
20+
*/
21+
} catch (HTTPException $e) {
22+
$this->assertTrue(FALSE, $e->getMessage());
23+
}
24+
}
25+
26+
public function testCreateIssue()
27+
{
28+
$this->markTestIncomplete();
29+
try {
30+
$issueService = new IssueService(getHostConfig(), getOptions());
31+
32+
$issue = $issueService->getAllProjects();
33+
34+
$i = 0;
35+
foreach ($issue as $p) {
36+
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
37+
$p->key, $p->id, $p->name, $p->projectCategory['name']
38+
);
39+
40+
}
41+
} catch (HTTPException $e) {
42+
$this->assertTrue(FALSE, $e->getMessage());
43+
}
44+
}
45+
//
46+
}
47+
48+
?>

0 commit comments

Comments
 (0)