Skip to content

Commit e7240c0

Browse files
authored
Moved around everything (#104)
* Removed RepositoryProviderInterface and moved InMemoryRepositoryProvider to App\Service\Repository * Created a new "Api" namespace * Added abstractions: IssueApi, LabelApi and MilestoneApi * CS * Test fix * Moved around unit tests * typo
1 parent 8a39db5 commit e7240c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+279
-175
lines changed

config/services.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ services:
7171
Github\Api\Issue\Comments:
7272
factory: ['@Github\Api\Issue', comments]
7373

74-
App\Issues\StatusApi: '@App\Issues\GitHub\GitHubStatusApi'
75-
App\Issues\CommentsApiInterface: '@App\Issues\GitHub\GithubCommentsApi'
74+
App\Api\Issue\IssueApi: '@App\Api\Issue\GithubIssueApi'
75+
App\Api\Label\LabelApi: '@App\Api\Label\GithubLabelApi'
76+
App\Api\Milestone\MilestoneApi: '@App\Api\Milestone\GithubMilestoneApi'
77+
App\Api\Status\StatusApi: '@App\Api\Status\GitHubStatusApi'
7678

77-
App\Repository\Provider\InMemoryRepositoryProvider:
79+
App\Service\RepositoryProvider:
7880
arguments: [ '%repositories%' ]
7981

80-
App\Repository\Provider\RepositoryProviderInterface: '@App\Repository\Provider\InMemoryRepositoryProvider'
81-
8282
subscriber.symfony_docs.milestone:
8383
class: App\Subscriber\MilestoneNewPRSubscriber
8484
arguments:

config/services_test.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ services:
33
autowire: true
44
autoconfigure: true
55

6-
App\Issues\GitHub\CachedLabelsApi:
7-
class: App\Tests\Service\Issues\Github\FakedCachedLabelApi
8-
9-
App\Issues\StatusApi: '@App\Issues\NullStatusApi'
10-
App\Issues\CommentsApiInterface: '@App\Issues\NullCommentsApi'
6+
App\Api\Issue\IssueApi: '@App\Api\Issue\NullIssueApi'
7+
App\Api\Label\LabelApi: '@App\Api\Label\StaticLabelApi'
8+
App\Api\Milestone\MilestoneApi: '@App\Api\Milestone\StaticMilestoneApi'
9+
App\Api\Status\StatusApi: '@App\Api\Status\NullStatusApi'

src/Issues/GitHub/GithubCommentsApi.php renamed to src/Api/Issue/GithubIssueApi.php

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

3-
namespace App\Issues\GitHub;
3+
namespace App\Api\Issue;
44

5-
use App\Issues\CommentsApiInterface;
6-
use App\Repository\Repository;
5+
use App\Model\Repository;
76
use Github\Api\Issue\Comments;
87

9-
class GithubCommentsApi implements CommentsApiInterface
8+
class GithubIssueApi implements IssueApi
109
{
1110
private $issueCommentApi;
1211

@@ -18,7 +17,7 @@ public function __construct(Comments $issueCommentApi)
1817
/**
1918
* This will comment on both Issues and Pull Requests.
2019
*/
21-
public function commentOnIssue(Repository $repository, $issueNumber, $commentBody)
20+
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
2221
{
2322
$this->issueCommentApi->create(
2423
$repository->getVendor(),

src/Api/Issue/IssueApi.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Api\Issue;
4+
5+
use App\Model\Repository;
6+
7+
/**
8+
* Create, update, close or comment on issues. Not that "issue" also refers to a
9+
* pull request.
10+
*
11+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
12+
*/
13+
interface IssueApi
14+
{
15+
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody);
16+
}

src/Api/Issue/NullIssueApi.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace App\Api\Issue;
4+
5+
use App\Model\Repository;
6+
7+
class NullIssueApi implements IssueApi
8+
{
9+
public function commentOnIssue(Repository $repository, $issueNumber, string $commentBody)
10+
{
11+
}
12+
}

src/Issues/GitHub/CachedLabelsApi.php renamed to src/Api/Label/GithubLabelApi.php

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

3-
namespace App\Issues\GitHub;
3+
namespace App\Api\Label;
44

5-
use App\Repository\Repository;
5+
use App\Model\Repository;
66
use Github\Api\Issue\Labels;
77
use Symfony\Contracts\Cache\CacheInterface;
88
use Symfony\Contracts\Cache\ItemInterface;
99

1010
/**
1111
* @author Bernhard Schussek <bschussek@gmail.com>
1212
*/
13-
class CachedLabelsApi
13+
class GithubLabelApi implements LabelApi
1414
{
1515
/**
1616
* @var Labels
@@ -35,7 +35,7 @@ public function __construct(Labels $labelsApi, CacheInterface $cache)
3535
$this->cache = $cache;
3636
}
3737

38-
public function getIssueLabels($issueNumber, Repository $repository)
38+
public function getIssueLabels($issueNumber, Repository $repository): array
3939
{
4040
$key = $this->getCacheKey($issueNumber, $repository);
4141
if (!isset($this->labelCache[$key])) {
@@ -56,7 +56,7 @@ public function getIssueLabels($issueNumber, Repository $repository)
5656
return array_keys($this->labelCache[$key]);
5757
}
5858

59-
public function addIssueLabel($issueNumber, $label, Repository $repository)
59+
public function addIssueLabel($issueNumber, string $label, Repository $repository)
6060
{
6161
$key = $this->getCacheKey($issueNumber, $repository);
6262

@@ -77,7 +77,7 @@ public function addIssueLabel($issueNumber, $label, Repository $repository)
7777
}
7878
}
7979

80-
public function removeIssueLabel($issueNumber, $label, Repository $repository)
80+
public function removeIssueLabel($issueNumber, string $label, Repository $repository)
8181
{
8282
$key = $this->getCacheKey($issueNumber, $repository);
8383
if (isset($this->labelCache[$key]) && !isset($this->labelCache[$key][$label])) {

src/Api/Label/LabelApi.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Api\Label;
4+
5+
use App\Model\Repository;
6+
7+
/**
8+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
9+
*/
10+
interface LabelApi
11+
{
12+
public function getIssueLabels($issueNumber, Repository $repository): array;
13+
14+
public function addIssueLabel($issueNumber, string $label, Repository $repository);
15+
16+
public function removeIssueLabel($issueNumber, string $label, Repository $repository);
17+
18+
public function addIssueLabels($issueNumber, array $labels, Repository $repository);
19+
20+
/**
21+
* @return string[]
22+
*/
23+
public function getAllLabelsForRepository(Repository $repository): array;
24+
25+
/**
26+
* @return string[]
27+
*/
28+
public function getComponentLabelsForRepository(Repository $repository): array;
29+
}

src/Api/Label/NullLabelApi.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Api\Label;
6+
7+
use App\Model\Repository;
8+
9+
class NullLabelApi implements LabelApi
10+
{
11+
public function getIssueLabels($issueNumber, Repository $repository): array
12+
{
13+
return [];
14+
}
15+
16+
public function addIssueLabel($issueNumber, string $label, Repository $repository)
17+
{
18+
}
19+
20+
public function removeIssueLabel($issueNumber, string $label, Repository $repository)
21+
{
22+
}
23+
24+
public function addIssueLabels($issueNumber, array $labels, Repository $repository)
25+
{
26+
}
27+
28+
public function getAllLabelsForRepository(Repository $repository): array
29+
{
30+
return [];
31+
}
32+
33+
public function getComponentLabelsForRepository(Repository $repository): array
34+
{
35+
return [];
36+
}
37+
}

tests/Service/Issues/Github/FakedCachedLabelApi.php renamed to src/Api/Label/StaticLabelApi.php

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

3-
declare(strict_types=1);
3+
namespace App\Api\Label;
44

5-
namespace App\Tests\Service\Issues\Github;
5+
use App\Model\Repository;
66

7-
use App\Issues\GitHub\CachedLabelsApi;
8-
use App\Repository\Repository;
9-
10-
class FakedCachedLabelApi extends CachedLabelsApi
7+
/**
8+
* Dont fetch data from external source.
9+
*
10+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
11+
*/
12+
class StaticLabelApi extends NullLabelApi
1113
{
1214
public function getComponentLabelsForRepository(Repository $repository): array
1315
{
@@ -42,4 +44,9 @@ public function getAllLabelsForRepository(Repository $repository): array
4244

4345
return $labels;
4446
}
47+
48+
public function getIssueLabels($issueNumber, Repository $repository): array
49+
{
50+
return [];
51+
}
4552
}

src/Issues/GitHub/MilestonesApi.php renamed to src/Api/Milestone/GithubMilestoneApi.php

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

3-
namespace App\Issues\GitHub;
3+
namespace App\Api\Milestone;
44

5-
use App\Repository\Repository;
5+
use App\Model\Repository;
66
use Github\Api\Issue;
77
use Github\Api\Issue\Milestones;
88

99
/**
1010
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1111
*/
12-
class MilestonesApi
12+
class GithubMilestoneApi implements MilestoneApi
1313
{
1414
/**
1515
* @var Milestones
@@ -32,7 +32,7 @@ public function __construct(Milestones $milestonesApi, Issue $issuesApi)
3232
$this->issuesApi = $issuesApi;
3333
}
3434

35-
private function getMilestones(Repository $repository)
35+
private function getMilestones(Repository $repository): array
3636
{
3737
$key = $this->getCacheKey($repository);
3838
if (!isset($this->cache[$key])) {
@@ -66,10 +66,7 @@ public function updateMilestone(Repository $repository, int $issueNumber, string
6666
]);
6767
}
6868

69-
/**
70-
* @return bool
71-
*/
72-
public function exists(Repository $repository, string $milestoneName)
69+
public function exists(Repository $repository, string $milestoneName): bool
7370
{
7471
foreach ($this->getMilestones($repository) as $milestone) {
7572
if ($milestone['title'] === $milestoneName) {

0 commit comments

Comments
 (0)