|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -namespace Vendor\MyTile; |
| 3 | +namespace Creacoon\GitLabTile; |
4 | 4 |
|
5 | 5 | use Illuminate\Console\Command;
|
| 6 | +use Illuminate\Support\Facades\Http; |
6 | 7 |
|
7 | 8 | class FetchDataFromApiCommand extends Command
|
8 | 9 | {
|
9 |
| - protected $signature = 'dashboard:fetch-data-from-xxx-api'; |
| 10 | + protected $signature = 'dashboard:fetch-data-from-gitlab-api'; |
| 11 | + protected $description = 'Fetch data for GitLab tile'; |
10 | 12 |
|
11 |
| - protected $description = 'Fetch data for tile'; |
12 |
| - |
13 |
| - public function handle(VeloApi $velo) |
| 13 | + public function handle() |
14 | 14 | {
|
15 |
| - $this->info('Fetching Velo stations...'); |
16 |
| - |
17 |
| - $myData = Http::get($endpoint)->json(); |
18 |
| - |
19 |
| - MyStore::make()->setData($myData); |
20 |
| - |
21 |
| - $this->info('All done!'); |
| 15 | + $usersResponse = Http::withHeaders([ |
| 16 | + 'PRIVATE-TOKEN' => env('GITLAB_API_TOKEN'), |
| 17 | + ])->get('https://gl.creacoon.nl/api/v4/users?active=true'); |
| 18 | + |
| 19 | + if ($usersResponse->successful()) { |
| 20 | + $usersData = $usersResponse->json(); |
| 21 | + dump('Users Data:', $usersData); |
| 22 | + |
| 23 | + $userProfiles = []; |
| 24 | + foreach ($usersData as $user) { |
| 25 | + $username = $user['username']; |
| 26 | + $userId = $user['id']; |
| 27 | + $userProfiles[$username] = [ |
| 28 | + 'avatar_url' => $user['avatar_url'] ?? null, |
| 29 | + 'name' => $user['name'] ?? $username, |
| 30 | + 'assigned_merge_requests' => 0, |
| 31 | + 'review_requested_merge_requests' => 0, |
| 32 | + 'todos' => 0, |
| 33 | + ]; |
| 34 | + |
| 35 | + $userCountResponse = Http::withHeaders([ |
| 36 | + 'PRIVATE-TOKEN' => env('GITLAB_API_TOKEN'), |
| 37 | + ])->get("https://gl.creacoon.nl/api/v4/user_counts"); |
| 38 | + |
| 39 | + if ($userCountResponse->successful()) { |
| 40 | + $userCountData = $userCountResponse->json(); |
| 41 | + dump('User Count Data for '.$username.':', $userCountData); |
| 42 | + |
| 43 | + $userProfiles[$username]['assigned_merge_requests'] = $userCountData['assigned_merge_requests'] ?? 0; |
| 44 | + $userProfiles[$username]['review_requested_merge_requests'] = $userCountData['review_requested_merge_requests'] ?? 0; |
| 45 | + $userProfiles[$username]['todos'] = $userCountData['todos'] ?? 0; |
| 46 | + } else { |
| 47 | + $this->error('Failed to fetch user count for: ' . $username . '. Status: ' . $userCountResponse->status() . ', Body: ' . $userCountResponse->body()); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + GitLabStore::make()->setData($userProfiles); |
| 52 | + $this->info('Data fetched successfully!'); |
| 53 | + } else { |
| 54 | + $this->error('Failed to fetch user data: ' . $usersResponse->status()); |
| 55 | + } |
22 | 56 | }
|
23 | 57 | }
|
0 commit comments