This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fgrosse/feature/labels-api
Feature/labels api
- Loading branch information
Showing
8 changed files
with
216 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ disabled: | |
- unalign_equals | ||
- unalign_double_arrow | ||
- phpdoc_separation | ||
- phpdoc_short_description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
################################################################################## | ||
# Gitlab Labels API # | ||
# See https://github.com/gitlabhq/gitlabhq/blob/v7.7.0/doc/api/labels.md # | ||
################################################################################## | ||
|
||
operations: | ||
listLabels: | ||
summary: Get all labels for a given project. | ||
httpMethod: GET | ||
uri: projects/{project_id}/labels | ||
parameters: | ||
project_id: | ||
required: true | ||
description: The ID of a project | ||
type: string | ||
location: uri | ||
|
||
createLabel: | ||
summary: Creates a new label for given repository with given name and color. | ||
httpMethod: POST | ||
uri: projects/{project_id}/labels | ||
parameters: | ||
project_id: | ||
required: true | ||
description: The ID of a project | ||
type: string | ||
location: uri | ||
name: | ||
required: true | ||
description: The name of the label | ||
type: string | ||
location: postField | ||
color: | ||
required: true | ||
description: Color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) | ||
type: string | ||
location: postField | ||
|
||
updateLabel: | ||
extends: createLabel | ||
summary: > | ||
Updates an existing label with new name or now color. | ||
Either the new name or new color is required to update the label. | ||
httpMethod: PUT | ||
uri: projects/{project_id}/labels | ||
parameters: | ||
new_name: | ||
required: false | ||
description: The new name of the label | ||
type: string | ||
location: postField | ||
color: | ||
required: false | ||
description: New color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) | ||
type: string | ||
location: postField | ||
|
||
deleteLabel: | ||
summary: Deletes a label given by its name. | ||
httpMethod: DELETE | ||
uri: projects/{project_id}/labels | ||
parameters: | ||
project_id: | ||
required: true | ||
description: The ID of a project | ||
type: string | ||
location: uri | ||
name: | ||
required: true | ||
description: The name of the label | ||
type: string | ||
location: postField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ imports: | |
- commits_api.yml | ||
- issues_api.yml | ||
- merge_requests_api.yml | ||
- labels_api.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/* | ||
* This file is part of fgrosse/gitlab-api. | ||
* | ||
* Copyright © Friedrich Große <friedrich.grosse@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gitlab\Test\Client; | ||
|
||
class LabelsAPITest extends GitlabClientTest | ||
{ | ||
public function testListLabels() | ||
{ | ||
$this->setMockResponse(__DIR__.'/fixtures/labels/list_labels.http'); | ||
$projectId = 'fgrosse/example-project'; | ||
$this->client->listLabels([ | ||
'project_id' => $projectId, | ||
]); | ||
|
||
$request = $this->requestHistory->getLastRequest(); | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/gitlab/api/v3/projects/'.urlencode($projectId).'/labels', $request->getPath()); | ||
$this->assertEquals('application/json', $request->getHeader('Accept')); | ||
} | ||
|
||
public function testCreateNewLabel() | ||
{ | ||
$this->setMockResponse(__DIR__.'/fixtures/labels/create_update_or_delete_label.http'); | ||
$projectId = 'fgrosse/example-project'; | ||
$this->client->createLabel([ | ||
'project_id' => $projectId, | ||
'name' => 'pink', | ||
'color' => '#FFAABB', | ||
]); | ||
|
||
$request = $this->requestHistory->getLastRequest(); | ||
$this->assertEquals('POST', $request->getMethod()); | ||
$this->assertEquals('/gitlab/api/v3/projects/'.urlencode($projectId).'/labels', $request->getPath()); | ||
$this->assertEquals('application/json', $request->getHeader('Accept')); | ||
$this->assertRequestHasPostParameter('name', 'pink', $request); | ||
$this->assertRequestHasPostParameter('color', '#FFAABB', $request); | ||
} | ||
|
||
public function testUpdateLabel() | ||
{ | ||
$this->setMockResponse(__DIR__.'/fixtures/labels/create_update_or_delete_label.http'); | ||
$projectId = 'fgrosse/example-project'; | ||
$this->client->updateLabel([ | ||
'project_id' => $projectId, | ||
'name' => 'pink', | ||
'new_name' => 'awesome pink', | ||
'color' => '#FFAABB', | ||
]); | ||
|
||
$request = $this->requestHistory->getLastRequest(); | ||
$this->assertEquals('PUT', $request->getMethod()); | ||
$this->assertEquals('/gitlab/api/v3/projects/'.urlencode($projectId).'/labels', $request->getPath()); | ||
$this->assertEquals('application/json', $request->getHeader('Accept')); | ||
$this->assertRequestHasPostParameter('name', 'pink', $request); | ||
$this->assertRequestHasPostParameter('new_name', 'awesome pink', $request); | ||
$this->assertRequestHasPostParameter('color', '#FFAABB', $request); | ||
} | ||
|
||
public function testDeleteLabel() | ||
{ | ||
$this->setMockResponse(__DIR__.'/fixtures/labels/create_update_or_delete_label.http'); | ||
$projectId = 'fgrosse/example-project'; | ||
$this->client->deleteLabel([ | ||
'project_id' => $projectId, | ||
'name' => 'pink', | ||
]); | ||
|
||
$request = $this->requestHistory->getLastRequest(); | ||
$this->assertEquals('DELETE', $request->getMethod()); | ||
$this->assertEquals('/gitlab/api/v3/projects/'.urlencode($projectId).'/labels', $request->getPath()); | ||
$this->assertRequestHasPostParameter('name', 'pink', $request); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Client/fixtures/labels/create_update_or_delete_label.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
{ | ||
"name": "Awesome", | ||
"color": "#DD10AA" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
[ | ||
{ | ||
"name": "Awesome", | ||
"color": "#DD10AA" | ||
}, | ||
{ | ||
"name": "Documentation", | ||
"color": "#1E80DD" | ||
}, | ||
{ | ||
"name": "Feature", | ||
"color": "#11FF22" | ||
}, | ||
{ | ||
"name": "Bug", | ||
"color": "#EE1122" | ||
} | ||
] |