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

134 lines
4.5 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference, api
---
2021-03-11 19:13:27 +05:30
# Project remote mirrors API **(FREE)**
2020-04-08 14:13:33 +05:30
2020-11-24 15:15:51 +05:30
[Push mirrors](../user/project/repository/repository_mirroring.md#pushing-to-a-remote-repository)
2020-04-08 14:13:33 +05:30
defined on a project's repository settings are called "remote mirrors", and the
state of these mirrors can be queried and modified via the remote mirror API
outlined below.
## List a project's remote mirrors
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/38121) in GitLab 12.9.
2020-04-08 14:13:33 +05:30
Returns an Array of remote mirrors and their statuses:
2020-05-24 23:13:21 +05:30
```plaintext
2020-04-08 14:13:33 +05:30
GET /projects/:id/remote_mirrors
```
Example request:
2020-05-24 23:13:21 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"
2020-04-08 14:13:33 +05:30
```
Example response:
```json
[
{
"enabled": true,
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true,
2020-05-24 23:13:21 +05:30
"keep_divergent_refs": true,
2020-04-08 14:13:33 +05:30
"update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
}
]
```
2021-02-22 17:27:13 +05:30
NOTE:
2021-04-17 20:07:23 +05:30
For security reasons, the `url` attribute is always scrubbed of username
2020-04-08 14:13:33 +05:30
and password information.
## Create a remote mirror
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/24189) in GitLab 12.9.
2020-04-08 14:13:33 +05:30
2021-04-17 20:07:23 +05:30
Create a remote mirror for a project. The mirror is disabled by default. You can enable it by including the optional parameter `enabled` when creating it:
2020-04-08 14:13:33 +05:30
2020-05-24 23:13:21 +05:30
```plaintext
2020-04-08 14:13:33 +05:30
POST /projects/:id/remote_mirrors
```
| Attribute | Type | Required | Description |
| :---------- | :----- | :--------- | :------------ |
| `url` | String | yes | The URL of the remote repository to be mirrored. |
| `enabled` | Boolean | no | Determines if the mirror is enabled. |
| `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. |
2020-05-24 23:13:21 +05:30
| `keep_divergent_refs` | Boolean | no | Determines if divergent refs are skipped. |
2020-04-08 14:13:33 +05:30
Example request:
2020-05-24 23:13:21 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request POST --data "url=https://username:token@example.com/gitlab/example.git" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"
2020-04-08 14:13:33 +05:30
```
Example response:
```json
{
"enabled": false,
"id": 101486,
"last_error": null,
"last_successful_update_at": null,
"last_update_at": null,
"last_update_started_at": null,
"only_protected_branches": false,
2020-05-24 23:13:21 +05:30
"keep_divergent_refs": false,
2020-04-08 14:13:33 +05:30
"update_status": "none",
"url": "https://*****:*****@example.com/gitlab/example.git"
}
```
## Update a remote mirror's attributes
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/38121) in GitLab 12.9.
2020-04-08 14:13:33 +05:30
Toggle a remote mirror on or off, or change which types of branches are
mirrored:
2020-05-24 23:13:21 +05:30
```plaintext
2020-04-08 14:13:33 +05:30
PUT /projects/:id/remote_mirrors/:mirror_id
```
| Attribute | Type | Required | Description |
| :---------- | :----- | :--------- | :------------ |
| `mirror_id` | Integer | yes | The remote mirror ID. |
| `enabled` | Boolean | no | Determines if the mirror is enabled. |
| `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. |
2020-05-24 23:13:21 +05:30
| `keep_divergent_refs` | Boolean | no | Determines if divergent refs are skipped. |
2020-04-08 14:13:33 +05:30
Example request:
2020-05-24 23:13:21 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request PUT --data "enabled=false" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"
2020-04-08 14:13:33 +05:30
```
Example response:
```json
{
"enabled": false,
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true,
2020-05-24 23:13:21 +05:30
"keep_divergent_refs": true,
2020-04-08 14:13:33 +05:30
"update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
}
```