Skip to content

Commit 90980ed

Browse files
Merge pull request #94 from TheDragonCode/1.x
Improved filtering of repositories by pattern
2 parents 8cff1d0 + aa86f12 commit 90980ed

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ Or, if you are specifying a token:
5959
notifications read laravel --token {...}
6060
```
6161

62-
In addition to the organization, you can also specify the full or partial name of the repository. For example:
62+
In addition, you can use any part of the organization name and/or repository name to check against the template:
6363

6464
```Bash
6565
notifications read laravel/framework
6666
# or
67-
notifications read laravel/fra
67+
notifications read lara*/fra
6868
# or
69-
notifications read la
69+
notifications read framework
70+
# or
71+
notifications read work
72+
# or
73+
notifications read fra*rk
7074
```
7175

76+
Pattern matching is implemented using the [`Str::is`](https://laravel.com/docs/strings#method-str-is) method.
77+
7278
You can also specify several names:
7379

7480
```Bash

app/Commands/ReadCommand.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DragonCode\GithubNotifications\Services\GitHub;
77
use DragonCode\GithubNotifications\Services\Output;
88
use Github\ResultPager;
9+
use Illuminate\Support\Str;
910
use LaravelZero\Framework\Commands\Command;
1011
use Symfony\Component\Console\Exception\InvalidOptionException;
1112

@@ -36,17 +37,17 @@ public function handle(): void
3637
}
3738
}
3839

39-
protected function welcome(array $repositories, ?array $exceptRepositories): void
40+
protected function welcome(array $includeRepositories, ?array $exceptRepositories): void
4041
{
41-
if ($repositories) {
42-
$this->bulletList('You specified the following repository name masks:', $repositories);
42+
if ($includeRepositories) {
43+
$this->bulletList('You specified the following repository name masks:', $includeRepositories);
4344
}
4445

4546
if ($exceptRepositories) {
4647
$this->bulletList('You specified the following masks to exclude repositories:', $exceptRepositories);
4748
}
4849

49-
if (! $repositories && ! $exceptRepositories) {
50+
if (! $includeRepositories && ! $exceptRepositories) {
5051
Output::info('Mark as read all notifications except open ones');
5152
}
5253
}
@@ -95,12 +96,12 @@ protected function gitHub(): GitHub
9596

9697
protected function repositories(): array
9798
{
98-
return $this->argument('repository');
99+
return $this->resolvePattern($this->argument('repository'));
99100
}
100101

101-
protected function exceptRepositories(): ?array
102+
protected function exceptRepositories(): array
102103
{
103-
return array_filter($this->option('except-repository')) ?: null;
104+
return $this->resolvePattern($this->option('except-repository'));
104105
}
105106

106107
protected function exceptIssues(): bool
@@ -127,14 +128,15 @@ protected function bulletList(string $title, array $values): void
127128
{
128129
Output::info($title);
129130

130-
$this->components->bulletList($this->sort($values));
131+
$this->components->bulletList($values);
131132
}
132133

133-
protected function sort(array $values): array
134+
protected function resolvePattern(?array $values): array
134135
{
135136
return collect($values)
136137
->filter()
137138
->unique()
139+
->map(fn (string $value) => Str::of($value)->trim()->start('*')->finish('*')->toString())
138140
->sort()
139141
->all();
140142
}

app/Services/GitHub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GitHub
1717
{
1818
protected array $repositories = [];
1919

20-
protected ?array $exceptRepositories = null;
20+
protected array $exceptRepositories = [];
2121

2222
protected bool $exceptIssues = false;
2323

@@ -44,7 +44,7 @@ public function repositories(array $repositories): self
4444
return $this;
4545
}
4646

47-
public function exceptRepositories(?array $except): self
47+
public function exceptRepositories(array $except): self
4848
{
4949
$this->exceptRepositories = $except;
5050

@@ -165,11 +165,11 @@ protected function pullRequest(NotificationData $notification): array
165165

166166
protected function shouldSkip(NotificationData $notification, ItemData $item): bool
167167
{
168-
if ($this->repositories && ! Str::startsWith($notification->fullName, $this->repositories)) {
168+
if ($this->repositories && ! Str::is($this->repositories, $notification->fullName)) {
169169
return true;
170170
}
171171

172-
if ($this->exceptRepositories && Str::startsWith($notification->fullName, $this->exceptRepositories)) {
172+
if ($this->exceptRepositories && Str::is($this->exceptRepositories, $notification->fullName)) {
173173
return true;
174174
}
175175

0 commit comments

Comments
 (0)