Skip to content

Commit 2998502

Browse files
committed
Show user initials. Get user counts for all users. Readme improvements.
1 parent 62f79d8 commit 2998502

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

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

33
---
44

5-
title: GitLab User Counts Tile
5+
GitLab User Counts Tile
66

77
---
88

@@ -15,12 +15,12 @@ This tile displays user counts from GitLab, including assigned merge requests, r
1515
You can install the tile via composer:
1616

1717
```bash
18-
composer require spatie/laravel-dashboard-gitlab-user-counts-tile
18+
composer require creacoon/laravel-dashboard-gitlab-user-counts-tile
1919
```
2020

2121
In the `dashboard` config file, you must add this configuration in the `tiles` key.
2222

23-
Sign up at your `Gitlab` instance to obtain GITLAB_API_TOKEN
23+
Sign up at your `GitLab` instance to obtain GITLAB_API_TOKEN
2424

2525
```php
2626
// in config/dashboard.php
@@ -30,12 +30,8 @@ return [
3030
'tiles' => [
3131
'gitlab' => [
3232
'api_token' => env('GITLAB_API_TOKEN'),
33-
'api_url' => env('GITLAB_API_URL', 'https://gitlab.example.com'),
34-
'specific_users' => [
35-
'user1',
36-
'user2',
37-
// Add more users as needed
38-
],
33+
'api_url' => env('GITLAB_API_URL', 'https://gitlab.com'),
34+
'specific_users' => explode(',', env('GITLAB_SPECIFIC_USERS')),
3935
],
4036
],
4137
];

src/FetchDataFromGitLabUserCountsCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class FetchDataFromGitLabUserCountsCommand extends Command
1212

1313
public function handle()
1414
{
15+
$tile_data = [];
16+
1517
foreach (config('dashboard.tiles.gitlab.specific_users') as $username) {
1618
$userResponse = Http::withHeaders([
1719
'PRIVATE-TOKEN' => config('dashboard.tiles.gitlab.api_token'),
@@ -22,31 +24,33 @@ public function handle()
2224
if ($userData) {
2325
$userProfile = [
2426
'avatar_url' => $userData['avatar_url'] ?? null,
25-
'name' => $userData['name'] ?? $username,
27+
'name' => preg_filter('/[^A-Z]/', '', $userData['name']),
2628
'assigned_merge_requests' => 0,
2729
'review_requested_merge_requests' => 0,
2830
'todos' => 0,
2931
];
3032

3133
$userCountResponse = Http::withHeaders([
3234
'PRIVATE-TOKEN' => config('dashboard.tiles.gitlab.api_token'),
35+
'Sudo' => $username
3336
])->get(config('dashboard.tiles.gitlab.api_url') . "/api/v4/user_counts");
3437

3538
if ($userCountResponse->successful()) {
3639
$userCountData = $userCountResponse->json();
3740
$userProfile['assigned_merge_requests'] = $userCountData['assigned_merge_requests'] ?? 0;
3841
$userProfile['review_requested_merge_requests'] = $userCountData['review_requested_merge_requests'] ?? 0;
3942
$userProfile['todos'] = $userCountData['todos'] ?? 0;
43+
44+
$tile_data[$username] = $userProfile;
4045
} else {
4146
$this->error('Failed to fetch user count for: ' . $username . '. Status: ' . $userCountResponse->status() . ', Body: ' . $userCountResponse->body());
4247
}
43-
44-
GitLabUserCountsStore::make()->setData([$username => $userProfile]);
4548
}
4649
} else {
4750
$this->error('Failed to fetch user data for: ' . $username . '. Status: ' . $userResponse->status() . ', Body: ' . $userResponse->body());
4851
}
4952
}
53+
GitLabUserCountsStore::make()->setData($tile_data);
5054

5155
$this->info('Data fetched successfully!');
5256
}

0 commit comments

Comments
 (0)