Skip to content

Commit a4df067

Browse files
authored
Merge branch 'master' into master
2 parents 18f6b3b + 5618a7e commit a4df067

File tree

8 files changed

+354
-38
lines changed

8 files changed

+354
-38
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ screen_capture.png
2626
bug-description.pdf
2727

2828
.env
29+
30+
# Ignore Vagrant Stuff
31+
.vagrant
32+
Vagrantfile
33+
# Ignore scotch.io box and the folders of them
34+
public/

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ $iss = new IssueService(new ArrayConfiguration(
9191
### Project
9292
- [Get Project Info](#get-project-info)
9393
- [Get All Project list](#get-all-project-list)
94+
- [Get Project Type](#get-project-type)
9495

9596
### Custom Field
9697
- [Get All Field list](#get-all-field-list)
@@ -103,6 +104,8 @@ $iss = new IssueService(new ArrayConfiguration(
103104
- [Create Sub Task](#create-sub-task)
104105
- [Add Attachment](#add-attachment)
105106
- [Update issue](#update-issue)
107+
- [Change assignee](#change-assignee)
108+
- [Remove issue](#remove-issue)
106109
- [Add comment](#add-comment)
107110
- [Perform a transition on an issue](#perform-a-transition-on-an-issue)
108111
- [Perform an advanced search, using the JQL](#perform-an-advanced-search)
@@ -160,6 +163,36 @@ try {
160163

161164
```
162165

166+
#### Get Project type
167+
168+
```php
169+
<?php
170+
require 'vendor/autoload.php';
171+
172+
use JiraRestApi\Project\ProjectService;
173+
use JiraRestApi\Project\ProjectType;
174+
use JiraRestApi\JiraException;
175+
176+
try {
177+
$proj = new ProjectService();
178+
179+
// get all project type
180+
$prjtyps = $proj->getProjectTypes();
181+
182+
foreach ($prjtyps as $pt) {
183+
var_dump($pt);
184+
}
185+
186+
// get specific project type.
187+
$pt = $proj->getProjectType('software');
188+
var_dump($pt);
189+
190+
} catch (JiraException $e) {
191+
print("Error Occured! " . $e->getMessage());
192+
}
193+
194+
```
195+
163196
#### Get All Field List
164197

165198
```php
@@ -451,9 +484,15 @@ try {
451484
->setDescription("This is a shorthand for a set operation on the summary field")
452485
;
453486

487+
// optionally set some query params
488+
$editParams = array(
489+
'notifyUsers' => false
490+
);
491+
454492
$issueService = new IssueService();
455493

456-
$ret = $issueService->update($issueKey, $issueField);
494+
// You can set the $paramArray param to disable notifications in example
495+
$ret = $issueService->update($issueKey, $issueField, $editParams);
457496

458497
var_dump($ret);
459498
} catch (JiraException $e) {
@@ -463,6 +502,56 @@ try {
463502

464503
If you want to change the custom field type when updating an issue, you can call the *addCustomField* function just as you did for creating issue.
465504

505+
#### Change Assignee
506+
507+
```php
508+
<?php
509+
require 'vendor/autoload.php';
510+
511+
use JiraRestApi\Issue\IssueService;
512+
use JiraRestApi\JiraException;
513+
514+
$issueKey = "TEST-879";
515+
516+
try {
517+
$issueService = new IssueService();
518+
519+
// if assignee is -1, automatic assignee used.
520+
// A null assignee will remove the assignee.
521+
$assignee = 'newAssigneeName';
522+
523+
$ret = $issueService->changeAssignee($issueKey, $assignee);
524+
525+
var_dump($ret);
526+
} catch (JiraException $e) {
527+
$this->assertTrue(FALSE, "Change Assignee Failed : " . $e->getMessage());
528+
}
529+
```
530+
531+
#### Remove Issue
532+
533+
```php
534+
<?php
535+
require 'vendor/autoload.php';
536+
537+
use JiraRestApi\Issue\IssueService;
538+
use JiraRestApi\JiraException;
539+
540+
$issueKey = "TEST-879";
541+
542+
try {
543+
$issueService = new IssueService();
544+
545+
$ret = $issueService->deleteIssue($issueKey);
546+
// if you want to delete issues with sub-tasks
547+
//$ret = $issueService->deleteIssue($issueKey, array('deleteSubtasks' => 'true'));
548+
549+
var_dump($ret);
550+
} catch (JiraException $e) {
551+
$this->assertTrue(FALSE, "Change Assignee Failed : " . $e->getMessage());
552+
}
553+
```
554+
466555
#### Add comment
467556

468557
```php

src/Issue/IssueService.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ private function bulkInsert($issues)
127127
*/
128128
public function addAttachments($issueIdOrKey, $filePathArray)
129129
{
130+
if (is_array($filePathArray) == false) {
131+
$filePathArray = [$filePathArray];
132+
}
133+
130134
$results = $this->upload($this->uri."/$issueIdOrKey/attachments", $filePathArray);
131135

132136
$this->log->addInfo('addAttachments result='.var_export($results, true));
@@ -155,10 +159,11 @@ public function addAttachments($issueIdOrKey, $filePathArray)
155159
*
156160
* @param $issueIdOrKey Issue Key
157161
* @param $issueField object of Issue class
162+
* @param array $paramArray Query Parameter key-value Array.
158163
*
159164
* @return created issue key
160165
*/
161-
public function update($issueIdOrKey, $issueField)
166+
public function update($issueIdOrKey, $issueField, $paramArray = [])
162167
{
163168
$issue = new Issue();
164169

@@ -171,7 +176,9 @@ public function update($issueIdOrKey, $issueField)
171176

172177
$this->log->addInfo("Update Issue=\n".$data);
173178

174-
$ret = $this->exec($this->uri."/$issueIdOrKey", $data, 'PUT');
179+
$queryParam = '?'.http_build_query($paramArray);
180+
181+
$ret = $this->exec($this->uri."/$issueIdOrKey".$queryParam, $data, 'PUT');
175182

176183
return $ret;
177184
}
@@ -200,6 +207,53 @@ public function addComment($issueIdOrKey, $comment)
200207
return $comment;
201208
}
202209

210+
/**
211+
* Change a issue assignee
212+
*
213+
* @param Issue $issueIdOrKey
214+
* @param Assigns $assigneeName Assigns an issue to a user.
215+
* If the assigneeName is "-1" automatic assignee is used.
216+
* A null name will remove the assignee.
217+
* @return true | false
218+
* @throws JiraException
219+
*
220+
*/
221+
public function changeAssignee($issueIdOrKey, $assigneeName)
222+
{
223+
$this->log->addInfo("changeAssignee=\n");
224+
225+
$ar = ['name' => $assigneeName];
226+
227+
$data = json_encode($ar);
228+
229+
$ret = $this->exec($this->uri."/$issueIdOrKey/assignee", $data, 'PUT');
230+
231+
$this->log->addInfo('change assignee of '.$issueIdOrKey.' to ' . $assigneeName .' result='.var_export($ret, true));
232+
233+
return $ret;
234+
}
235+
236+
/**
237+
* Delete a issue.
238+
*
239+
* @param issueIdOrKey Issue id or key
240+
* @param array $paramArray Query Parameter key-value Array.
241+
* @return true | false
242+
*
243+
*/
244+
public function deleteIssue($issueIdOrKey, $paramArray = [])
245+
{
246+
$this->log->addInfo("deleteIssue=\n");
247+
248+
$queryParam = '?'.http_build_query($paramArray);
249+
250+
$ret = $this->exec($this->uri."/$issueIdOrKey".$queryParam, '', 'DELETE');
251+
252+
$this->log->addInfo('delete issue '.$issueIdOrKey.' result='.var_export($ret, true));
253+
254+
return $ret;
255+
}
256+
203257
/**
204258
* Get a list of the transitions possible for this issue by the current user, along with fields that are required and their types.
205259
*

src/JiraClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function exec($context, $post_data = null, $custom_request = null)
193193

194194
//The server successfully processed the request, but is not returning any content.
195195
if ($this->http_response == 204) {
196-
return '';
196+
return true;
197197
}
198198

199199
// HostNotFound, No route to Host, etc Network error

src/Project/ProjectService.php

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace JiraRestApi\Project;
44

5-
use JiraRestApi\Issue\Reporter;
65
use JiraRestApi\Issue\IssueType;
6+
use JiraRestApi\Issue\Reporter;
77

88
class ProjectService extends \JiraRestApi\JiraClient
99
{
@@ -19,7 +19,7 @@ public function getAllProjects()
1919
$ret = $this->exec($this->uri, null);
2020

2121
$prjs = $this->json_mapper->mapArray(
22-
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Project\Project'
22+
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Project\Project'
2323
);
2424

2525
return $prjs;
@@ -36,12 +36,12 @@ public function getAllProjects()
3636
*/
3737
public function get($projectIdOrKey)
3838
{
39-
$ret = $this->exec($this->uri."/$projectIdOrKey", null);
39+
$ret = $this->exec($this->uri . "/$projectIdOrKey", null);
4040

41-
$this->log->addInfo('Result='.$ret);
41+
$this->log->addInfo('Result=' . $ret);
4242

4343
$prj = $this->json_mapper->map(
44-
json_decode($ret), new Project()
44+
json_decode($ret), new Project()
4545
);
4646

4747
return $prj;
@@ -69,12 +69,63 @@ public function getAssignable($projectIdOrKey)
6969

7070
public function getStatuses($projectIdOrKey)
7171
{
72-
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null);
72+
$ret = $this->exec($this->uri . "/$projectIdOrKey/statuses", null);
7373
$json = json_decode($ret);
7474
$results = array_map(function ($elem) {
7575
return $this->json_mapper->map($elem, new IssueType());
7676
}, $json);
7777

7878
return $results;
7979
}
80+
81+
/**
82+
* @return ProjectType[]
83+
*/
84+
public function getProjectTypes()
85+
{
86+
$ret = $this->exec($this->uri . "/type");
87+
88+
$this->log->addInfo('Result=' . $ret);
89+
90+
$json = json_decode($ret);
91+
$results = array_map(function ($elem) {
92+
return $this->json_mapper->map($elem, new ProjectType());
93+
}, $json);
94+
95+
return $results;
96+
}
97+
98+
/**
99+
* @param string|int $key
100+
* @return ProjectType
101+
*/
102+
public function getProjectType($key)
103+
{
104+
$ret = $this->exec($this->uri . "/type/$key");
105+
106+
$this->log->addInfo('Result=' . $ret);
107+
108+
$type = $this->json_mapper->map(
109+
json_decode($ret, false), new ProjectType()
110+
);
111+
112+
return $type;
113+
}
114+
115+
/**
116+
* @param string|int $key
117+
* @return ProjectType
118+
*/
119+
public function getAccessibleProjectType($key)
120+
{
121+
$ret = $this->exec($this->uri . "/type/$key/accessible");
122+
123+
$this->log->addInfo('Result=' . $ret);
124+
125+
$type = $this->json_mapper->map(
126+
json_decode($ret, false), new ProjectType()
127+
);
128+
129+
return $type;
130+
}
80131
}

src/Project/ProjectType.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace JiraRestApi\Project;
3+
4+
use JiraRestApi\ClassSerialize;
5+
6+
class ProjectType
7+
{
8+
use ClassSerialize;
9+
10+
/** @var string */
11+
public $key;
12+
13+
/** @var string */
14+
public $formattedKey;
15+
16+
/** @var string */
17+
public $descriptionI18nKey;
18+
19+
/** @var string */
20+
public $icon;
21+
22+
/** @var string */
23+
public $color;
24+
25+
}

0 commit comments

Comments
 (0)