Skip to content

Commit 550be1d

Browse files
Added the ability to pass multiple repository names
1 parent 94ca3a1 commit 550be1d

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ notifications read laravel --token {...}
4848
In addition to the organization, you can also specify the full or partial name of the repository. For example:
4949

5050
```Bash
51-
notifications read some/name
51+
notifications read laravel/framework
5252
# or
53-
notifications read some/na
53+
notifications read laravel/fra
5454
# or
55-
notifications read so
55+
notifications read la
5656
```
5757

58-
При определении имени используется функция [`str_starts_with`](https://www.php.net/manual/en/function.str-starts-with).
58+
You can also specify several names:
59+
60+
```Bash
61+
notifications read laravel/framework laravel/jet
62+
```
63+
64+
When determining the name, the [`str_starts_with`](https://www.php.net/manual/en/function.str-starts-with) function is used.
5965

6066
### Options
6167

app/Commands/ReadCommand.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class ReadCommand extends Command
1414
{
1515
protected $signature = 'read'
16-
. ' {repository? : Full or partial repository name}'
16+
. ' {repository?* : Full or partial repository names}'
1717
. ' {--i|without-issues : Exclude issues from processing}'
1818
. ' {--s|without-pulls : Exclude Pull Requests from processing}'
1919
. ' {--o|with-open : Process including open Issues and Pull Requests}'
@@ -23,42 +23,49 @@ class ReadCommand extends Command
2323

2424
public function handle(): void
2525
{
26-
$repository = $this->repository();
26+
$repositories = $this->repositories();
2727

28-
$this->welcome($repository);
28+
$this->welcome($repositories);
2929

3030
if ($this->hasContinue()) {
31-
$this->read($repository);
31+
$this->read($repositories);
3232
}
3333
}
3434

35-
protected function welcome(?string $repository): void
35+
protected function welcome(array $repositories): void
3636
{
37-
$this->show($repository ?: 'All Notifications');
37+
if ($repositories) {
38+
$this->components->info('You specified the following repository name masks:');
39+
$this->components->bulletList($repositories);
40+
41+
return;
42+
}
43+
44+
$this->components->info('All Notifications');
3845
}
3946

4047
protected function hasContinue(): bool
4148
{
4249
return confirm('Continue');
4350
}
4451

45-
protected function read(?string $repository): void
52+
protected function read(array $repositories): void
4653
{
4754
$this->gitHub()
48-
->repository($repository)
55+
->repositories($repositories)
4956
->withoutIssues($this->withoutIssues())
5057
->withoutPulls($this->withoutPulls())
5158
->withOpen($this->withOpen())
5259
->when(
53-
$this->shouldBeAll($repository),
60+
$this->shouldBeAll($repositories),
5461
fn (GitHub $gitHub) => $gitHub->markAll(),
5562
fn (GitHub $gitHub) => $gitHub->mark()
5663
);
5764
}
5865

59-
protected function shouldBeAll(?string $repository): bool
66+
protected function shouldBeAll(array $repositories): bool
6067
{
61-
return empty($repository)
68+
return empty($repositories)
6269
&& ! $this->withoutIssues()
6370
&& ! $this->withoutPulls()
6471
&& $this->withOpen();
@@ -75,14 +82,13 @@ protected function gitHub(): GitHub
7582
]);
7683
}
7784

78-
public function show(string $value): void
79-
{
80-
$this->components->info($value);
81-
}
82-
83-
protected function repository(): ?string
85+
protected function repositories(): array
8486
{
85-
return $this->argument('repository');
87+
return collect($this->argument('repository'))
88+
->filter()
89+
->unique()
90+
->sort()
91+
->all();
8692
}
8793

8894
protected function withoutIssues(): bool

app/Services/GitHub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class GitHub
1717
{
18-
protected ?string $repository = null;
18+
protected array $repositories = [];
1919

2020
protected bool $withoutIssues = false;
2121

@@ -31,9 +31,9 @@ public function __construct(
3131
protected ResultPager $paginator,
3232
) {}
3333

34-
public function repository(?string $repository): self
34+
public function repositories(array $repositories): self
3535
{
36-
$this->repository = $repository;
36+
$this->repositories = $repositories;
3737

3838
return $this;
3939
}
@@ -132,7 +132,7 @@ protected function pullRequest(NotificationData $notification): array
132132

133133
protected function shouldSkip(NotificationData $notification, ItemData $item): bool
134134
{
135-
if ($this->repository && Str::startsWith($notification->fullName, $this->repository)) {
135+
if ($this->repositories && Str::startsWith($notification->fullName, $this->repositories)) {
136136
return true;
137137
}
138138

0 commit comments

Comments
 (0)