319.md 2.6 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 55 56 57 58 59 60 61 62 63 64 65 66 67
# Import API

> 原文:[https://docs.gitlab.com/ee/api/import.html](https://docs.gitlab.com/ee/api/import.html)

*   [Import repository from GitHub](#import-repository-from-github)
*   [Import repository from Bitbucket Server](#import-repository-from-bitbucket-server)

# Import API[](#import-api "Permalink")

## Import repository from GitHub[](#import-repository-from-github "Permalink")

通过 API 将项目从 GitHub 导入到 GitLab.

```
POST /import/github 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `personal_access_token` | string | yes | GitHub 个人访问令牌 |
| `repo_id` | integer | yes | GitHub 存储库 ID |
| `new_name` | string | no | 新存储库名称 |
| `target_namespace` | string | yes | 要将存储库导入的命名空间 |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "personal_access_token=abc123&repo_id=12345&target_namespace=root" "https://gitlab.example.com/api/v4/import/github" 
```

响应示例:

```
{  "id":  27,  "name":  "my-repo",  "full_path":  "/root/my-repo",  "full_name":  "Administrator / my-repo"  } 
```

## Import repository from Bitbucket Server[](#import-repository-from-bitbucket-server "Permalink")

通过 API 将项目从 Bitbucket Server 导入到 GitLab.

**注意:** Bitbucket 项目密钥仅用于在 Bitbucket 中查找存储库. 如果要将存储库导入到 GitLab 组,则必须指定`target_namespace` . 如果您未指定`target_namespace` ,则项目将导入您的个人用户名称空间.

```
POST /import/bitbucket_server 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `bitbucket_server_url` | string | yes | Bitbucket 服务器网址 |
| `bitbucket_server_username` | string | yes | Bitbucket 服务器用户名 |
| `personal_access_token` | string | yes | Bitbucket 服务器个人访问令牌/密码 |
| `bitbucket_server_project` | string | yes | Bitbucket 项目密钥 |
| `bitbucket_server_repo` | string | yes | Bitbucket 存储库名称 |
| `new_name` | string | no | 新的回购名称 |
| `target_namespace` | string | no | 导入仓库的命名空间 |

```
curl --request POST \
  --url https://gitlab.example.com/api/v4/import/bitbucket_server \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" \
  --data '{
    "bitbucket_server_url": "http://bitbucket.example.com",
    "bitbucket_server_username": "root",
    "personal_access_token": "Nzk4MDcxODY4MDAyOiP8y410zF3tGAyLnHRv/E0+3xYs",
    "bitbucket_server_project": "NEW",
    "bitbucket_server_repo": "my-repo"
}' 
```