Skip to content

Commit f4d356f

Browse files
committed
refactor: clean up
1 parent 3abf926 commit f4d356f

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,21 @@ jobs:
3434
- name: List Installed Dependencies
3535
run: composer show -D
3636

37-
- name: Get latest GitHub Statistics
37+
- name: Get latest GitHub statistics
3838
id: stats
3939
env:
4040
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141
run: |
4242
set -e
43-
44-
# Get stargazers
4543
STARS=$(curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/tempestphp/tempest-framework | jq '.stargazers_count // empty')
46-
STARS_K=""
47-
if [ -n "$STARS" ]; then
48-
if [ "$STARS" -gt 999 ]; then
49-
STARS_K=$(awk "BEGIN { printf \"%.1fK\", $STARS/1000 }")
50-
else
51-
STARS_K=$STARS
52-
fi
53-
fi
54-
55-
# Get latest release tag
5644
TAG=$(curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/tempestphp/tempest-framework/releases/latest | jq -r '.tag_name // empty')
57-
58-
echo "Stars: $STARS_K"
59-
echo "Latest Version: $TAG"
60-
61-
# Push these values to the output
62-
echo "stars=$STARS_K" >> "$GITHUB_OUTPUT"
45+
echo "Stars: $STARS"
46+
echo "Latest version: $TAG"
47+
echo "stars=$STARS" >> "$GITHUB_OUTPUT"
6348
echo "latest_tag=$TAG" >> "$GITHUB_OUTPUT"
6449
6550
- name: Deploy
6651
run: php ./tempest deploy
6752
env:
6853
TEMPEST_BUILD_STARGAZERS: ${{ steps.stats.outputs.stars }}
6954
TEMPEST_BUILD_LATEST_RELEASE: ${{ steps.stats.outputs.latest_tag }}
70-
71-

src/GitHub/GetLatestRelease.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public function __invoke(): ?string
3030
->body;
3131

3232
return json_decode($body)->tag_name ?? $defaultRelease;
33-
} catch (Throwable $e) {
34-
ll($e);
35-
return Kernel::VERSION;
33+
} catch (Throwable) {
34+
return $defaultRelease;
3635
}
3736
}
3837
}

src/GitHub/GetStargazersCount.php

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

33
namespace App\GitHub;
44

5+
use PDO;
56
use Tempest\HttpClient\HttpClient;
67
use Throwable;
78

@@ -15,6 +16,17 @@ public function __construct(
1516
}
1617

1718
public function __invoke(): ?string
19+
{
20+
if ($stargazers = $this->getStargazersCount()) {
21+
return $stargazers > 999
22+
? (round($stargazers / 1000, 1) . 'K')
23+
: $stargazers;
24+
}
25+
26+
return null;
27+
}
28+
29+
private function getStargazersCount(): ?int
1830
{
1931
if ($stargazers = env('TEMPEST_BUILD_STARGAZERS')) {
2032
return $stargazers;
@@ -24,13 +36,9 @@ public function __invoke(): ?string
2436
$body = $this->httpClient
2537
->get(uri: 'https://api.github.com/repos/tempestphp/tempest-framework')
2638
->body;
27-
$stargazers = json_decode($body)->stargazers_count ?? null;
2839

29-
return $stargazers > 999
30-
? (round($stargazers / 1000, 1) . 'K')
31-
: $stargazers;
32-
} catch (Throwable $e) {
33-
ll($e);
40+
return $stargazers = json_decode($body)->stargazers_count ?? null;
41+
} catch (\Throwable) {
3442
return null;
3543
}
3644
}

0 commit comments

Comments
 (0)