Skip to content

Commit 162a042

Browse files
committed
create issue
1 parent 94749da commit 162a042

File tree

7 files changed

+111
-75
lines changed

7 files changed

+111
-75
lines changed

src/JiraClient.php

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -143,65 +143,16 @@ public function exec($context, $post_data = null, $custom_request = null) {
143143
curl_close($ch);
144144

145145
// don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION
146-
if ($this->http_response != 200) {
146+
if ($this->http_response != 200 && $this->http_response != 201) {
147147
throw new HTTPException("CURL HTTP Request Failed: Status Code : "
148-
. $this->http_response . " URL:" . $url);
148+
. $this->http_response . " URL:" . $url
149+
. "\nError Message : " . $response);
149150
}
150151
}
151152

152153
return $response;
153154
}
154155

155-
function indent($json) {
156-
157-
$result = '';
158-
$pos = 0;
159-
$strLen = strlen($json);
160-
$indentStr = ' ';
161-
$newLine = "\n";
162-
$prevChar = '';
163-
$outOfQuotes = true;
164-
165-
for ($i=0; $i<=$strLen; $i++) {
166-
167-
// Grab the next character in the string.
168-
$char = substr($json, $i, 1);
169-
170-
// Are we inside a quoted string?
171-
if ($char == '"' && $prevChar != '\\') {
172-
$outOfQuotes = !$outOfQuotes;
173-
174-
// If this character is the end of an element,
175-
// output a new line and indent the next line.
176-
} else if(($char == '}' || $char == ']') && $outOfQuotes) {
177-
$result .= $newLine;
178-
$pos --;
179-
for ($j=0; $j<$pos; $j++) {
180-
$result .= $indentStr;
181-
}
182-
}
183-
184-
// Add the character to the result string.
185-
$result .= $char;
186-
187-
// If the last character was the beginning of an element,
188-
// output a new line and indent the next line.
189-
if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
190-
$result .= $newLine;
191-
if ($char == '{' || $char == '[') {
192-
$pos ++;
193-
}
194-
195-
for ($j = 0; $j < $pos; $j++) {
196-
$result .= $indentStr;
197-
}
198-
}
199-
200-
$prevChar = $char;
201-
}
202-
203-
return $result;
204-
}
205156
}
206157

207158

src/issue/IssueField.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,58 @@
55
class IssueField {
66
public function __construct() {
77
$this->project = new \JiraRestApi\Project\Project();
8-
$this->reporter = new \JiraRestApi\Issue\Reporter();
8+
99
$this->assignee = new \JiraRestApi\Issue\Reporter();
1010
$this->priority = new \JiraRestApi\Issue\Priority();
11+
$this->versions = array();
12+
13+
$this->issuetype = new \JiraRestApi\Issue\IssueType();
14+
}
15+
16+
public function setProjectName($name) {
17+
//$this->project->name = $name;
18+
$this->project->id = '12000';
19+
}
20+
public function setProjectId($id) {
21+
$this->project->id = $id;
22+
}
23+
24+
public function setIssueType($name) {
25+
$this->issuetype->name = $name;
26+
}
27+
28+
public function setSummary($summary) {
29+
$this->summary = $summary;
30+
}
31+
32+
public function setReporterName($name) {
33+
if (is_null($this->reporter))
34+
$this->reporter = new \JiraRestApi\Issue\Reporter();
35+
36+
$this->reporter->name = $name;
37+
}
38+
39+
public function setAssigneeName($name) {
40+
$this->assignee->name = $name;
41+
}
42+
43+
public function setPriorityName($name) {
44+
$this->priority->name = $name;
45+
}
46+
47+
public function setDescription($description) {
48+
$this->description = $description;
49+
}
50+
51+
public function addVersion($id, $name) {
52+
$v = new Version();
53+
54+
if (isset($id))
55+
$v->id = $id;
56+
if (isset($name))
57+
$v->name = $name;
58+
59+
array_push($this->versions, $v);
1160
}
1261

1362
/** @var string */
@@ -79,8 +128,8 @@ public function __construct() {
79128
/** @var Reporter */
80129
public $assignee;
81130

82-
/** @var string */
83-
public $versions;
131+
/* @var VersionList[\JiraRestApi\Issue\Version] */
132+
public $versions;
84133
}
85134

86135
?>

src/issue/IssueService.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public function get($issueIdOrKey) {
3737
*/
3838
public function create($issueField) {
3939
$issue = new Issue();
40-
$issue->fields = $issueField;
40+
41+
// serilize only not null field.
42+
$issue->fields = array_filter((array) $issueField, function ($val) {
43+
return !is_null($val);
44+
});
4145

4246
$data = json_encode($issue);
4347

@@ -48,7 +52,7 @@ public function create($issueField) {
4852
$issue = $this->json_mapper->map(
4953
json_decode($ret), new Issue()
5054
);
51-
55+
5256
return $issue;
5357
}
5458
}

src/issue/Version.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
class Version {
6+
/* @var string */
7+
public $self;
8+
9+
/* @var string */
10+
public $id;
11+
12+
/* @var string */
13+
public $description;
14+
15+
/* @var string */
16+
public $name;
17+
18+
/* @var bool */
19+
public $archived;
20+
21+
/* @var bool */
22+
public $released;
23+
24+
/* @var DateTime */
25+
public $releaseDate;
26+
}
27+
28+
?>

src/issue/issueType.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
namespace JiraRestApi\Issue;
44

5-
class IssueStatus {
5+
class IssueType {
66
/* @var string */
77
public $self;
88

9+
/* @var string */
10+
public $id;
11+
912
/* @var string */
1013
public $description;
1114

1215
/* @var string */
1316
public $iconUrl;
1417

1518
/* @var string */
16-
public $name;
17-
18-
/* @var string */
19-
public $id;
19+
public $name;
2020

21-
/* @var string */
22-
public $statusCategory;
21+
/* @var bool */
22+
public $subtask;
2323
}
2424

2525
?>

tests/IssueTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@ public function testCreateIssue()
3131
//$this->markTestIncomplete();
3232
try {
3333
$issueField = new IssueField();
34-
$issueField->project->name = "TEST";
35-
$issueField->summary = "something's wrong";
36-
$issueField->reporter->name = "smithers";
37-
$issueField->assignee->name = "homer";
38-
$issueField->priority->name = "Critical";
39-
$issueField->description = "Full description for issue";
40-
41-
//$issueService = new IssueService(getHostConfig(), getOptions());
34+
$issueField->setProjectName("TEST");
35+
$issueField->setSummary("something's wrong");
36+
//$issueField->setReporterName("smithers");
37+
$issueField->setAssigneeName("lesstif");
38+
$issueField->setPriorityName("Critical");
39+
$issueField->setIssueType("Bug");
40+
$issueField->setDescription("Full description for issue");
41+
42+
$issueField->addVersion(null, "1.0.1");
43+
$issueField->addVersion(null, "1.0.3");
44+
45+
$issueService = new IssueService(getHostConfig(), getOptions());
4246

43-
//$ret = $issueService->create($issueField);
47+
$ret = $issueService->create($issueField);
4448

45-
//print_r($ret);
49+
print_r($ret);
4650
} catch (HTTPException $e) {
4751
$this->assertTrue(FALSE, "Create Failed : " . $e->getMessage());
4852
}

tests/ProjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testGetProject()
2323

2424
public function testGetProjectLists()
2525
{
26-
$this->markTestIncomplete();
26+
//$this->markTestIncomplete();
2727
try {
2828
$proj = new ProjectService(getHostConfig(), getOptions());
2929

0 commit comments

Comments
 (0)