Skip to content

Commit 09219d7

Browse files
committed
Protected branches.
1 parent 3cf5498 commit 09219d7

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎lib/Gitlab/Api/Repositories.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ public function commits($project_id)
2525
return $this->get('projects/'.urlencode($project_id).'/repository/commits');
2626
}
2727

28+
public function protectBranch($project_id, $branch_id)
29+
{
30+
return $this->post('projects/'.urlencode($project_id).'/repository/branches/'.urlencode($branch_id).'/protect');
31+
}
32+
2833
}

‎lib/Gitlab/Client.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Client
3737
*/
3838
private $options = array(
3939
'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)',
40-
'timeout' => 10
40+
'timeout' => 60
4141
);
4242

4343
private $base_url = null;

‎lib/Gitlab/Model/Branch.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static function fromArray(Project $project, array $data)
1515
$branch = new Branch($project, $data['name']);
1616

1717
if (isset($data['commit'])) {
18-
$data['commit'] = Commit::fromArray($data['commit']);
18+
$data['commit'] = Commit::fromArray($project, $data['commit']);
1919
}
2020

2121
return $branch->hydrate($data);
@@ -29,7 +29,14 @@ public function __construct(Project $project, $name = null)
2929

3030
public function show()
3131
{
32-
$data = $this->api('projects')->branch($this->project->id, $this->name);
32+
$data = $this->api('repositories')->branch($this->project->id, $this->name);
33+
34+
return Branch::fromArray($this->project, $data);
35+
}
36+
37+
public function protect()
38+
{
39+
$data = $this->api('repositories')->protectBranch($this->project->id, $this->name);
3340

3441
return Branch::fromArray($this->project, $data);
3542
}

‎lib/Gitlab/Model/Project.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,20 @@ public function branches()
127127
return $branches;
128128
}
129129

130-
public function branch($branch_id)
130+
public function branch($branch_name)
131131
{
132-
$branch = new Branch($this, $branch_id);
132+
$branch = new Branch($this, $branch_name);
133133

134134
return $branch->show();
135135
}
136136

137+
public function protectBranch($branch_name)
138+
{
139+
$branch = new Branch($this, $branch_name);
140+
141+
return $branch->protect();
142+
}
143+
137144
public function tags()
138145
{
139146
$data = $this->api('repo')->tags($this->id);

0 commit comments

Comments
 (0)