Skip to content

Commit 773c755

Browse files
Jakub Nowakm1guelpf
authored andcommitted
users impersonation token filtering
1 parent 11e1021 commit 773c755

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

index.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$client = \Gitlab\Client::create('https://git.oxyshop.cz')
6+
->authenticate('GZ_Sjjs2LESUW3kDzx4N', \Gitlab\Client::AUTH_HTTP_TOKEN);
7+
8+
$pager = new \Gitlab\ResultPager($client);
9+
10+
$oxidGroupId = 36;
11+
$projects = $pager->fetchAll($client->groups(), 'projects', [$oxidGroupId, []]);
12+
13+
$pc = $mc = 0;
14+
foreach ($projects as $id => $project) {
15+
$pc++;
16+
print_r("\n" . '------------------------------' . "\n");
17+
print_r('*' . $project['name_with_namespace'] . '*' . "\n");
18+
foreach ($client->api('merge_requests')->all($project['id'], ['state' => 'opened']) as $mr) {
19+
$mc++;
20+
$labels = implode(',', $mr['labels']);
21+
print_r("{$mr['title']}, Author: {$mr['author']['name']}, Assignee: {$mr['assignee']['name']}, Labels: {$labels}\n");
22+
}
23+
}
24+
25+
print_r("Total OXID Projects: $pc, Total Open MR: $mc");
26+
/*
27+
$nowajaId = 5;
28+
$tokens = $client->users()->userImpersonationTokens($nowajaId, ['state' => 'active']);
29+
30+
print_r($tokens);*/

lib/Gitlab/Api/Users.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Gitlab\Api;
22

3+
use function count;
34
use Symfony\Component\OptionsResolver\Options;
45

56
class Users extends AbstractApi
@@ -256,11 +257,20 @@ public function email($id)
256257

257258
/**
258259
* @param int $user_id
260+
* @param array $params
259261
* @return mixed
260262
*/
261-
public function userImpersonationTokens($user_id)
263+
public function userImpersonationTokens($user_id, $params = [])
262264
{
263-
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens');
265+
if (count($params)) {
266+
$resolver = $this->createOptionsResolver();
267+
268+
$resolver->setDefined('state')
269+
->setAllowedValues('state', ['all', 'active', 'inactive'])
270+
;
271+
}
272+
273+
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens', $resolver->resolve($params));
264274
}
265275

266276
/**

0 commit comments

Comments
 (0)