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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
2.5 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2022-11-25 23:54:43 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference, api
---
2021-03-11 19:13:27 +05:30
# Suggest Changes API **(FREE)**
2019-02-15 15:39:39 +05:30
2021-09-04 01:27:46 +05:30
This page describes the API for [suggesting changes](../user/project/merge_requests/reviews/suggestions.md).
2019-02-15 15:39:39 +05:30
Every API call to suggestions must be authenticated.
2023-05-27 22:25:52 +05:30
## Create a suggestion
To create a suggestion through the API, use the Discussions API to
[create a new thread in the merge request diff](discussions.md#create-new-merge-request-thread).
The format for suggestions is:
````markdown
```suggestion:-3+0
example text
```
````
## Apply a suggestion
2019-02-15 15:39:39 +05:30
2022-04-04 11:22:00 +05:30
Applies a suggested patch in a merge request. Users must have
at least the Developer role to perform such action.
2019-02-15 15:39:39 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2019-02-15 15:39:39 +05:30
PUT /suggestions/:id/apply
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2023-01-13 00:05:48 +05:30
| `id` | integer | yes | The ID of a suggestion |
2021-03-11 19:13:27 +05:30
| `commit_message` | string | no | A custom commit message to use instead of the default generated message or the project's default message |
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/suggestions/5/apply"
2019-02-15 15:39:39 +05:30
```
Example response:
```json
2023-01-13 00:05:48 +05:30
{
"id": 5,
"from_line": 10,
"to_line": 10,
"applicable": true,
"applied": false,
"from_content": "This is an eaxmple\n",
"to_content": "This is an example\n"
}
```
2023-05-27 22:25:52 +05:30
## Apply multiple suggestions
2023-01-13 00:05:48 +05:30
```plaintext
PUT /suggestions/batch_apply
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `ids` | integer | yes | The IDs of suggestions |
| `commit_message` | string | no | A custom commit message to use instead of the default generated message or the project's default message |
```shell
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --header 'Content-Type: application/json' --data '{"ids": [5, 6]}' "https://gitlab.example.com/api/v4/suggestions/batch_apply"
```
Example response:
```json
[
2019-02-15 15:39:39 +05:30
{
2023-01-13 00:05:48 +05:30
"id": 5,
2019-02-15 15:39:39 +05:30
"from_line": 10,
"to_line": 10,
2023-01-13 00:05:48 +05:30
"applicable": true,
"applied": false,
"from_content": "This is an eaxmple\n",
"to_content": "This is an example\n"
}
{
"id": 6,
"from_line": 19
"to_line": 19,
"applicable": true,
"applied": false,
"from_content": "This is another eaxmple\n",
"to_content": "This is another example\n"
2019-02-15 15:39:39 +05:30
}
2023-01-13 00:05:48 +05:30
]
2019-02-15 15:39:39 +05:30
```