Skip to content

Commit 8425a4b

Browse files
andreasciamannaradutopala
authored andcommitted
Added API for creating/updating a tag release (#144)
Added unit tests.
1 parent 1e34efd commit 8425a4b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

lib/Gitlab/Api/Repositories.php

+30
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public function createTag($project_id, $name, $ref, $message = null)
9090
));
9191
}
9292

93+
/**
94+
* @param int $project_id
95+
* @param string $tag_name
96+
* @param string $description
97+
*
98+
* @return mixed
99+
*/
100+
public function createRelease( $project_id, $tag_name, $description ) {
101+
return $this->post( $this->getProjectPath( $project_id, 'repository/tags/' . $this->encodeBranch( $tag_name ) . '/release' ), array(
102+
'id' => $project_id,
103+
'tag_name' => $tag_name,
104+
'description' => $description
105+
) );
106+
}
107+
108+
/**
109+
* @param int $project_id
110+
* @param string $tag_name
111+
* @param string $description
112+
*
113+
* @return mixed
114+
*/
115+
public function updateRelease( $project_id, $tag_name, $description ) {
116+
return $this->put( $this->getProjectPath( $project_id, 'repository/tags/' . $this->encodeBranch( $tag_name ) . '/release' ), array(
117+
'id' => $project_id,
118+
'tag_name' => $tag_name,
119+
'description' => $description
120+
) );
121+
}
122+
93123
/**
94124
* @param int $project_id
95125
* @param string $sha

test/Gitlab/Tests/Api/RepositoriesTest.php

+48
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,54 @@ public function shouldCreateTag()
150150
$this->assertEquals($expectedArray, $api->createTag(1, '1.0', 'abcd1234', '1.0 release'));
151151
}
152152

153+
/**
154+
* @test
155+
*/
156+
public function shouldCreateRelease() {
157+
$project_id = 1;
158+
$tagName = 'sometag';
159+
$description = '1.0 release';
160+
161+
$expectedArray = array( 'name' => $tagName );
162+
163+
$api = $this->getApiMock();
164+
$api->expects( $this->once())
165+
->method('post')
166+
->with( 'projects/' . $project_id . '/repository/tags/' . $tagName . '/release', array(
167+
'id' => $project_id,
168+
'tag_name' => $tagName,
169+
'description' => $description
170+
))
171+
->will($this->returnValue($expectedArray))
172+
;
173+
174+
$this->assertEquals( $expectedArray, $api->createRelease( $project_id, $tagName, $description ) );
175+
}
176+
177+
/**
178+
* @test
179+
*/
180+
public function shouldUpdateRelease() {
181+
$project_id = 1;
182+
$tagName = 'sometag';
183+
$description = '1.0 release';
184+
185+
$expectedArray = array( 'description' => $tagName );
186+
187+
$api = $this->getApiMock();
188+
$api->expects( $this->once())
189+
->method('put')
190+
->with( 'projects/' . $project_id . '/repository/tags/' . $tagName . '/release', array(
191+
'id' => $project_id,
192+
'tag_name' => $tagName,
193+
'description' => $description
194+
))
195+
->will($this->returnValue($expectedArray))
196+
;
197+
198+
$this->assertEquals( $expectedArray, $api->updateRelease( $project_id, $tagName, $description ) );
199+
}
200+
153201
/**
154202
* @test
155203
*/

0 commit comments

Comments
 (0)