Skip to content

Commit b6e6c14

Browse files
Fix styling
1 parent c33575a commit b6e6c14

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

packages/github/src/Commands/GitHubTokenCommand.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Console\Command;
7+
78
class GitHubTokenCommand extends Command
89
{
910
protected $signature = 'github:token
@@ -16,9 +17,10 @@ class GitHubTokenCommand extends Command
1617
public function handle(): int
1718
{
1819
$user = User::first();
19-
20-
if (!$user) {
20+
21+
if (! $user) {
2122
$this->error('No user found in database. Please create a user first.');
23+
2224
return 1;
2325
}
2426

@@ -43,21 +45,22 @@ private function checkToken(User $user): int
4345
// Check environment variable first (like monorepo v2 does)
4446
$token = env('GITHUB_TOKEN');
4547
$source = 'environment';
46-
48+
4749
// Fallback to user model
48-
if (!$token) {
50+
if (! $token) {
4951
$token = $user->github_token;
5052
$source = 'user model';
5153
}
52-
53-
if (!$token) {
54+
55+
if (! $token) {
5456
$this->warn('No GitHub token found.');
5557
$this->showInstructions();
58+
5659
return 1;
5760
}
5861

59-
$this->info("GitHub token found in {$source}: " . substr($token, 0, 10) . '...');
60-
62+
$this->info("GitHub token found in {$source}: ".substr($token, 0, 10).'...');
63+
6164
// Test the token
6265
try {
6366
$response = \Illuminate\Support\Facades\Http::withHeaders([
@@ -68,20 +71,20 @@ private function checkToken(User $user): int
6871
if ($response->successful()) {
6972
$userData = $response->json();
7073
$this->info("✅ Token is valid for user: {$userData['login']}");
71-
74+
7275
// Check scopes
7376
$scopes = $response->header('X-OAuth-Scopes');
7477
$this->line("📋 Available scopes: {$scopes}");
75-
78+
7679
$availableScopes = explode(', ', $scopes ?? '');
77-
80+
7881
// Check required scopes (with equivalent higher-level scopes)
7982
$scopeChecks = [
8083
'repo' => ['repo'],
8184
'read:org' => ['read:org', 'admin:org'], // admin:org includes read:org
82-
'workflow' => ['workflow']
85+
'workflow' => ['workflow'],
8386
];
84-
87+
8588
foreach ($scopeChecks as $required => $acceptable) {
8689
$hasScope = false;
8790
foreach ($acceptable as $scope) {
@@ -90,7 +93,7 @@ private function checkToken(User $user): int
9093
break;
9194
}
9295
}
93-
96+
9497
if ($hasScope) {
9598
$this->info("{$required}");
9699
} else {
@@ -102,10 +105,12 @@ private function checkToken(User $user): int
102105
} else {
103106
$this->error('❌ Token is invalid or expired.');
104107
$this->showInstructions();
108+
105109
return 1;
106110
}
107111
} catch (\Exception $e) {
108112
$this->error("❌ Failed to validate token: {$e->getMessage()}");
113+
109114
return 1;
110115
}
111116
}
@@ -118,6 +123,7 @@ private function clearToken(User $user): int
118123
]);
119124

120125
$this->info('✅ GitHub token cleared.');
126+
121127
return 0;
122128
}
123129

@@ -126,24 +132,25 @@ private function showTokenInfo(User $user): int
126132
// Check environment variable first
127133
$token = env('GITHUB_TOKEN');
128134
$source = 'environment';
129-
135+
130136
// Fallback to user model
131-
if (!$token) {
137+
if (! $token) {
132138
$token = $user->github_token;
133139
$source = 'user model';
134140
}
135-
136-
if (!$token) {
141+
142+
if (! $token) {
137143
$this->warn('No GitHub token found.');
144+
138145
return 1;
139146
}
140147

141148
$this->info('GitHub Token Information:');
142149
$this->line("Source: {$source}");
143150
$this->line("User ID: {$user->id}");
144151
$this->line("GitHub ID: {$user->github_id}");
145-
$this->line("Token: " . substr($token, 0, 10) . '...' . substr($token, -4));
146-
$this->line("Token Type: " . (str_starts_with($token, 'gho_') ? 'OAuth Token' : 'Personal Access Token'));
152+
$this->line('Token: '.substr($token, 0, 10).'...'.substr($token, -4));
153+
$this->line('Token Type: '.(str_starts_with($token, 'gho_') ? 'OAuth Token' : 'Personal Access Token'));
147154

148155
return 0;
149156
}
@@ -156,16 +163,16 @@ private function showStatus(User $user): int
156163
// Check environment variable first
157164
$token = env('GITHUB_TOKEN');
158165
$source = 'environment';
159-
166+
160167
// Fallback to user model
161-
if (!$token) {
168+
if (! $token) {
162169
$token = $user->github_token;
163170
$source = 'user model';
164171
}
165-
172+
166173
if ($token) {
167174
$this->info("✅ Token found in {$source} for user: {$user->name}");
168-
$this->line("Token: " . substr($token, 0, 10) . '...');
175+
$this->line('Token: '.substr($token, 0, 10).'...');
169176
$this->line('');
170177
$this->line('Use --check to validate the token');
171178
} else {
@@ -196,4 +203,4 @@ private function showInstructions(): void
196203
$this->line(' php artisan github:token --info # Show token details');
197204
$this->line(' php artisan github:token --clear # Remove token');
198205
}
199-
}
206+
}

packages/monorepo/src/Commands/Concerns/HasGitHubTokenConcern.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function getGitHubTokenWithValidation(): ?string
2626

2727
if (! $token) {
2828
$this->error('No GitHub token found. Please link your GitHub account.');
29+
2930
return null;
3031
}
3132

packages/monorepo/src/Commands/CreateRelease.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CreateRelease extends Command
2525
// 1. Check the current version of this monorepo from GitHub API ✓
2626
// 2. Ask the user for the new version, e.g. 4.2.11 ✓
2727
// 3. Read directory of all packages (also private) ✓
28-
// 4. If repos do not exist, create them (2nd iteration)
28+
// 4. If repos do not exist, create them (2nd iteration)
2929
// 5. For each new repo, add it to devlink.php (2nd iteration)
3030
// 6. Read the DEVLOG.md file ✓
3131
// 7. Suggest contents from the DEVLOG.md file ✓
@@ -44,7 +44,7 @@ public function __construct()
4444
{
4545
parent::__construct();
4646
$token = $this->getGitHubToken();
47-
47+
4848
// Only initialize services if token exists
4949
// If no token, we'll handle the error in the handle() method
5050
if ($token) {
@@ -57,12 +57,12 @@ public function __construct()
5757
public function handle(): int
5858
{
5959
// If services weren't initialized due to missing token, initialize them now with validation
60-
if (!isset($this->githubService)) {
60+
if (! isset($this->githubService)) {
6161
$token = $this->getGitHubTokenWithValidation();
62-
if (!$token) {
62+
if (! $token) {
6363
return 1;
6464
}
65-
65+
6666
$this->githubService = new GitHubService($token);
6767
$this->packageComparisonService = new PackageComparisonService($this->githubService, config('monorepo.organization', 'mooxphp'));
6868
$this->devlogService = new DevlogService($this->githubService);

0 commit comments

Comments
 (0)