Skip to content

Commit 3e16b61

Browse files
Laravel 9 (#3)
* Update composer.json * Laravel 9 Migration * Laravel 9 Migration * Fix things * Fix things * Fix things * Fix things * Update composer.json * Fix things * Fix things * Update README.md * Update README.md * Update README.md * Update README.md * Fix things * Fix things
1 parent 0c80c67 commit 3e16b61

File tree

9 files changed

+110
-81
lines changed

9 files changed

+110
-81
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
# laravel-jira
22
Easily access the Jira-API in your Laravel Application
3+
4+
## Configuration via .env
5+
6+
```
7+
JIRAAPI_V3_HOST="https://xxxxxxx.atlassian.net"
8+
JIRAAPI_V3_USER="[email protected]"
9+
JIRAAPI_V3_PERSONAL_ACCESS_TOKEN='Generated in your Jiras personal settings'
10+
```
11+
12+
## Usage
13+
14+
```php
15+
$jira = app(Jira::class);
16+
17+
$jira->users()->get();
18+
$jira->projectVersions('PROJECT_KEY');
19+
```

composer.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"license": "MIT",
99
"type": "project",
1010
"require": {
11-
"php": ">=7.2.5",
12-
"laravel/framework": "^6.0|^7.0|^8.0",
13-
"lesstif/php-jira-rest-client": "^2.5",
14-
"khill/php-duration": "^1.0"
11+
"php": "^8.2",
12+
"laravel/framework": "^9.0",
13+
"lesstif/jira-cloud-restapi": "^1.4",
14+
"khill/php-duration": "^1.1"
1515
},
1616
"autoload": {
1717
"psr-4": {
@@ -27,10 +27,7 @@
2727
"laravel": {
2828
"providers": [
2929
"LaravelJira\\JiraServiceProvider"
30-
],
31-
"aliases": {
32-
"Jira": "LaravelJira\\JiraFacade"
33-
}
30+
]
3431
}
3532
}
3633
}

config/jira.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
return [
4-
'url' => env('JIRA_HOST'),
5-
'username' => env('JIRA_USER'),
6-
'password' => env('JIRA_PASS'),
4+
'host' => env('JIRAAPI_V3_HOST'),
5+
'user' => env('JIRAAPI_V3_USER'),
6+
'accesstoken' => env('JIRAAPI_V3_PERSONAL_ACCESS_TOKEN'),
77
];

src/Jira.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ class Jira
88
use Services\Project;
99
use Services\User;
1010

11-
private $url;
12-
private $username;
13-
private $password;
14-
15-
public function __construct($url, $username, $password)
16-
{
17-
$this->url = $url;
18-
$this->username = $username;
19-
$this->password = $password;
11+
public function __construct(
12+
public string $url,
13+
public string $user,
14+
public string $accessToken
15+
) {
2016
}
2117
}

src/JiraFacade.php

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

77
class JiraFacade extends Facade
88
{
9-
protected static function getFacadeAccessor()
9+
protected static function getFacadeAccessor(): string
1010
{
11-
return 'jira';
11+
return Jira::class;
1212
}
1313
}

src/JiraServiceProvider.php

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

33
namespace LaravelJira;
44

5+
use Illuminate\Foundation\Application;
56
use Illuminate\Support\ServiceProvider;
7+
use RuntimeException;
68

79
class JiraServiceProvider extends ServiceProvider
810
{
@@ -12,8 +14,22 @@ public function boot()
1214
__DIR__.'/../config/jira.php' => config_path('jira.php'),
1315
]);
1416

15-
$this->app->singleton(Jira::class, function ($app) {
16-
return new Jira(...array_values(config('jira')));
17+
$this->app->singleton(Jira::class, function (Application $app) {
18+
$configuration = config('jira');
19+
20+
if (!$configuration['host']) {
21+
throw new RuntimeException('No Jira host specified');
22+
}
23+
24+
if (!$configuration['user']) {
25+
throw new RuntimeException('No Jira user specified');
26+
}
27+
28+
if (!$configuration['accesstoken']) {
29+
throw new RuntimeException('No Jira Access token specified');
30+
}
31+
32+
return new Jira($configuration['host'], $configuration['user'], $configuration['accesstoken']);
1733
});
1834
}
1935

src/Responses/Versions.php

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace LaravelJira\Responses;
44

5+
use ArrayObject;
56
use Carbon\Carbon;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\Facades\Log;
8-
use JiraRestApi\Issue\IssueService;
9-
use JiraRestApi\Issue\Version;
9+
use JiraCloud\Issue\IssueService;
10+
use JiraCloud\Issue\Version;
1011
use Khill\Duration\Duration;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213

@@ -21,23 +22,21 @@
2122
*/
2223
class Versions
2324
{
24-
public $versions;
25-
2625
/** @var Collection */
27-
private $filteredVersions;
26+
private Collection $filteredVersions;
2827

29-
public function __construct($versions)
30-
{
31-
$this->versions = $versions;
28+
public function __construct(
29+
public ArrayObject $versions
30+
) {
3231
$this->filteredVersions = collect($versions);
3332
}
3433

35-
public function get()
34+
public function get(): Collection
3635
{
3736
return $this->filteredVersions;
3837
}
3938

40-
public function orderByReleaseDate()
39+
public function orderByReleaseDate(): static
4140
{
4241
$this->filteredVersions = $this->filteredVersions->sort(function (Version $versionA, Version $versionB) {
4342
if (!$versionA->releaseDate) {
@@ -57,61 +56,91 @@ public function orderByReleaseDate()
5756
return $this;
5857
}
5958

60-
public function released()
59+
public function released(): static
6160
{
6261
$this->filterVersions(true, null, null);
6362

6463
return $this;
6564
}
6665

67-
public function unreleased()
66+
private function filterVersions($released, $archived, $overdue): static
67+
{
68+
$this->filteredVersions = $this->filteredVersions->reject(function (Version $version) use (
69+
$released,
70+
$archived,
71+
$overdue
72+
) {
73+
if (!is_null($released) && $version->released != $released) {
74+
return true;
75+
}
76+
77+
if (!is_null($archived) && $version->archived != $archived) {
78+
return true;
79+
}
80+
81+
if (!is_null($overdue) && $version->overdue != $overdue) {
82+
return true;
83+
}
84+
85+
// if (!$version->releaseDate) {
86+
// return true;
87+
// }
88+
//
89+
// return Carbon::now()->gt(Carbon::instance($version->releaseDate));
90+
return false;
91+
});
92+
93+
return $this;
94+
}
95+
96+
public function unreleased(): static
6897
{
6998
$this->filterVersions(false, null, null);
7099

71100
return $this;
72101
}
73102

74-
public function archived()
103+
public function archived(): static
75104
{
76105
$this->filterVersions(null, true, null);
77106

78107
return $this;
79108
}
80109

81-
public function unarchived()
110+
public function unarchived(): static
82111
{
83112
$this->filterVersions(null, false, null);
84113

85114
return $this;
86115
}
87116

88-
public function overdue()
117+
public function overdue(): static
89118
{
90119
$this->filterVersions(null, true, true);
91120

92121
return $this;
93122
}
94123

95-
public function notOverdue()
124+
public function notOverdue(): static
96125
{
97126
$this->filterVersions(null, false, false);
98127

99128
return $this;
100129
}
101130

102-
public function withTicketInformation(int $verbosityLevel = OutputInterface::VERBOSITY_NORMAL)
131+
public function withTicketInformation(int $verbosityLevel = OutputInterface::VERBOSITY_NORMAL): static
103132
{
104-
$issueService = new IssueService();
133+
$this->filteredVersions->transform(function ($version) use ($verbosityLevel) {
134+
$issueService = new IssueService();
105135

106-
$this->filteredVersions->transform(function ($version) use ($issueService, $verbosityLevel) {
107136
if ($verbosityLevel >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
108137
if ($version->archived) {
109-
Log::debug("- Skipping ticket informations for milestone {$version->name} #$version->id");
138+
Log::debug("- Skipping ticket informations for milestone $version->name #$version->id");
110139

111140
return $version;
112141
}
113142

114-
Log::debug("- Updating milestone {$version->name} #$version->id");
143+
Log::debug("- Updating milestone $version->name #$version->id");
115144
}
116145

117146
$searchResult = $issueService->search('fixVersion = '.$version->id, 0, 500);
@@ -164,8 +193,8 @@ public function withTicketInformation(int $verbosityLevel = OutputInterface::VER
164193
] : null,
165194
'created' => $issue->fields->created ? Carbon::instance($issue->fields->created) : null,
166195
'updated' => $issue->fields->updated ? Carbon::instance($issue->fields->updated) : null,
167-
'description' => $issue->fields->description,
168-
'priority' => $issue->fields->priority ? $issue->fields->priority->name : null,
196+
'description' => $issue->fields->description ?? null,
197+
'priority' => $issue->fields->priority?->name,
169198
'assignee' => $issue->fields->assignee ? [
170199
'id' => $issue->fields->assignee->accountId,
171200
'display_name' => $issue->fields->assignee->displayName,
@@ -197,31 +226,4 @@ public function withTicketInformation(int $verbosityLevel = OutputInterface::VER
197226

198227
return $this;
199228
}
200-
201-
private function filterVersions($released, $archived, $overdue)
202-
{
203-
$this->filteredVersions = $this->filteredVersions->reject(function (Version $version) use (
204-
$released,
205-
$archived,
206-
$overdue
207-
) {
208-
if (!is_null($released) && $version->released != $released) {
209-
return true;
210-
}
211-
212-
if (!is_null($archived) && $version->archived != $archived) {
213-
return true;
214-
}
215-
216-
if (!is_null($overdue) && $version->overdue != $overdue) {
217-
return true;
218-
}
219-
220-
// if (!$version->releaseDate) {
221-
// return true;
222-
// }
223-
//
224-
// return Carbon::now()->gt(Carbon::instance($version->releaseDate));
225-
});
226-
}
227229
}

src/Services/Project.php

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

33
namespace LaravelJira\Services;
44

5-
use JiraRestApi\Project\ProjectService;
5+
use JiraCloud\Project\ProjectService;
66
use LaravelJira\Responses\Versions;
77

88
trait Project
@@ -12,7 +12,7 @@ trait Project
1212
*
1313
* @return Versions
1414
*/
15-
public function projectVersions($projectName)
15+
public function projectVersions($projectName): Versions
1616
{
1717
$proj = new ProjectService();
1818

src/Services/User.php

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

33
namespace LaravelJira\Services;
44

5-
use JiraRestApi\Project\ProjectService;
6-
use JiraRestApi\User\UserService;
5+
use JiraCloud\User\UserService;
76
use LaravelJira\Responses\Users;
8-
use LaravelJira\Responses\Versions;
97

108
trait User
119
{
1210
/**
1311
* @return Users
1412
*/
15-
public function users()
13+
public function users(): Users
1614
{
1715
$userService = new UserService();
1816

19-
return new Users($userService->getUsers([
17+
return new Users(users: $userService->findUsers([
18+
'accountId' => '.', // get all users.
2019
'startAt' => 0,
2120
'maxResults' => 1000,
21+
'includeInactive' => false,
22+
//'property' => '*',
2223
]));
2324
}
2425
}

0 commit comments

Comments
 (0)