labels.md 3.5 KB
Newer Older
R
Robert Schilling 已提交
1 2 3 4
# Labels

## List labels

5
Get all labels for a given project.
R
Robert Schilling 已提交
6 7 8 9 10

```
GET /projects/:id/labels
```

11 12 13 14 15 16 17 18 19 20
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the project |

```bash
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/1/labels
```

Example response:

R
Robert Schilling 已提交
21 22
```json
[
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
   {
      "name" : "bug",
      "color" : "#d9534f"
   },
   {
      "color" : "#d9534f",
      "name" : "confirmed"
   },
   {
      "name" : "critical",
      "color" : "#d9534f"
   },
   {
      "color" : "#428bca",
      "name" : "discussion"
   },
   {
      "name" : "documentation",
      "color" : "#f0ad4e"
   },
   {
      "color" : "#5cb85c",
      "name" : "enhancement"
   },
   {
      "color" : "#428bca",
      "name" : "suggestion"
   },
   {
      "color" : "#f0ad4e",
      "name" : "support"
   }
R
Robert Schilling 已提交
55 56 57 58 59
]
```

## Create a new label

60 61 62 63
Creates a new label for the given repository with the given name and color.

It returns 200 if the label was successfully created, 400 for wrong parameters
and 409 if the label already exists.
R
Robert Schilling 已提交
64 65 66 67 68

```
POST /projects/:id/labels
```

69 70 71 72 73 74 75 76 77
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id`      | integer | yes | The ID of the project |
| `name`    | string  | yes | The name of the label |
| `color`   | string  | yes | The color of the label in 6-digit hex notation with leading `#` sign |

```bash
curl --data "name=feature&color=#5843AD" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels"
```
R
Robert Schilling 已提交
78

79
Example response:
R
Robert Schilling 已提交
80

81 82 83 84 85 86
```json
{
   "name" : "feature",
   "color" : "#5843AD"
}
```
R
Robert Schilling 已提交
87 88 89

## Delete a label

90 91 92 93 94
Deletes a label with a given name.

It returns 200 if the label was successfully deleted, 400 for wrong parameters
and 404 if the label does not exist.
In case of an error, an additional error message is returned.
R
Robert Schilling 已提交
95 96 97 98 99

```
DELETE /projects/:id/labels
```

100 101 102 103
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id`      | integer | yes | The ID of the project |
| `name`    | string  | yes | The name of the label |
R
Robert Schilling 已提交
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
```bash
curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels?name=bug"
```

Example response:

```json
{
   "title" : "feature",
   "color" : "#5843AD",
   "updated_at" : "2015-11-03T21:22:30.737Z",
   "template" : false,
   "project_id" : 1,
   "created_at" : "2015-11-03T21:22:30.737Z",
   "id" : 9
}
```
R
Robert Schilling 已提交
122 123 124

## Edit an existing label

125
Updates an existing label with new name or new color. At least one parameter
R
Robert Schilling 已提交
126 127
is required, to update the label.

128 129 130 131
It returns 200 if the label was successfully deleted, 400 for wrong parameters
and 404 if the label does not exist.
In case of an error, an additional error message is returned.

R
Robert Schilling 已提交
132 133 134 135
```
PUT /projects/:id/labels
```

136 137 138 139 140 141 142 143 144 145
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id`      | integer | yes | The ID of the project |
| `name`    | string  | yes | The name of the existing label |
| `new_name` | string  | yes if `color` if not provided | The new name of the label |
| `color`   | string  | yes if `new_name` is not provided | The new color of the label in 6-digit hex notation with leading `#` sign |

```bash
curl -X PUT --data "name=documentation&new_name=docs&color=#8E44AD" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels"
```
R
Robert Schilling 已提交
146

147
Example response:
R
Robert Schilling 已提交
148

149 150 151 152 153 154
```json
{
   "color" : "#8E44AD",
   "name" : "docs"
}
```