Skip to content
Open

v2 #17

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
11 changes: 2 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
php: [8.4, 8.3, 8.2]
laravel: ['10.*', '11.*', '12.*']
stability: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -47,7 +40,7 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In your `config/services.php` file, add the following lines:
'oh_dear' => [
'pulse' => [
'api_key' => env('OH_DEAR_API_TOKEN'),
'site_id' => env('OH_DEAR_SITE_ID'),
'monitor_id' => env('OH_DEAR_MONITOR_ID'),
],
],
```
Expand Down
23 changes: 10 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,22 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"guzzlehttp/guzzle": "^7.9.3",
"illuminate/contracts": "^10.0|^11.0|^12.0",
"laravel/pulse": "^1.0@beta",
"ohdearapp/ohdear-php-sdk": "^3.10",
"spatie/laravel-package-tools": "^1.16.1"
"laravel/pulse": "^1.4.3",
"spatie/laravel-package-tools": "^1.92.7"
},
"require-dev": {
"laravel/pint": "^1.13.7",
"nunomaduro/collision": "^7.10|^8.0",
"orchestra/testbench": "^8.19|^9.0|^10.0",
"pestphp/pest": "^2.30|^3.7",
"pestphp/pest-plugin-arch": "^2.5|^3.0",
"pestphp/pest-plugin-laravel": "^2.2|^3.1",
"spatie/laravel-ray": "^1.33"
"nunomaduro/collision": "^7.10|^8.8.2",
"orchestra/testbench": "^8.0|^9.0|^10.4",
"pestphp/pest": "^2.35|^3.0",
"pestphp/pest-plugin-laravel": "^2.4|^3.0",
"spatie/laravel-ray": "^1.40.2"
},
"autoload": {
"psr-4": {
"OhDear\\OhDearPulse\\": "src/",
"OhDear\\OhDearPulse\\Database\\Factories\\": "database/factories/"
"OhDear\\OhDearPulse\\": "src/"
}
},
"autoload-dev": {
Expand Down
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/brokenLinks.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<div>
<a href="https://ohdear.app/sites/{{config('services.oh_dear.pulse.site_id')}}/check/broken-links/report"
<a href="https://ohdear.app/monitors/{{config('services.oh_dear.pulse.monitor_id')}}/check/broken-links/report"
target="_blank"
class="text-xs font-bold text-gray-700 uppercase transition-colors dark:text-gray-400 hover:text-brand ">
<x-ohdear-pulse::logo-ohdear class="inline-block w-10"/>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/cron.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class="text-base font-bold text-gray-600 truncate dark:text-gray-300"
</div>

<div>
<a href="https://ohdear.app/sites/{{config('services.oh_dear.pulse.site_id')}}/check/scheduled-tasks/list" target="_blank" class="text-xs font-bold text-gray-700 uppercase transition-colors dark:text-gray-400 dark:hover:text-brand ">
<a href="https://ohdear.app/monitors/{{config('services.oh_dear.pulse.monitor_id')}}/check/scheduled-tasks/list" target="_blank" class="text-xs font-bold text-gray-700 uppercase transition-colors dark:text-gray-400 dark:hover:text-brand ">
<x-ohdear-pulse::logo-ohdear class="inline-block w-10" />
</a>
</div>
Expand All @@ -43,7 +43,7 @@ class="text-base font-bold text-gray-600 truncate dark:text-gray-300"
<tr wire:key="cronCheck.{{ $cronCheck->id }}">
<x-pulse::td class="px-4 dark:bg-gray-800">
<code class="block text-xs text-gray-900 truncate dark:text-gray-100" title="{{ $cronCheck->name }}">
<a href="https://ohdear.app/sites/{{$siteId}}/check/scheduled-tasks/{{$cronCheck->id}}" target="_blank">
<a href="https://ohdear.app/monitors/{{$monitorId}}/check/scheduled-tasks/{{$cronCheck->id}}" target="_blank">
{{ $cronCheck->name }}
</a>
</code>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/uptime.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>

<div class="relative">
<a href="https://ohdear.app/sites/{{config('services.oh_dear.pulse.site_id')}}/check/uptime/report" target="_blank">
<a href="https://ohdear.app/monitors/{{config('services.oh_dear.pulse.monitor_id')}}/check/uptime/report" target="_blank">
<x-ohdear-pulse::logo-ohdear />
</a>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/VerifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected function verifyApiToken(array $ohDearConfig): self

protected function verifySiteId(array $ohDearConfig): self
{
if (empty($ohDearConfig['site_id'])) {
throw new Exception('No site id found. Make sure you added an site id to the `oh_dear.pulse.site_id` key of the `services` config file. You can found your site id on the settings page of a site on Oh Dear.');
if (empty($ohDearConfig['monitor_id'])) {
throw new Exception('No site id found. Make sure you added an site id to the `oh_dear.pulse.monitor_id` key of the `services` config file. You can found your site id on the settings page of a site on Oh Dear.');
}

$this->comment('Oh Dear site id found.');
Expand All @@ -64,7 +64,7 @@ protected function verifyConnection(array $ohDearConfig): self
{
$this->comment('Trying to reach Oh Dear...');

$site = app('ohdear-pulse')->site($ohDearConfig['site_id']);
$site = app('ohdear-pulse')->site($ohDearConfig['monitor_id']);

$this->comment("Successfully connected to Oh Dear. The configured site URL is: {$site->sortUrl}");

Expand Down
4 changes: 2 additions & 2 deletions src/Livewire/Concerns/UsesOhDearApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OhDear\OhDearPulse\Livewire\Concerns;

use OhDear\OhDearPulse\OhDearPulse;
use OhDear\PhpSdk\OhDear;
use OhDear\OhDearPulse\Support\OhDearApi\OhDear;

trait UsesOhDearApi
{
Expand All @@ -14,7 +14,7 @@ public function ohDear(): ?OhDear

public function isConfigured(): bool
{
if (! $this->siteId) {
if (! $this->monitorId) {
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Livewire/OhDearBrokenLinksCardComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class OhDearBrokenLinksCardComponent extends Card
use RemembersApiCalls;
use UsesOhDearApi;

public ?int $siteId = null;
public ?int $monitorId = null;

public function mount(?int $siteId = null)
public function mount(?int $monitorId = null)
{
$this->siteId = $siteId ?? config('services.oh_dear.pulse.site_id');
$this->monitorId = $monitorId ?? config('services.oh_dear.pulse.monitor_id');
}

public function render(): Renderable
Expand All @@ -33,7 +33,7 @@ public function render(): Renderable
}

/**
* @return array<\OhDear\PhpSdk\Resources\BrokenLink>|null
* @return array<\OhDear\OhDearPulse\Support\OhDearApi\Resources\BrokenLink>|null
*/
public function getBrokenLinks(): ?array
{
Expand All @@ -42,8 +42,8 @@ public function getBrokenLinks(): ?array
}

return $this->rememberApiCall(
fn () => $this->ohDear()?->brokenLinks($this->siteId),
'site:'.$this->siteId,
fn () => $this->ohDear()?->brokenLinks($this->monitorId),
'monitor:'.$this->monitorId,
CarbonInterval::minutes(15)
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Livewire/OhDearCronPulseCardComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class OhDearCronPulseCardComponent extends Card
use RemembersApiCalls;
use UsesOhDearApi;

public ?int $siteId;
public ?int $monitorId;

protected function css()
{
return __DIR__.'/../../dist/output.css';
}

public function mount(?int $siteId = null)
public function mount(?int $monitorId = null)
{
$this->siteId = $siteId ?? config('services.oh_dear.pulse.site_id');
$this->monitorId = $monitorId ?? config('services.oh_dear.pulse.monitor_id');
}

public function render(): Renderable
Expand All @@ -37,7 +37,7 @@ public function render(): Renderable
}

/**
* @return array<\OhDear\PhpSdk\Resources\CronCheck>|null
* @return array<\OhDear\OhDearPulse\Support\OhDearApi\Resources\CronCheck>|null
*/
public function getCronChecks(): ?array
{
Expand All @@ -46,8 +46,8 @@ public function getCronChecks(): ?array
}

return $this->rememberApiCall(
fn () => $this->ohDear()?->cronChecks($this->siteId),
'site:'.$this->siteId,
fn () => $this->ohDear()?->cronChecks($this->monitorId),
'monitor:'.$this->monitorId,
);
}
}
34 changes: 17 additions & 17 deletions src/Livewire/OhDearUptimePulseCardComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
use OhDear\OhDearPulse\Livewire\Concerns\RemembersApiCalls;
use OhDear\OhDearPulse\Livewire\Concerns\UsesOhDearApi;
use OhDear\OhDearPulse\OhDearPulse;
use OhDear\PhpSdk\Resources\Check;
use OhDear\PhpSdk\Resources\PerformanceRecord;
use OhDear\PhpSdk\Resources\Site;
use OhDear\OhDearPulse\Support\OhDearApi\Resources\Check;
use OhDear\OhDearPulse\Support\OhDearApi\Resources\Monitor;
use OhDear\OhDearPulse\Support\OhDearApi\Resources\PerformanceRecord;

#[Lazy]
class OhDearUptimePulseCardComponent extends Card
{
use RemembersApiCalls;
use UsesOhDearApi;

public int $siteId;
public int $monitorId;

public Collection $sites;
public Collection $monitors;

public array $performanceRecords;

Expand All @@ -35,11 +35,11 @@ protected function css()
return __DIR__.'/../../dist/output.css';
}

public function mount(?int $siteId = null)
public function mount(?int $monitorId = null)
{
$this->sites = collect();
$this->monitors = collect();

$this->siteId = $siteId ?? config('services.oh_dear.pulse.site_id');
$this->monitorId = $monitorId ?? config('services.oh_dear.pulse.monitor_id');

$this->fetchPerformanceRecords();
}
Expand All @@ -48,11 +48,11 @@ public function fetchPerformanceRecords(): void
{
$performanceRecords = $this->rememberApiCall(
fn () => $this->ohDear()->performanceRecords(
$this->siteId,
$this->monitorId,
Carbon::now()->subMinutes(20),
Carbon::now(),
),
'performance-records:'.$this->siteId,
'performance-records:'.$this->monitorId,
CarbonInterval::seconds(30),
);

Expand Down Expand Up @@ -98,22 +98,22 @@ public function render(): Renderable
]);
}

public function getSite(): ?Site
public function getSite(): ?Monitor
{
if (! OhDearPulse::isConfigured()) {
return null;
}

$siteAttributes = $this->rememberApiCall(
fn () => $this->ohDear()?->site($this->siteId)?->attributes,
'site:'.$this->siteId,
fn () => $this->ohDear()?->site($this->monitorId)?->attributes,
'monitor:'.$this->monitorId,
CarbonInterval::seconds(10),
);

return new Site($siteAttributes);
return new Monitor($siteAttributes);
}

protected function getStatus(?Site $site): ?string
protected function getStatus(?Monitor $site): ?string
{
if (! $site) {
return null;
Expand All @@ -138,7 +138,7 @@ protected function getStatusColor(): string
};
}

protected function getPerformance(?Site $site): ?string
protected function getPerformance(?Monitor $site): ?string
{
if (! $site) {
return null;
Expand All @@ -151,7 +151,7 @@ protected function getPerformance(?Site $site): ?string
return $check->summary;
}

protected function getCheck(Site $site, string $type): ?Check
protected function getCheck(Monitor $site, string $type): ?Check
{
return collect($site->checks)
->first(fn (Check $check) => $check->type === $type);
Expand Down
2 changes: 1 addition & 1 deletion src/OhDearPulseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use OhDear\OhDearPulse\Livewire\OhDearBrokenLinksCardComponent;
use OhDear\OhDearPulse\Livewire\OhDearCronPulseCardComponent;
use OhDear\OhDearPulse\Livewire\OhDearUptimePulseCardComponent;
use OhDear\PhpSdk\OhDear;
use OhDear\OhDearPulse\Support\OhDearApi\OhDear;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand Down
16 changes: 16 additions & 0 deletions src/Support/OhDearApi/Actions/ManagesBrokenLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace OhDear\OhDearPulse\Support\OhDearApi\Actions;

use OhDear\OhDearPulse\Support\OhDearApi\Resources\BrokenLink;

trait ManagesBrokenLinks
{
public function brokenLinks(int $monitorId): array
{
return $this->transformCollection(
$this->get("broken-links/$monitorId")['data'],
BrokenLink::class
);
}
}
16 changes: 16 additions & 0 deletions src/Support/OhDearApi/Actions/ManagesCronChecks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace OhDear\OhDearPulse\Support\OhDearApi\Actions;

use OhDear\OhDearPulse\Support\OhDearApi\Resources\CronCheck;

trait ManagesCronChecks
{
public function cronChecks(int $monitorId)
{
return $this->transformCollection(
$this->get("monitors/{$monitorId}/cron-checks")['data'],
CronCheck::class
);
}
}
15 changes: 15 additions & 0 deletions src/Support/OhDearApi/Actions/ManagesMonitors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace OhDear\OhDearPulse\Support\OhDearApi\Actions;

use OhDear\OhDearPulse\Support\OhDearApi\Resources\Monitor;

trait ManagesMonitors
{
public function site(int $monitorId): Monitor
{
$siteAttributes = $this->get("monitors/{$monitorId}");

return new Monitor($siteAttributes, $this);
}
}
Loading