Skip to content

Commit ba1bb04

Browse files
author
Matt Humphrey
committed
Added project contributors endpoint
1 parent 31245d4 commit ba1bb04

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

lib/Gitlab/Api/Repositories.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,13 @@ public function deleteFile($project_id, $file_path, $branch_name, $commit_messag
241241
'commit_message' => $commit_message
242242
));
243243
}
244+
245+
/**
246+
* @param int $project_id
247+
* @return mixed
248+
*/
249+
public function contributors($project_id)
250+
{
251+
return $this->get($this->getProjectPath($project_id, 'repository/contributors'));
252+
}
244253
}

lib/Gitlab/Model/Contributor.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php namespace Gitlab\Model;
2+
3+
use Gitlab\Client;
4+
5+
/**
6+
* Class Contributor
7+
*
8+
* @property-read string $name
9+
* @property-read string $email
10+
* @property-read int $commits
11+
* @property-read int $additions
12+
* @property-read int $deletions
13+
* @property-read Project $project
14+
*/
15+
class Contributor extends AbstractModel
16+
{
17+
/**
18+
* @var array
19+
*/
20+
protected static $properties = array(
21+
'name',
22+
'email',
23+
'commits',
24+
'additions',
25+
'deletions',
26+
'project'
27+
);
28+
29+
/**
30+
* @param Client $client
31+
* @param Project $project
32+
* @param array $data
33+
* @return Contributor
34+
*/
35+
public static function fromArray(Client $client, Project $project, array $data)
36+
{
37+
$contributor = new static($project, $client);
38+
39+
return $contributor->hydrate($data);
40+
}
41+
42+
/**
43+
* @param Project $project
44+
* @param Client $client
45+
*/
46+
public function __construct(Project $project, Client $client = null)
47+
{
48+
$this->setClient($client);
49+
$this->setData('project', $project);
50+
}
51+
}

lib/Gitlab/Model/Project.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,4 +989,19 @@ public function removeLabel($name)
989989

990990
return true;
991991
}
992+
993+
/**
994+
* @return array
995+
*/
996+
public function contributors()
997+
{
998+
$data = $this->api('repo')->contributors($this->id);
999+
1000+
$contributors = array();
1001+
foreach ($data as $contributor) {
1002+
$contributors[] = Contributor::fromArray($this->getClient(), $this, $contributor);
1003+
}
1004+
1005+
return $contributors;
1006+
}
9921007
}

0 commit comments

Comments
 (0)