Skip to content

Commit f146d73

Browse files
author
Pete Bishop
committed
Add GitHub Retrieved Release Notes Page
1 parent 4524b6a commit f146d73

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

app/Support/GitHub.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Support;
44

5+
use Illuminate\Support\Collection;
56
use Illuminate\Support\Facades\Cache;
67
use Illuminate\Support\Facades\Http;
78

@@ -38,6 +39,17 @@ function () {
3839
return $version['name'] ?? 'Unknown';
3940
}
4041

42+
public function releases(): Collection
43+
{
44+
return Cache::remember(
45+
$this->getCacheKey('releases'),
46+
now()->addHour(),
47+
function () {
48+
return $this->fetchReleases();
49+
}
50+
);
51+
}
52+
4153
private function fetchLatestVersion()
4254
{
4355
// Make a request to GitHub
@@ -55,4 +67,17 @@ private function getCacheKey(string $string): string
5567
{
5668
return sprintf('%s-%s', $this->package, $string);
5769
}
70+
71+
private function fetchReleases(): ?Collection
72+
{
73+
// Make a request to GitHub
74+
$response = Http::get('https://api.github.com/repos/'.$this->package.'/releases');
75+
76+
// Check if the request was successful
77+
if ($response->failed()) {
78+
return null;
79+
}
80+
81+
return collect($response->json());
82+
}
5883
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Release Notes
3+
order: 1100
4+
---
5+
6+
@forelse (\App\Support\GitHub::electron()->releases() as $release)
7+
## {{ $release['name'] }}
8+
Released: {{ \Carbon\Carbon::parse($release['published_at'])->format('F j, Y') }}**
9+
10+
{{ str_replace('#', '##', $release['body']) }}
11+
---
12+
@empty
13+
## We couldn't show you the latest release notes at this time.
14+
Not to worry, you can head over to GitHub to see the [latest release notes](https://github.com/NativePHP/electron/releases).
15+
@endforelse

0 commit comments

Comments
 (0)