66use Laravel \Nova \Http \Requests \NovaRequest ;
77use Laravel \Nova \Metrics \Value ;
88use Laravel \Nova \Metrics \ValueResult ;
9- use Laravel \Nova \Nova ;
109use Symfony \Component \Process \Process ;
1110
1211class 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}
0 commit comments