Skip to content

Commit 3a7686d

Browse files
committed
Add Sentry configuration to .env.example and update Issues metric for outdated packages
1 parent 2d6e25b commit 3a7686d

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ FONNTE_NUMBER = "your_number"
8282

8383
# SENTRY
8484
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
85+
SENTRY_ORGANIZATION_ID=exampleOrganizationId
86+
SENTRY_PROJECT_ID=exampleProjectId
87+
SENTRY_AUTH_TOKEN=exampleAuthToken
8588
SENTRY_TRACES_SAMPLE_RATE=1.0
8689
SENTRY_PROFILES_SAMPLE_RATE=1.0
8790

app/Nova/Dashboards/Main.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public function cards()
5757
ServerResource::make('inode')
5858
->width('1/2')
5959
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
60-
Issues::make('')
60+
Issues::make('outdated')
61+
->width('1/2')
62+
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
63+
Issues::make()
6164
->width('1/2')
6265
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
6366
Welcome::make()

app/Nova/Metrics/Issues.php

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Laravel\Nova\Http\Requests\NovaRequest;
77
use Laravel\Nova\Metrics\Value;
88
use Laravel\Nova\Metrics\ValueResult;
9-
use Laravel\Nova\Nova;
109
use Symfony\Component\Process\Process;
1110

1211
class Issues extends Value
@@ -22,21 +21,42 @@ public function name()
2221
{
2322
return $this->type === 'issues' ? 'Issues' : 'Outdated Packages';
2423
}
24+
2525
/**
2626
* Calculate the value of the metric.
2727
*/
2828
public function calculate(NovaRequest $request): ValueResult
2929
{
30-
$composer = config('app.composer');
31-
$home = config('app.composer_home');
32-
$devFlag = '--no-dev';
33-
$process = Process::fromShellCommandline("$composer outdated $devFlag -f json", base_path(), ['COMPOSER_HOME' => $home]);
34-
$process->run();
35-
$value = $process->getOutput();
36-
$data = json_decode($value, true);
37-
$count = count($data['installed'] ?? []);
38-
return $this->result($count);
30+
if ($this->type === 'outdated') {
31+
$composer = config('app.composer');
32+
$home = config('app.composer_home');
33+
$devFlag = '--no-dev';
34+
$process = Process::fromShellCommandline("$composer outdated $devFlag -f json", base_path(), ['COMPOSER_HOME' => $home]);
35+
$process->run();
36+
$value = $process->getOutput();
37+
$data = json_decode($value, true);
38+
$count = count($data['installed'] ?? []);
39+
} else {
40+
//
41+
$organization = config('sentry.organization');
42+
$project = config('sentry.project');
43+
$token = config('sentry.token');
44+
45+
$client = new \GuzzleHttp\Client;
46+
$response = $client->request('GET', "https://sentry.io/api/0/projects/$organization/$project/issues/", [
47+
'headers' => [
48+
'Authorization' => "Bearer $token",
49+
],
50+
'query' => [
51+
'query' => 'is:unresolved',
52+
],
53+
]);
3954

55+
$data = json_decode($response->getBody()->getContents(), true);
56+
$count = count($data);
57+
}
58+
59+
return $this->result($count);
4060

4161
}
4262

@@ -53,10 +73,18 @@ public function ranges(): array
5373
/**
5474
* Determine the amount of time the results of the metric should be cached.
5575
*/
56-
public function cacheFor(): DateTimeInterface|null
76+
public function cacheFor(): ?DateTimeInterface
5777
{
5878
// return now()->addMinutes(5);
5979

6080
return null;
6181
}
82+
83+
/**
84+
* Get the URI key for the metric.
85+
*/
86+
public function uriKey(): string
87+
{
88+
return 'issues_'.$this->type;
89+
}
6290
}

config/sentry.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// @see https://docs.sentry.io/product/sentry-basics/dsn-explainer/
1111
'dsn' => env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')),
1212

13+
'organization' => env('SENTRY_ORGANIZATION_ID'),
14+
'project' => env('SENTRY_PROJECT_ID'),
15+
'token' => env('SENTRY_AUTH_TOKEN'),
16+
1317
// @see https://spotlightjs.com/
1418
// 'spotlight' => env('SENTRY_SPOTLIGHT', false),
1519

0 commit comments

Comments
 (0)