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
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
51 changes: 37 additions & 14 deletions app/Commands/ReadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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()) {
Expand Down
13 changes: 13 additions & 0 deletions app/Services/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class GitHub
{
protected array $repositories = [];

protected ?array $exceptRepositories = null;

protected bool $exceptIssues = false;

protected bool $exceptPulls = false;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down