Skip to content

Commit e35f6d7

Browse files
committed
Add support for sudo and creating project for another user
1 parent 3bdeff2 commit e35f6d7

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public function create($name, array $params = array())
2323

2424
return $this->post('projects', $params);
2525
}
26+
27+
public function createForUser($user_id, $name, array $params = array())
28+
{
29+
$params['name'] = $name;
30+
31+
return $this->post('projects/user/'.urlencode($user_id), $params);
32+
}
2633

2734
public function remove($project_id)
2835
{

lib/Gitlab/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ public function api($name)
119119
* @param string $token Gitlab private token
120120
* @param null|string $authMethod One of the AUTH_* class constants
121121
*/
122-
public function authenticate($token, $authMethod = null)
122+
public function authenticate($token, $authMethod = null, $sudo=null)
123123
{
124124
$this->httpClient->addListener(
125125
new AuthListener(
126126
$authMethod,
127-
$token
127+
$token,
128+
$sudo
128129
)
129130
);
130131
}

lib/Gitlab/HttpClient/Listener/AuthListener.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ class AuthListener implements ListenerInterface
2323
* @var string
2424
*/
2525
private $token;
26+
/**
27+
* @var string|null
28+
*/
29+
private $sudo;
2630

2731
/**
2832
* @param string $method
2933
* @param string $token
3034
*/
31-
public function __construct($method, $token)
35+
public function __construct($method, $token, $sudo=null)
3236
{
3337
$this->method = $method;
3438
$this->token = $token;
39+
$this->sudo = $sudo;
3540
}
3641

3742
/**
@@ -49,12 +54,17 @@ public function preSend(RequestInterface $request)
4954
switch ($this->method) {
5055
case Client::AUTH_HTTP_TOKEN:
5156
$request->addHeader('private_token: '.$this->token);
57+
if(!is_null($this->sudo)){
58+
$request->addHeader('SUDO: '.$this->sudo);
59+
}
5260
break;
5361

5462
case Client::AUTH_URL_TOKEN:
5563
$url = $request->getUrl();
5664
$url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query(array('private_token' => $this->token), '', '&'));
57-
65+
if(!is_null($this->sudo)){
66+
$url.="&".utf8_encode(http_build_query(array('sudo' => $this->sudo), '', '&'));
67+
}
5868
$request->fromUrl(new Url($url));
5969
break;
6070
}

0 commit comments

Comments
 (0)