Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Gitlab/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public function create($name, array $params = array())

return $this->post('projects', $params);
}

public function createForUser($user_id, $name, array $params = array())
{
$params['name'] = $name;

return $this->post('projects/user/'.urlencode($user_id), $params);
}

public function remove($project_id)
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Gitlab/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ public function api($name)
* @param string $token Gitlab private token
* @param null|string $authMethod One of the AUTH_* class constants
*/
public function authenticate($token, $authMethod = null)
public function authenticate($token, $authMethod = null, $sudo = null)
{
$this->httpClient->addListener(
new AuthListener(
$authMethod,
$token
$token,
$sudo
)
);
}
Expand Down
20 changes: 17 additions & 3 deletions lib/Gitlab/HttpClient/Listener/AuthListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ class AuthListener implements ListenerInterface
* @var string
*/
private $method;

/**
* @var string
*/
private $token;

/**
* @var string|null
*/
private $sudo;

/**
* @param string $method
* @param string $token
*/
public function __construct($method, $token)
public function __construct($method, $token, $sudo = null)
{
$this->method = $method;
$this->token = $token;
$this->sudo = $sudo;
}

/**
Expand All @@ -49,12 +56,19 @@ public function preSend(RequestInterface $request)
switch ($this->method) {
case Client::AUTH_HTTP_TOKEN:
$request->addHeader('private_token: '.$this->token);
if (!is_null($this->sudo)) {
$request->addHeader('SUDO: '.$this->sudo);
}
break;

case Client::AUTH_URL_TOKEN:
$url = $request->getUrl();
$url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query(array('private_token' => $this->token), '', '&'));

$query=array('private_token' => $this->token);
if (!is_null($this->sudo)) {
$query['sudo'] = $this->sudo;
}
$url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query($query, '', '&'));

$request->fromUrl(new Url($url));
break;
}
Expand Down