
# 导入合并请求 - ImportMergeRequest
#### 功能介绍
导入合并请求
#### 调试
您可以在[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CodeArtsRepo/doc?api=ImportMergeRequest&version=v4)中调试该接口，支持自动认证鉴权。API Explorer可以自动生成SDK代码示例，并提供SDK代码示例调试功能。
#### 授权信息
账号根用户具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备如下身份策略权限，更多的权限说明请参见[权限和授权项](https://support.huaweicloud.com/api-codeartsrepo/codeartsrepo_05_0036.html)。
| 授权项                                        | 访问级别  | 资源类型（\*为必须） | 条件键 | 别名 | 依赖的授权项 |
|:---|:---|:---|:---|:---|:---|
| codeartsrepo:repository:createMergeRequest | Write | -           | -   | -  | -      |
   
#### URI
POST /v4/repositories/{repository_id}/import-merge-requests
表1路径参数 
| 参数            | 是否必选 | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|:---|
| repository_id | 是    | Integer | **参数解释：** 仓库的ID，通过[查询用户所有仓库](https://support.huaweicloud.com/api-codeartsrepo/ListUserAllRepositories.html)接口查询项目列表获取。 **约束限制：** 不涉及。 **默认取值：** 不涉及。 **取值范围：** 1\~2147483647 |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释：** 用户Token。 通过调用IAM服务[获取用户Token](https://support.huaweicloud.com/api-iam/iam_30_0001.html)接口获取（响应消息头中X-Subject-Token的值）。 **约束限制：** 不涉及。 **取值范围：** 字符串长度不少于1，不超过10万。 **默认取值：** 不涉及。 |
   
表3请求Body参数 
| 参数                   | 是否必选 | 参数类型                                                                               | 描述                                                                                                                   |
|:---|:---|:---|:---|
| iid                  | 是    | Integer                                                                            | 合并请求iid **取值范围：** 1\~9223372036854775807 |
| source_uniq_key      | 是    | String                                                                             | 导入唯一标识                                                                                                               |
| author_id            | 否    | Integer                                                                            | 作者id **取值范围：** 1\~9223372036854775807    |
| state                | 是    | String                                                                             | 状态                                                                                                                   |
| title                | 否    | String                                                                             | 标题                                                                                                                   |
| description          | 否    | String                                                                             | 描述                                                                                                                   |
| source_branch        | 是    | String                                                                             | 源分支                                                                                                                  |
| target_branch        | 是    | String                                                                             | 目标分支                                                                                                                 |
| target_repository_id | 是    | String                                                                             | 目标仓库                                                                                                                 |
| labels               | 否    | Object                                                                             | 标签                                                                                                                   |
| created_at           | 否    | String                                                                             | 创建时间                                                                                                                 |
| updated_at           | 否    | String                                                                             | 更新时间                                                                                                                 |
| merged_at            | 否    | String                                                                             | 合并时间                                                                                                                 |
| closed_at            | 否    | String                                                                             | 关闭时间                                                                                                                 |
| approvers            | 否    | Array of [ApproverParamDto] objects | 审核人列表                                                                                                                |
| diff_refs            | 是    | Object                                                                             | 合并请求变更commit列表                                                                                                       |
| squash               | 否    | Boolean                                                                            | squash合并                                                                                                             |
| remove_source_branch | 否    | Boolean                                                                            | 合并mr后删除源分支                                                                                                           |
| branch_is_deleted    | 否    | Boolean                                                                            | 源分支是否被删除                                                                                                             |
| fork                 | 否    | Boolean                                                                            | 源合并请求是否是fork合并请求                                                                                                     |
| import_source_from   | 否    | String                                                                             | 导入来源                                                                                                                 |
   
 表4ApproverParamDto 
| 参数          | 是否必选 | 参数类型    | 描述    |
|:---|:---|:---|:---|
| approver_id | 否    | Integer | 审核人id |
| code_owner  | 否    | Boolean | 代码所有者 |
| accept      | 否    | Boolean | 是否接纳  |
   
表5DiffRefsParamDto 
| 参数        | 是否必选 | 参数类型   | 描述                          |
|:---|:---|:---|:---|
| base_sha  | 是    | String | 合并请求中原分支与目标分支的共同基准点         |
| start_sha | 是    | String | 合并请求中，从共同基准点开始到原分支方向的第一个提交点 |
| head_sha  | 是    | String | 合并请求中原分支指向的提交点              |
   
#### 响应参数
**状态码：200**
表6响应Body参数 
| 参数                               | 参数类型                                                                                                              | 描述                                                                                                                   |
|:---|:---|:---|
| id                               | Integer                                                                                                           | 合并请求id                                                                                                               |
| iid                              | Integer                                                                                                           | 合并请求iid                                                                                                              |
| repository_id                    | Integer                                                                                                           | 目标仓库id                                                                                                               |
| title                            | String                                                                                                            | 合并请求标题                                                                                                               |
| description                      | String                                                                                                            | 合并请求描述                                                                                                               |
| state                            | String                                                                                                            | 合并请求状态                                                                                                               |
| created_at                       | String                                                                                                            | 创建时间                                                                                                                 |
| updated_at                       | String                                                                                                            | 更新时间                                                                                                                 |
| source_branch                    | String                                                                                                            | 源分支                                                                                                                  |
| target_branch                    | String                                                                                                            | 目标分支                                                                                                                 |
| is_source_branch_protected       | Boolean                                                                                                           | 源分支是否为保护分支                                                                                                           |
| is_source_branch_default         | Boolean                                                                                                           | 源分支是否为默认分支                                                                                                           |
| devcloud_source_branch           | String                                                                                                            | 源分支                                                                                                                  |
| upvotes                          | Integer                                                                                                           | MR点赞数                                                                                                                |
| downvotes                        | Integer                                                                                                           | MR倒赞数                                                                                                                |
| author                           | [UserBasicExternalDto] object                                 | 作者                                                                                                                   |
| assignee                         | [UserBasicExternalDto] object                                 | 合并人                                                                                                                  |
| source_repository_id             | Integer                                                                                                           | 源仓库id                                                                                                                |
| target_repository_id             | Integer                                                                                                           | 目标仓库id                                                                                                               |
| source_project_id                | String                                                                                                            | 源项目id                                                                                                                |
| target_project_id                | String                                                                                                            | 目标项目id                                                                                                               |
| labels                           | Array of objects                                                                                                  | 标签                                                                                                                   |
| work_in_progress                 | Boolean                                                                                                           | WIP状态                                                                                                                |
| milestone                        | [MilestoneBasicDto] object                                       | 里程碑                                                                                                                  |
| merge_when_build_succeeds        | Boolean                                                                                                           | 流水线成功后自动合入                                                                                                           |
| merge_status                     | String                                                                                                            | 可合并状态                                                                                                                |
| sha                              | String                                                                                                            | 当前合并请求最新commit                                                                                                       |
| merge_commit_sha                 | String                                                                                                            | 合入commit节点                                                                                                           |
| subscribed                       | Boolean                                                                                                           | 订阅                                                                                                                   |
| merged_by                        | [UserBasicExternalDto] object                                 | 合并人                                                                                                                  |
| merged_at                        | String                                                                                                            | 合并时间                                                                                                                 |
| closed_by                        | [UserBasicExternalDto] object                                 | 关闭人                                                                                                                  |
| closed_at                        | String                                                                                                            | 关闭时间                                                                                                                 |
| user_notes_count                 | Integer                                                                                                           | 检视意见数量                                                                                                               |
| should_remove_source_branch      | Boolean                                                                                                           | 是否需要删除源分支                                                                                                            |
| force_remove_source_branch       | Boolean                                                                                                           | 合入后删除源分支                                                                                                             |
| web_url                          | String                                                                                                            | 主页url                                                                                                                |
| merge_request_diff               | [MergeRequestDiffExternalDto] object                   | 合并请求diff                                                                                                             |
| merge_request_reviewers_count    | Integer                                                                                                           | 评审人数量                                                                                                                |
| merge_request_review_count       | Integer                                                                                                           | 打分                                                                                                                   |
| merge_request_reviewer_list      | Array of [MergeRequestReviewerExternalDto] objects | 评审人列表                                                                                                                |
| merge_request_assignee_list      | Array of [UserBasicExternalDto] objects                       | 合并人列表                                                                                                                |
| notes                            | Integer                                                                                                           | 检视意见                                                                                                                 |
| codecheck_state                  | Integer                                                                                                           | 代码检查状态                                                                                                               |
| codecheck_defect_count           | Integer                                                                                                           | 代码检查问题数                                                                                                              |
| merge_request_related_work_items | Array of [MergeRequestRelatedWorkItemDto] objects   | 合并请求关联单数量                                                                                                            |
| diverged_commits_count           | Integer                                                                                                           | 源分支落后commit数                                                                                                         |
| moderation_result                | Boolean                                                                                                           | 送审结果                                                                                                                 |
| moderation_time                  | Long                                                                                                              | 送审时间时间戳 **取值范围：** 1\~9223372036854775807 |
| moderation_status                | Integer                                                                                                           | 送审状态码 **取值范围：** 1\~2147483647            |
| is_use_temp_branch               | Boolean                                                                                                           | 是否使用临时分支                                                                                                             |
| only_assignee_can_merge          | Boolean                                                                                                           | 只有合并人允许合入                                                                                                            |
| review_mode                      | String                                                                                                            | 检视模式                                                                                                                 |
| squash                           | Boolean                                                                                                           | squash合入                                                                                                             |
| approval_merge_request_approvers | Array of [ApprovalUserDto] objects                                 | 审核模式审核人                                                                                                              |
| approval_merge_request_reviewers | Array of [ApprovalUserDto] objects                                 | 审核模式检视人                                                                                                              |
| topic                            | String                                                                                                            | MR主题                                                                                                                 |
| source_repository                | [ProjectSimpleDto] object                                         | 源仓库                                                                                                                  |
| target_repository                | [ProjectSimpleDto] object                                         | 目标仓库                                                                                                                 |
| is_source_branch_exist           | Boolean                                                                                                           | 源分支存在                                                                                                                |
| merge_request_type               | String                                                                                                            | 合并请求类型                                                                                                               |
| squash_commit_message            | String                                                                                                            | squash提交信息                                                                                                           |
| auto_merge                       | Boolean                                                                                                           | 自动合入                                                                                                                 |
| merge_error                      | String                                                                                                            | MR原始错误信息                                                                                                             |
| json_merge_error                 | [MergeErrorDto] object                                               | MR错误信息                                                                                                               |
| rebase_in_progress               | Boolean                                                                                                           | 是否正在rebase                                                                                                           |
   
 表7MilestoneBasicDto 
| 参数              | 参数类型    | 描述                                                                                                         |
|:---|:---|:---|
| id              | Integer | 里程碑id **取值范围：** 1\~2147483647  |
| iid             | Integer | 里程碑iid **取值范围：** 1\~2147483647 |
| repository_id   | Integer | 仓库id **取值范围：** 1\~2147483647   |
| title           | String  | 里程碑标题                                                                                                      |
| description     | String  | 里程碑描述                                                                                                      |
| state           | String  | 状态                                                                                                         |
| created_at      | String  | 创建时间                                                                                                       |
| updated_at      | String  | 更新时间                                                                                                       |
| due_date        | String  | 到期时间                                                                                                       |
| start_date      | String  | 开始时间                                                                                                       |
| repository_path | String  | 仓库路径                                                                                                       |
| web_url         | String  | 主页url                                                                                                      |
   
 表8UserBasicExternalDto 
| 参数             | 参数类型    | 描述                                                                                                                                                                                                        |
|:---|:---|:---|
| id             | Integer | 用户id **取值范围：** 1\~2147483647                                                                                                  |
| name           | String  | 名称                                                                                                                                                                                                        |
| username       | String  | 用户名称                                                                                                                                                                                                      |
| state          | String  | 状态                                                                                                                                                                                                        |
| avatar_url     | String  | 头像url                                                                                                                                                                                                     |
| web_url        | String  | 主页url                                                                                                                                                                                                     |
| nick_name      | String  | 用户昵称                                                                                                                                                                                                      |
| tenant_name    | String  | 租户名称                                                                                                                                                                                                      |
| has_permission | Boolean | **参数解释：** 是否有相关权限。 **取值范围：** true：有权限。 false：没权限。 |
   
 表9MergeRequestDiffExternalDto 
| 参数                  | 参数类型    | 描述                                                                                                              |
|:---|:---|:---|
| id                  | Integer | 合并请求diff id **取值范围：** 1\~2147483647 |
| state               | String  | 状态                                                                                                              |
| merge_request_id    | Integer | 合并请求id **取值范围：** 1\~2147483647      |
| created_at          | String  | 创建时间                                                                                                            |
| updated_at          | String  | 更新时间                                                                                                            |
| base_commit_sha     | String  | base commit节点                                                                                                   |
| real_size           | String  | diff文件数量                                                                                                        |
| head_commit_sha     | String  | head commit节点                                                                                                   |
| start_commit_sha    | String  | start commit节点                                                                                                  |
| commits_count       | Integer | commit数量 **取值范围：** 1\~2147483647    |
| external_diff       | String  | 外部diff文件                                                                                                        |
| external_diff_store | Integer | 外部差异存储 **取值范围：** 1\~2147483647      |
| stored_externally   | Boolean | 是否外部存储                                                                                                          |
| added_lines         | Integer | 新增行数 **取值范围：** 0\~2147483647        |
| removed_lines       | Integer | 删除行数 **取值范围：** 0\~2147483647        |
   
 表10MergeRequestReviewerExternalDto 
| 参数          | 参数类型    | 描述                                                                                                        |
|:---|:---|:---|
| id          | Integer | 评审人id **取值范围：** 1\~2147483647 |
| username    | String  | 评审人名称                                                                                                     |
| name        | String  | 评审人名称                                                                                                     |
| nick_name   | String  | 评审人昵称                                                                                                     |
| state       | Boolean | 评审人状态                                                                                                     |
| score       | Integer | 打分 **取值范围：** -2\~2            |
| tenant_name | String  | 租户名称                                                                                                      |
   
 表11MergeRequestRelatedWorkItemDto 
| 参数                  | 参数类型    | 描述                                                                                                         |
|:---|:---|:---|
| id                  | Integer | 关联id **取值范围：** 1\~2147483647   |
| user_id             | String  | 用户id                                                                                                       |
| repo_id             | Integer | 仓库id **取值范围：** 1\~2147483647   |
| merge_request_id    | Integer | 合并请求id **取值范围：** 1\~2147483647 |
| target_branch       | String  | 目标分支                                                                                                       |
| source_branch       | String  | 源分支                                                                                                        |
| merge_request_title | String  | 合并请求标题                                                                                                     |
| merge_request_url   | String  | 合并请求url                                                                                                    |
| merge_request_state | String  | 合并请求状态                                                                                                     |
| related_id          | String  | 关联单id                                                                                                      |
| related_title       | String  | 关联单标题                                                                                                      |
| related_url         | String  | 关联单url                                                                                                     |
| result              | Integer | 关联结果                                                                                                       |
| message             | String  | 关联结果信息                                                                                                     |
| create_at           | String  | 创建时间                                                                                                       |
| update_at           | String  | 更新时间                                                                                                       |
| subject             | String  | 话题                                                                                                         |
| tracker             | Object  | 跟单人                                                                                                        |
| status              | Object  | 状态                                                                                                         |
   
 表12ApprovalUserDto 
| 参数               | 参数类型    | 描述                                                                                                       |
|:---|:---|:---|
| id               | Integer | 用户id **取值范围：** 1\~2147483647 |
| username         | String  | 用户名称                                                                                                     |
| name             | String  | 用户名称                                                                                                     |
| nick_name        | String  | 用户昵称                                                                                                     |
| name_cn          | String  | 中文名称                                                                                                     |
| email            | String  | 电子邮箱                                                                                                     |
| state            | String  | 状态                                                                                                       |
| updated_at       | String  | 更新时间                                                                                                     |
| avatar_url       | String  | 头像url                                                                                                    |
| tenant_name      | String  | 租户名称                                                                                                     |
| approver_comment | String  | 审核意见                                                                                                     |
   
 表13ProjectSimpleDto 
| 参数                  | 参数类型    | 描述               |
|:---|:---|:---|
| id                  | Integer | 仓库id             |
| description         | String  | 仓库描述信息           |
| name                | String  | 仓库名称             |
| name_with_namespace | String  | 组织名/组织名.../仓库名   |
| path                | String  | 仓库路径             |
| path_with_namespace | String  | 仓库完整路径           |
| created_at          | String  | 创建时间             |
| updated_at          | String  | 更新时间             |
| archived            | Boolean | 是否归档             |
| is_kia              | Boolean | 是否机密             |
| ssh_url_to_repo     | String  | 仓库ssh地址          |
| http_url_to_repo    | String  | 仓库http地址         |
| web_url             | String  | 仓库页面链接           |
| readme_url          | String  | 仓库readme文件链接     |
| project_id          | String  | 项目id             |
| project_name        | String  | 项目名称             |
| develop_mode        | String  | 仓库开发模式：normal、CR |
| moderation_result   | Boolean | 审核状态             |
   
 表14MergeErrorDto 
| 参数               | 参数类型   | 描述    |
|:---|:---|:---|
| merge_user_name  | String | 合并人名字 |
| merge_start_time | String | 合入时间  |
| error_title      | String | 错误标题  |
| http_code_status | String | 状态码   |
| error_code       | String | 错误码   |
| error_message    | String | 错误信息  |
   
**状态码：401**
表15响应Body参数 
| 参数         | 参数类型   | 描述                                                    |
|:---|:---|:---|
| error_code | String | **参数解释：** 错误码。  |
| error_msg  | String | **参数解释：** 错误信息。 |
   
#### 请求示例
```
/v4/repositories/123/import-merge-requests
{
  "iid" : 9223372036854776000,
  "source_uniq_key" : "string",
  "author_id" : 9223372036854776000,
  "state" : "string",
  "title" : "string",
  "description" : "string",
  "source_branch" : "string",
  "target_branch" : "string",
  "target_repository_id" : "string",
  "labels" : { },
  "created_at" : "string",
  "updated_at" : "string",
  "merged_at" : "string",
  "closed_at" : "string",
  "approvers" : [ { } ],
  "diff_refs" : {
    "base_sha" : "ssssssssshhhhhhhhhhaaaa",
    "start_sha" : "sssssssssshhhhhhhhhaaaa",
    "head_sha" : "sssssssssxxxxxxxxaaaa"
  },
  "squash" : true,
  "remove_source_branch" : true,
  "branch_is_deleted" : true,
  "fork" : true,
  "import_source_from" : "string"
}
```
#### 响应示例
**状态码：200**
OK
```
{
  "id" : 47858,
  "iid" : 1,
  "repository_id" : 2111983939,
  "title" : "新建文件 d",
  "description" : "merge \"ddd\" into \"master\"\n新建文件 d",
  "state" : "opened",
  "created_at" : "2024-11-30T17:47:53.000+08:00",
  "updated_at" : "2025-03-06T17:43:39.000+08:00",
  "source_branch" : "ddd",
  "target_branch" : "master",
  "is_source_branch_protected" : false,
  "devcloud_source_branch" : "ddd",
  "author" : {
    "id" : 9124,
    "name" : "example_name",
    "username" : "c369c68f1ff84679b5a8ed904d8bff1c",
    "state" : "active",
    "avatar_url" : "",
    "web_url" : "https://example.com/c369c68f1ff84679b5a8ed904d8bff1c",
    "nick_name" : "dev",
    "tenant_name" : "example_name"
  },
  "source_repository_id" : 2111983939,
  "target_repository_id" : 2111983939,
  "source_project_id" : "3e1f6634946144c2b1ccb46fb8152b8f",
  "target_project_id" : "3e1f6634946144c2b1ccb46fb8152b8f",
  "labels" : [ ],
  "work_in_progress" : false,
  "milestone" : null,
  "merge_when_build_succeeds" : false,
  "merge_status" : "can_be_merged",
  "sha" : "4f14849504009dd415b288f7ab21420933ecb516",
  "merge_commit_sha" : null,
  "subscribed" : true,
  "merged_by" : null,
  "merged_at" : null,
  "closed_by" : null,
  "closed_at" : null,
  "user_notes_count" : 0,
  "force_remove_source_branch" : false,
  "web_url" : "https://example.com/********/2111983939/1/mergedetail?source=ddd&target=master",
  "merge_request_diff" : {
    "id" : 70760,
    "state" : "collected",
    "merge_request_id" : 47858,
    "created_at" : "2024-11-30T17:47:53.000+08:00",
    "updated_at" : "2024-11-30T17:47:53.000+08:00",
    "base_commit_sha" : "c4f7b1bed9a869f64c90050311fad29ad4e40eb4",
    "real_size" : "1",
    "head_commit_sha" : "4f14849504009dd415b288f7ab21420933ecb516",
    "start_commit_sha" : "c4f7b1bed9a869f64c90050311fad29ad4e40eb4",
    "commits_count" : 1,
    "external_diff" : "diff-70760",
    "external_diff_store" : 1,
    "stored_externally" : true,
    "added_lines" : 1,
    "removed_lines" : 0
  },
  "merge_request_reviewers_count" : 0,
  "merge_request_review_count" : 0,
  "merge_request_reviewer_list" : [ ],
  "merge_request_assignee_list" : [ ],
  "notes" : 0,
  "codecheck_state" : 7,
  "codecheck_defect_count" : 0,
  "merge_request_related_work_items" : [ ],
  "diverged_commits_count" : 6,
  "moderation_result" : true,
  "moderation_time" : 0,
  "moderation_status" : 0,
  "is_use_temp_branch" : false,
  "review_mode" : "approval",
  "squash" : false,
  "approval_merge_request_approvers" : [ ],
  "approval_merge_request_reviewers" : [ ],
  "source_repository" : {
    "id" : 2111983939,
    "description" : "ddd",
    "name" : "dddd",
    "name_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f / dddd",
    "path" : "dddd",
    "path_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "created_at" : "2024-11-30T17:46:46.000+08:00",
    "updated_at" : "2024-11-30T17:46:46.000+08:00",
    "archived" : false,
    "is_kia" : false,
    "ssh_url_to_repo" : "git@example.com:3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "http_url_to_repo" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "web_url" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "readme_url" : null,
    "project_id" : "3e1f6634946144c2b1ccb46fb8152b8f",
    "project_name" : null,
    "develop_mode" : "normal",
    "moderation_result" : true
  },
  "target_repository" : {
    "id" : 2111983939,
    "description" : "ddd",
    "name" : "dddd",
    "name_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f / dddd",
    "path" : "dddd",
    "path_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "created_at" : "2024-11-30T17:46:46.000+08:00",
    "updated_at" : "2024-11-30T17:46:46.000+08:00",
    "archived" : false,
    "is_kia" : false,
    "ssh_url_to_repo" : "git@example.com:3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "http_url_to_repo" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "web_url" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "readme_url" : null,
    "project_id" : "3e1f6634946144c2b1ccb46fb8152b8f",
    "project_name" : null,
    "develop_mode" : "normal",
    "moderation_result" : true
  },
  "is_source_branch_exist" : true,
  "merge_request_type" : "MergeRequest",
  "squash_commit_message" : null,
  "auto_merge" : false,
  "merge_error" : null,
  "json_merge_error" : null,
  "rebase_in_progress" : false
}
```
**状态码：401**
Unauthorized
```
{
  "error_code" : "DEV.00000003",
  "error_msg" : "认证信息过期"
}
```
#### SDK代码示例
SDK代码示例如下。
#### Java
```
package com.huaweicloud.sdk.test;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.codeartsrepo.v4.region.CodeArtsRepoRegion;
import com.huaweicloud.sdk.codeartsrepo.v4.*;
import com.huaweicloud.sdk.codeartsrepo.v4.model.*;
import java.util.List;
import java.util.ArrayList;
public class ImportMergeRequestSolution {
    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);
        CodeArtsRepoClient client = CodeArtsRepoClient.newBuilder()
                .withCredential(auth)
                .withRegion(CodeArtsRepoRegion.valueOf("<YOUR REGION>"))
                .build();
        ImportMergeRequestRequest request = new ImportMergeRequestRequest();
        request.withRepositoryId({repository_id});
        ImportMrParamsDto body = new ImportMrParamsDto();
        List<ApproverParamDto> listbodyApprovers = new ArrayList<>();
        body.withImportSourceFrom("string");
        body.withFork(true);
        body.withBranchIsDeleted(true);
        body.withRemoveSourceBranch(true);
        body.withSquash(true);
        body.withApprovers(listbodyApprovers);
        body.withClosedAt("string");
        body.withMergedAt("string");
        body.withUpdatedAt("string");
        body.withCreatedAt("string");
        body.withLabels(new Object());
        body.withTargetRepositoryId("string");
        body.withTargetBranch("string");
        body.withSourceBranch("string");
        body.withDescription("string");
        body.withTitle("string");
        body.withState(ImportMrParamsDto.StateEnum.fromValue("string"));
        body.withAuthorId(9223372036854776000);
        body.withSourceUniqKey("string");
        body.withIid(9223372036854776000);
        request.withBody(body);
        try {
            ImportMergeRequestResponse response = client.importMergeRequest(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
```
#### Python
```
# coding: utf-8
import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcodeartsrepo.v4.region.codeartsrepo_region import CodeArtsRepoRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcodeartsrepo.v4 import *
if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    credentials = BasicCredentials(ak, sk)
    client = CodeArtsRepoClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CodeArtsRepoRegion.value_of("<YOUR REGION>")) \
        .build()
    try:
        request = ImportMergeRequestRequest()
        request.repository_id = {repository_id}
        listApproversbody = []
        request.body = ImportMrParamsDto(
            import_source_from="string",
            fork=True,
            branch_is_deleted=True,
            remove_source_branch=True,
            squash=True,
            approvers=listApproversbody,
            closed_at="string",
            merged_at="string",
            updated_at="string",
            created_at="string",
            labels={},
            target_repository_id="string",
            target_branch="string",
            source_branch="string",
            description="string",
            title="string",
            state="string",
            author_id=9223372036854776000,
            source_uniq_key="string",
            iid=9223372036854776000
        )
        response = client.import_merge_request(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
```
#### Go
```
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    codeartsrepo "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codeartsrepo/v4/region"
)
func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    hcClient, err := codeartsrepo.CodeArtsRepoClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    client := codeartsrepo.NewCodeArtsRepoClient(hcClient)
    request := &model.ImportMergeRequestRequest{}
request.RepositoryId = int32({repository_id})
    }
importSourceFromImportMrParamsDto:= "string"
forkImportMrParamsDto:= true
branchIsDeletedImportMrParamsDto:= true
removeSourceBranchImportMrParamsDto:= true
squashImportMrParamsDto:= true
closedAtImportMrParamsDto:= "string"
mergedAtImportMrParamsDto:= "string"
updatedAtImportMrParamsDto:= "string"
createdAtImportMrParamsDto:= "string"
var labelsImportMrParamsDto interface{} = make(map[string]string)
descriptionImportMrParamsDto:= "string"
titleImportMrParamsDto:= "string"
authorIdImportMrParamsDto:= int32(9223372036854776000)
request.Body = &model.ImportMrParamsDto{
ImportSourceFrom: &importSourceFromImportMrParamsDto,
Fork: &forkImportMrParamsDto,
BranchIsDeleted: &branchIsDeletedImportMrParamsDto,
RemoveSourceBranch: &removeSourceBranchImportMrParamsDto,
Squash: &squashImportMrParamsDto,
Approvers: &listApproversbody,
ClosedAt: &closedAtImportMrParamsDto,
MergedAt: &mergedAtImportMrParamsDto,
UpdatedAt: &updatedAtImportMrParamsDto,
CreatedAt: &createdAtImportMrParamsDto,
Labels: &labelsImportMrParamsDto,
TargetRepositoryId: "string",
TargetBranch: "string",
SourceBranch: "string",
Description: &descriptionImportMrParamsDto,
Title: &titleImportMrParamsDto,
State: model.GetImportMrParamsDtoStateEnum().STRING,
AuthorId: &authorIdImportMrParamsDto,
SourceUniqKey: "string",
Iid: int32(9223372036854776000),
}
response, err := client.ImportMergeRequest(request)
if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
```
#### 更多
更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CodeArtsRepo/sdk?api=ImportMergeRequest&version=v4)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述           |
|:---|:---|
| 200 | OK           |
| 401 | Unauthorized |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-codeartsrepo/ErrorCode.html)。
