debian-mirror-gitlab/doc/api/group_badges.md

189 lines
6.2 KiB
Markdown
Raw Normal View History

2018-03-27 19:54:05 +05:30
# Group badges API
2020-03-09 13:42:32 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/17082)
2018-05-09 12:01:36 +05:30
in GitLab 10.6.
2018-03-27 19:54:05 +05:30
## Placeholder tokens
Badges support placeholders that will be replaced in real time in both the link and image URL. The allowed placeholders are:
- **%{project_path}**: will be replaced by the project path.
- **%{project_id}**: will be replaced by the project id.
- **%{default_branch}**: will be replaced by the project default branch.
- **%{commit_sha}**: will be replaced by the last project's commit sha.
2018-10-15 14:42:47 +05:30
Because these endpoints aren't inside a project's context, the information used to replace the placeholders will be
2018-03-27 19:54:05 +05:30
from the first group's project by creation date. If the group hasn't got any project the original URL with the placeholders will be returned.
## List all badges of a group
Gets a list of a group's badges.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /groups/:id/badges
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
2020-01-01 13:55:28 +05:30
| `name` | string | no | Name of the badges to return (case-sensitive). |
2018-03-27 19:54:05 +05:30
2020-03-09 13:42:32 +05:30
```shell
2020-01-01 13:55:28 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/badges?name=Coverage
2018-03-27 19:54:05 +05:30
```
Example response:
```json
[
{
2020-01-01 13:55:28 +05:30
"name": "Coverage",
2018-03-27 19:54:05 +05:30
"id": 1,
"link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
2020-01-01 13:55:28 +05:30
}
2018-03-27 19:54:05 +05:30
]
```
## Get a badge of a group
Gets a badge of a group.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
| `badge_id` | integer | yes | The badge ID |
2020-03-09 13:42:32 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id
2018-03-27 19:54:05 +05:30
```
Example response:
```json
{
"id": 1,
"link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
}
```
## Add a badge to a group
Adds a badge to a group.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
POST /groups/:id/badges
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
| `link_url` | string | yes | URL of the badge link |
| `image_url` | string | yes | URL of the badge image |
2020-03-09 13:42:32 +05:30
```shell
2019-12-04 20:38:33 +05:30
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "link_url=https://gitlab.com/gitlab-org/gitlab-foss/commits/master&image_url=https://shields.io/my/badge1&position=0" https://gitlab.example.com/api/v4/groups/:id/badges
2018-03-27 19:54:05 +05:30
```
Example response:
```json
{
"id": 1,
2019-12-04 20:38:33 +05:30
"link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-27 19:54:05 +05:30
"image_url": "https://shields.io/my/badge1",
2019-12-04 20:38:33 +05:30
"rendered_link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-27 19:54:05 +05:30
"rendered_image_url": "https://shields.io/my/badge1",
"kind": "group"
}
```
## Edit a badge of a group
Updates a badge of a group.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
PUT /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
| `badge_id` | integer | yes | The badge ID |
| `link_url` | string | no | URL of the badge link |
| `image_url` | string | no | URL of the badge image |
2020-03-09 13:42:32 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id
2018-03-27 19:54:05 +05:30
```
Example response:
```json
{
"id": 1,
2019-12-04 20:38:33 +05:30
"link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-27 19:54:05 +05:30
"image_url": "https://shields.io/my/badge",
2019-12-04 20:38:33 +05:30
"rendered_link_url": "https://gitlab.com/gitlab-org/gitlab-foss/commits/master",
2018-03-27 19:54:05 +05:30
"rendered_image_url": "https://shields.io/my/badge",
"kind": "group"
}
```
## Remove a badge from a group
Removes a badge from a group.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
DELETE /groups/:id/badges/:badge_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
| `badge_id` | integer | yes | The badge ID |
2020-03-09 13:42:32 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/badges/:badge_id
2018-03-27 19:54:05 +05:30
```
## Preview a badge from a group
Returns how the `link_url` and `image_url` final URLs would be after resolving the placeholder interpolation.
2020-04-08 14:13:33 +05:30
```plaintext
2018-03-27 19:54:05 +05:30
GET /groups/:id/badges/render
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) owned by the authenticated user |
| `link_url` | string | yes | URL of the badge link|
| `image_url` | string | yes | URL of the badge image |
2020-03-09 13:42:32 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/badges/render?link_url=http%3A%2F%2Fexample.com%2Fci_status.svg%3Fproject%3D%25%7Bproject_path%7D%26ref%3D%25%7Bdefault_branch%7D&image_url=https%3A%2F%2Fshields.io%2Fmy%2Fbadge
2018-03-27 19:54:05 +05:30
```
Example response:
```json
2018-05-09 12:01:36 +05:30
{
2018-03-27 19:54:05 +05:30
"link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
"image_url": "https://shields.io/my/badge",
"rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
"rendered_image_url": "https://shields.io/my/badge",
}
```