Skip to content

Commit

Permalink
#426 Implemented new feature ProjectService::getProjectComponents() t… (
Browse files Browse the repository at this point in the history
#427)

* #426 Implemented new feature ProjectService::getProjectComponents() to extract the Components defined in a Jira Project. Updated README.md with an example.

* #426 Added a trailing dot to the ProjectService::getProjectComponents() method Description to be StyleCI compliant.

Co-authored-by: enrico.degaudenzi <[email protected]>
  • Loading branch information
edegaudenzi and enrico.degaudenzi authored May 7, 2022
1 parent 19e7d2f commit 889091e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ $iss = new IssueService(new ArrayConfiguration(
- [Delete Project](#delete-project)
- [Get Project Info](#get-project-info)
- [Get All Project list](#get-all-project-list)
- [Get Project Components](#get-project-components)
- [Get Project Type](#get-project-type)
- [Get Project Version](#get-project-version)
Expand Down Expand Up @@ -377,6 +378,32 @@ try {
```
#### Get Project Components
[See Jira API reference (Get project components)](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#project-getProjectComponents)
```php
<?php
require 'vendor/autoload.php';
use JiraRestApi\Project\ProjectService;
use JiraRestApi\JiraException;
try {
$proj = new ProjectService();
$prjs = $proj->getAllProjects();
// Extract and show Project Components for every Jira Project
foreach ($prjs as $p) {
var_export($proj->getProjectComponents($p->id));
}
} catch (JiraRestApi\JiraException $e) {
print("Error Occured! " . $e->getMessage());
}
```
#### Get Project type
[See Jira API reference (get all types)](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/project/type-getAllProjectTypes)
Expand Down
21 changes: 21 additions & 0 deletions src/Project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JiraRestApi\Project;

use JiraRestApi\Component\Component;
use JiraRestApi\Issue\IssueType;
use JiraRestApi\Issue\Reporter;
use JiraRestApi\Issue\Version;
Expand Down Expand Up @@ -97,6 +98,26 @@ public function getStatuses($projectIdOrKey)
return $results;
}

/**
* Get the Components defined in a Jira Project.
*
* @param string|int $projectIdOrKey
*
* @throws \JiraRestApi\JiraException
*
* @return \JiraRestApi\Component\Component[]
*/
public function getProjectComponents($projectIdOrKey)
{
$ret = $this->exec($this->uri."/$projectIdOrKey/components", null);
$json = json_decode($ret);
$results = array_map(function ($elem) {
return $this->json_mapper->map($elem, new Component());
}, $json);

return $results;
}

/**
* make transition info array for project issue transition.
*
Expand Down

0 comments on commit 889091e

Please sign in to comment.