diff --git a/README.md b/README.md index 1a52b5f..09a3bda 100644 --- a/README.md +++ b/README.md @@ -85,24 +85,25 @@ By default, only those Issues and Pull Requests that have been closed or merged But you can define the parameters yourself: ```Bash --i, --except-issues Exclude issues from processing --p, --except-pulls Exclude Pull Requests from processing --m, --except-mentions Exclude notifications with your mention from processing --o, --with-open Process including open Issues and Pull Requests --n, --no-interaction Do not ask any interactive question --q, --quiet Do not output any message +-r, --except-repository Exclude repositories from processing +-i, --except-issues Exclude issues from processing +-p, --except-pulls Exclude Pull Requests from processing +-m, --except-mentions Exclude notifications with your mention from processing +-o, --with-open Process including open Issues and Pull Requests +-n, --no-interaction Do not ask any interactive question +-q, --quiet Do not output any message ``` For example: ```Bash # except issues + with open -notifications read qwerty -ion +notifications read laravel -ion ``` With this set of options, notifications that have: -- whose repository name begins with the word `qwerty` +- whose repository name begins with the word `laravel` - Pull Requests only, both open and closed - will not be asked to continue in the console @@ -112,6 +113,20 @@ With this set of options, notifications that have: > notifications read --help > ``` +You can also exclude certain repositories: + +```Bash +notifications read laravel -ion -r laravel/framework -r laravel/breeze +``` + +With this set of options, notifications that have: + +- whose repository name begins with the word `laravel` +- Pull Requests only, both open and closed +- will not be asked to continue in the console +- repositories `laravel/framework` and `laravel/breeze` will not be processed + + ## Result ### Before diff --git a/app/Commands/ReadCommand.php b/app/Commands/ReadCommand.php index c2772e1..90caad7 100644 --- a/app/Commands/ReadCommand.php +++ b/app/Commands/ReadCommand.php @@ -15,6 +15,7 @@ class ReadCommand extends Command { protected $signature = 'read' . ' {repository?* : Full or partial repository names}' + . ' {--r|except-repository=* : Exclude repositories from processing}' . ' {--i|except-issues : Exclude issues from processing}' . ' {--p|except-pulls : Exclude Pull Requests from processing}' . ' {--m|except-mentions : Exclude notifications with your mention from processing}' @@ -25,26 +26,29 @@ class ReadCommand extends Command public function handle(): void { - $repositories = $this->repositories(); + $include = $this->repositories(); + $except = $this->exceptRepositories(); - $this->welcome($repositories); + $this->welcome($include, $except); if ($this->hasContinue()) { - $this->read($repositories); + $this->read($include); } } - protected function welcome(array $repositories): void + protected function welcome(array $repositories, ?array $exceptRepositories): void { if ($repositories) { - Output::info('You specified the following repository name masks:'); - - $this->components->bulletList($repositories); + $this->bulletList('You specified the following repository name masks:', $repositories); + } - return; + if ($exceptRepositories) { + $this->bulletList('You specified the following masks to exclude repositories:', $exceptRepositories); } - Output::info('Mark as read all notifications except open ones'); + if (! $repositories && ! $exceptRepositories) { + Output::info('Mark as read all notifications except open ones'); + } } protected function hasContinue(): bool @@ -56,6 +60,7 @@ protected function read(array $repositories): void { $this->gitHub() ->repositories($repositories) + ->exceptRepositories($this->exceptRepositories()) ->exceptIssues($this->exceptIssues()) ->exceptPulls($this->exceptPulls()) ->exceptMentions($this->exceptMentions()) @@ -70,6 +75,7 @@ protected function read(array $repositories): void protected function shouldBeAll(array $repositories): bool { return empty($repositories) + && ! $this->exceptRepositories() && ! $this->exceptIssues() && ! $this->exceptPulls() && ! $this->exceptMentions() @@ -89,11 +95,12 @@ protected function gitHub(): GitHub protected function repositories(): array { - return collect($this->argument('repository')) - ->filter() - ->unique() - ->sort() - ->all(); + return $this->argument('repository'); + } + + protected function exceptRepositories(): ?array + { + return array_filter($this->option('except-repository')) ?: null; } protected function exceptIssues(): bool @@ -116,6 +123,22 @@ protected function withOpen(): bool return $this->option('with-open'); } + protected function bulletList(string $title, array $values): void + { + Output::info($title); + + $this->components->bulletList($this->sort($values)); + } + + protected function sort(array $values): array + { + return collect($values) + ->filter() + ->unique() + ->sort() + ->all(); + } + protected function token(): string { if ($token = $this->detectToken()) { diff --git a/app/Services/GitHub.php b/app/Services/GitHub.php index a80279d..ab7479c 100644 --- a/app/Services/GitHub.php +++ b/app/Services/GitHub.php @@ -17,6 +17,8 @@ class GitHub { protected array $repositories = []; + protected ?array $exceptRepositories = null; + protected bool $exceptIssues = false; protected bool $exceptPulls = false; @@ -42,6 +44,13 @@ public function repositories(array $repositories): self return $this; } + public function exceptRepositories(?array $except): self + { + $this->exceptRepositories = $except; + + return $this; + } + public function exceptIssues(bool $except): self { $this->exceptIssues = $except; @@ -160,6 +169,10 @@ protected function shouldSkip(NotificationData $notification, ItemData $item): b return true; } + if ($this->exceptRepositories && Str::startsWith($notification->fullName, $this->exceptRepositories)) { + return true; + } + if ($this->exceptIssues && $notification->type === 'Issue') { return true; }