Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,22 @@ Or, if you are specifying a token:
notifications read laravel --token {...}
```

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

```Bash
notifications read laravel/framework
# or
notifications read laravel/fra
notifications read lara*/fra
# or
notifications read la
notifications read framework
# or
notifications read work
# or
notifications read fra*rk
```

Pattern matching is implemented using the [`Str::is`](https://laravel.com/docs/strings#method-str-is) method.

You can also specify several names:

```Bash
Expand Down
20 changes: 11 additions & 9 deletions app/Commands/ReadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DragonCode\GithubNotifications\Services\GitHub;
use DragonCode\GithubNotifications\Services\Output;
use Github\ResultPager;
use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;

Expand Down Expand Up @@ -36,17 +37,17 @@ public function handle(): void
}
}

protected function welcome(array $repositories, ?array $exceptRepositories): void
protected function welcome(array $includeRepositories, ?array $exceptRepositories): void
{
if ($repositories) {
$this->bulletList('You specified the following repository name masks:', $repositories);
if ($includeRepositories) {
$this->bulletList('You specified the following repository name masks:', $includeRepositories);
}

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

if (! $repositories && ! $exceptRepositories) {
if (! $includeRepositories && ! $exceptRepositories) {
Output::info('Mark as read all notifications except open ones');
}
}
Expand Down Expand Up @@ -95,12 +96,12 @@ protected function gitHub(): GitHub

protected function repositories(): array
{
return $this->argument('repository');
return $this->resolvePattern($this->argument('repository'));
}

protected function exceptRepositories(): ?array
protected function exceptRepositories(): array
{
return array_filter($this->option('except-repository')) ?: null;
return $this->resolvePattern($this->option('except-repository'));
}

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

$this->components->bulletList($this->sort($values));
$this->components->bulletList($values);
}

protected function sort(array $values): array
protected function resolvePattern(?array $values): array
{
return collect($values)
->filter()
->unique()
->map(fn (string $value) => Str::of($value)->trim()->start('*')->finish('*')->toString())
->sort()
->all();
}
Expand Down
8 changes: 4 additions & 4 deletions app/Services/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GitHub
{
protected array $repositories = [];

protected ?array $exceptRepositories = null;
protected array $exceptRepositories = [];

protected bool $exceptIssues = false;

Expand All @@ -44,7 +44,7 @@ public function repositories(array $repositories): self
return $this;
}

public function exceptRepositories(?array $except): self
public function exceptRepositories(array $except): self
{
$this->exceptRepositories = $except;

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

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

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

Expand Down