Skip to content

Commit 1e34efd

Browse files
Anthony Lawrenceradutopala
authored andcommitted
Add archive/unarchive functionality (#142)
* Added the archive & unarchive methods to API. * Added the archive/unarchive calls to the Project Model. * Added test for Archiving * Added Unarchive Test
1 parent b0a0887 commit 1e34efd

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ public function remove($project_id)
126126
{
127127
return $this->delete('projects/'.$this->encodePath($project_id));
128128
}
129+
130+
/**
131+
* @param int $project_id
132+
* @return mixed
133+
*/
134+
public function archive($project_id){
135+
return $this->post("projects/".$this->encodePath($project_id)."/archive");
136+
}
137+
138+
/**
139+
* @param int $project_id
140+
* @return mixed
141+
*/
142+
public function unarchive($project_id){
143+
return $this->post("projects/".$this->encodePath($project_id)."/unarchive");
144+
}
129145

130146
/**
131147
* @param int $project_id

lib/Gitlab/Model/Project.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ public function update(array $params)
141141

142142
return static::fromArray($this->getClient(), $data);
143143
}
144+
145+
/**
146+
* @return Project
147+
*/
148+
public function archive()
149+
{
150+
$data = $this->api("projects")->archive($this->id);
151+
152+
return static::fromArray($this->getClient(), $data);
153+
}
154+
155+
/**
156+
* @return Project
157+
*/
158+
public function unarchive()
159+
{
160+
$data = $this->api("projects")->unarchive($this->id);
161+
162+
return static::fromArray($this->getClient(), $data);
163+
}
144164

145165
/**
146166
* @return bool

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,40 @@ public function shouldUpdateProject()
142142
'issues_enabled' => true
143143
)));
144144
}
145+
146+
/**
147+
* @test
148+
*/
149+
public function shouldArchiveProject()
150+
{
151+
$expectedArray = array('id' => 1, 'archived' => true);
152+
153+
$api = $this->getApiMock();
154+
$api->expects($this->once())
155+
->method('post')
156+
->with('projects/1/archive')
157+
->will($this->returnValue($expectedArray))
158+
;
159+
160+
$this->assertEquals($expectedArray, $api->archive(1));
161+
}
162+
163+
/**
164+
* @test
165+
*/
166+
public function shouldUnarchiveProject()
167+
{
168+
$expectedArray = array('id' => 1, 'archived' => false);
169+
170+
$api = $this->getApiMock();
171+
$api->expects($this->once())
172+
->method('post')
173+
->with('projects/1/unarchive')
174+
->will($this->returnValue($expectedArray))
175+
;
176+
177+
$this->assertEquals($expectedArray, $api->unarchive(1));
178+
}
145179

146180
/**
147181
* @test

0 commit comments

Comments
 (0)