多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Projects API > 原文:[https://docs.gitlab.com/ee/api/projects.html](https://docs.gitlab.com/ee/api/projects.html) * [Project visibility level](#project-visibility-level) * [Project merge method](#project-merge-method) * [List all projects](#list-all-projects) * [Pagination limits](#pagination-limits) * [List user projects](#list-user-projects) * [List projects starred by a user](#list-projects-starred-by-a-user) * [Get single project](#get-single-project) * [Get project users](#get-project-users) * [Get project events](#get-project-events) * [Create project](#create-project) * [Create project for user](#create-project-for-user) * [Edit project](#edit-project) * [Fork project](#fork-project) * [List Forks of a project](#list-forks-of-a-project) * [Star a project](#star-a-project) * [Unstar a project](#unstar-a-project) * [List Starrers of a project](#list-starrers-of-a-project) * [Languages](#languages) * [Archive a project](#archive-a-project) * [Unarchive a project](#unarchive-a-project) * [Remove project](#remove-project) * [Restore project marked for deletion](#restore-project-marked-for-deletion-premium) * [Upload a file](#upload-a-file) * [Share project with group](#share-project-with-group) * [Delete a shared project link within a group](#delete-a-shared-project-link-within-a-group) * [Hooks](#hooks) * [List project hooks](#list-project-hooks) * [Get project hook](#get-project-hook) * [Add project hook](#add-project-hook) * [Edit project hook](#edit-project-hook) * [Delete project hook](#delete-project-hook) * [Fork relationship](#fork-relationship) * [Create a forked from/to relation between existing projects](#create-a-forked-fromto-relation-between-existing-projects) * [Delete an existing forked from relationship](#delete-an-existing-forked-from-relationship) * [Search for projects by name](#search-for-projects-by-name) * [Start the Housekeeping task for a Project](#start-the-housekeeping-task-for-a-project) * [Push Rules](#push-rules-starter) * [Get project push rules](#get-project-push-rules) * [Add project push rule](#add-project-push-rule) * [Edit project push rule](#edit-project-push-rule) * [Delete project push rule](#delete-project-push-rule) * [Transfer a project to a new namespace](#transfer-a-project-to-a-new-namespace) * [Branches](#branches) * [Project Import/Export](#project-importexport) * [Project members](#project-members) * [Start the pull mirroring process for a Project](#start-the-pull-mirroring-process-for-a-project-starter) * [Project badges](#project-badges) * [Issue and merge request description templates](#issue-and-merge-request-description-templates) * [Download snapshot of a Git repository](#download-snapshot-of-a-git-repository) # Projects API[](#projects-api "Permalink") ## Project visibility level[](#project-visibility-level "Permalink") GitLab 中的项目可以是私有的,内部的或公共的. 这由项目中的`visibility`字段确定. 项目可见性级别的值为: * `private` :必须为每个用户显式授予项目访问权限. * `internal` :任何登录的用户都可以克隆该项目. * `public` :无需任何身份验证即可访问该项目. ## Project merge method[](#project-merge-method "Permalink") `merge_method`当前有三个选项可供选择: * `merge` :为每个合并创建一个合并提交,只要没有冲突就允许合并. * `rebase_merge` :为每个合并创建一个合并提交,但是仅当可能进行快速合并时才允许合并. 这样,您可以确保在合并到目标分支后,如果此合并请求将生成,则该请求也将生成. * `ff` :没有创建合并提交,并且所有合并都被快速转发,这意味着仅当分支可以被快速转发时才允许合并. ## List all projects[](#list-all-projects "Permalink") 获取已认证用户跨 GitLab 的所有可见项目的列表. 在未经身份验证的情况下访问时,仅返回带有"简单"字段的公共项目. ``` GET /projects ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `archived` | boolean | no | 受存档状态限制 | | `visibility` | string | no | 受`public` , `internal`或`private`可见性的限制 | | `order_by` | string | no | 返回按`id` , `name` , `path` , `created_at` , `updated_at`或`last_activity_at`字段排序的项目. 只有管​​理员可以使用`repository_size` , `storage_size`或`wiki_size`字段. 默认为`created_at` | | `sort` | string | no | 返回按`asc`或`desc`顺序排序的项目. 默认为`desc` | | `search` | string | no | 返回符合搜索条件的项目列表 | | `search_namespaces` | boolean | no | 匹配搜索条件时包括祖先名称空间. 默认为`false` | | `simple` | boolean | no | 仅返回每个项目的有限字段. 这是没有身份验证的无操作操作,因为这样*只会*返回简单的字段. | | `owned` | boolean | no | 受当前用户明确拥有的项目限制 | | `membership` | boolean | no | 受当前用户是其成员的项目的限制 | | `starred` | boolean | no | 受当前用户加注星标的项目限制 | | `statistics` | boolean | no | 包括项目统计 | | `with_custom_attributes` | boolean | no | 在响应中包括[自定义属性](custom_attributes.html) (仅管理员) | | `with_issues_enabled` | boolean | no | 受启用的问题限制功能 | | `with_merge_requests_enabled` | boolean | no | 通过启用的合并请求限制功能 | | `with_programming_language` | string | no | 受使用给定编程语言的项目限制 | | `wiki_checksum_failed` | boolean | no | 限制维基校验和计算失败的项目(在[GitLab Premium](https://about.gitlab.com/pricing/) 11.2 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/6137) ) | | `repository_checksum_failed` | boolean | no | 限制存储库校验和计算失败的项目(在[GitLab Premium](https://about.gitlab.com/pricing/) 11.2 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/6137) ) | | `min_access_level` | integer | no | 受当前用户的最小[访问权限](members.html)限制 | | `id_after` | integer | no | 将结果限制为 ID 大于指定 ID 的项目 | | `id_before` | integer | no | 将结果限制为 ID 小于指定 ID 的项目 | | `last_activity_after` | datetime | no | 在指定时间后,将结果限制为具有 last_activity 的项目. 格式:ISO 8601 YYYY-MM-DDTHH:MM:SSZ | | `last_activity_before` | datetime | no | 将结果限制为在指定时间之前具有 last_activity 的项目. 格式:ISO 8601 YYYY-MM-DDTHH:MM:SSZ | | `repository_storage` | string | no | 将结果限制为存储在 repository_storage 上的项目. 仅适用于管理员. | **注意:**此端点支持所选`order_by`选项的[键集分页](README.html#keyset-based-pagination) . 当`simple=true`或用户未经身份验证时,这将返回如下内容: ``` [ { "id": 4, "description": null, "default_branch": "master", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git", "web_url": "http://example.com/diaspora/diaspora-client", "readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md", "tag_list": [ "example", "disapora client" ], "name": "Diaspora Client", "name_with_namespace": "Diaspora / Diaspora Client", "path": "diaspora-client", "path_with_namespace": "diaspora/diaspora-client", "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "forks_count": 0, "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png", "star_count": 0, }, { "id": 6, "description": null, "default_branch": "master", ... ``` 当用户通过身份验证且未设置`simple` ,将返回以下内容: ``` [ { "id": 4, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git", "web_url": "http://example.com/diaspora/diaspora-client", "readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md", "tag_list": [ "example", "disapora client" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Client", "name_with_namespace": "Diaspora / Diaspora Client", "path": "diaspora-client", "path_with_namespace": "diaspora/diaspora-client", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": false, "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png", "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "marked_for_deletion_at": "2020-04-03", // Deprecated and will be removed in API v5 in favor of marked_for_deletion_on "marked_for_deletion_on": "2020-04-03", "statistics": { "commit_count": 37, "storage_size": 1038090, "repository_size": 1038090, "wiki_size" : 0, "lfs_objects_size": 0, "job_artifacts_size": 0, "packages_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" }, }, { "id": 6, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:brightbox/puppet.git", "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "readme_url": "http://example.com/brightbox/puppet/blob/master/README.md", "tag_list": [ "example", "puppet" ], "owner": { "id": 4, "name": "Brightbox", "created_at": "2013-09-30T13:46:02Z" }, "name": "Puppet", "name_with_namespace": "Brightbox / Puppet", "path": "puppet", "path_with_namespace": "brightbox/puppet", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 4, "name": "Brightbox", "path": "brightbox", "kind": "group", "full_path": "brightbox" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": false, "avatar_url": null, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "ci_default_git_depth": 0, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "auto_devops_enabled": true, "auto_devops_deploy_strategy": "continuous", "repository_storage": "default", "approvals_before_merge": 0, "mirror": false, "mirror_user_id": 45, "mirror_trigger_builds": false, "only_mirror_protected_branches": false, "mirror_overwrites_diverged_branches": false, "external_authorization_classification_label": null, "packages_enabled": true, "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, "repository_size": 2066080, "wiki_size" : 0, "lfs_objects_size": 0, "job_artifacts_size": 0, "packages_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ] ``` **注意:**对于使用 GitLab [Silver,Premium 或更高版本](https://about.gitlab.com/pricing/)的用户[,](https://about.gitlab.com/pricing/)已不推荐使用`marked_for_deletion_at`属性,并将在 API v5 中将其删除,以支持`marked_for_deletion_on`属性. 在 GitLab 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` [ { "id": 4, "description": null, "approvals_before_merge": 0, ... } ] ``` 您可以使用以下[自定义属性](custom_attributes.html)进行过滤: ``` GET /projects?custom_attributes[key]=value&custom_attributes[other_key]=other_value ``` ### Pagination limits[](#pagination-limits "Permalink") 从 GitLab 13.0 开始, [基于偏移量的分页](README.html#offset-based-pagination)将被[限制为 50,000 条记录](https://gitlab.com/gitlab-org/gitlab/-/issues/34565) . 要检索超出此限制的项目,将需要进行[键集分页](README.html#keyset-based-pagination) . 请注意,键集分页仅支持`order_by=id` . 其他排序选项不可用. ## List user projects[](#list-user-projects "Permalink") 获取给定用户拥有的可见项目的列表. 在未经身份验证的情况下访问时,仅返回公共项目. ``` GET /users/:user_id/projects ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `user_id` | string | yes | 用户的 ID 或用户名 | | `archived` | boolean | no | 受存档状态限制 | | `visibility` | string | no | 受`public` , `internal`或`private`可见性的限制 | | `order_by` | string | no | 返回按`id` , `name` , `path` , `created_at` , `updated_at`或`last_activity_at`字段排序的项目. 默认为`created_at` | | `sort` | string | no | 返回按`asc`或`desc`顺序排序的项目. 默认为`desc` | | `search` | string | no | 返回符合搜索条件的项目列表 | | `simple` | boolean | no | 仅返回每个项目的有限字段. 这是没有身份验证的无操作操作,因为这样*只会*返回简单的字段. | | `owned` | boolean | no | 受当前用户明确拥有的项目限制 | | `membership` | boolean | no | 受当前用户是其成员的项目的限制 | | `starred` | boolean | no | Limit by projects starred by the current user | | `statistics` | boolean | no | 包括项目统计 | | `with_custom_attributes` | boolean | no | 在响应中包括[自定义属性](custom_attributes.html) (仅管理员) | | `with_issues_enabled` | boolean | no | 受启用的问题限制功能 | | `with_merge_requests_enabled` | boolean | no | 通过启用的合并请求限制功能 | | `with_programming_language` | string | no | 受使用给定编程语言的项目限制 | | `min_access_level` | integer | no | 受当前用户的最小[访问权限](members.html)限制 | | `id_after` | integer | no | 将结果限制为 ID 大于指定 ID 的项目 | | `id_before` | integer | no | 将结果限制为 ID 小于指定 ID 的项目 | **注意:**此端点支持所选`order_by`选项的[键集分页](README.html#keyset-based-pagination) . ``` [ { "id": 4, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git", "web_url": "http://example.com/diaspora/diaspora-client", "readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md", "tag_list": [ "example", "disapora client" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Client", "name_with_namespace": "Diaspora / Diaspora Client", "path": "diaspora-client", "path_with_namespace": "diaspora/diaspora-client", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": false, "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png", "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "marked_for_deletion_at": "2020-04-03", // Deprecated and will be removed in API v5 in favor of marked_for_deletion_on "marked_for_deletion_on": "2020-04-03", "statistics": { "commit_count": 37, "storage_size": 1038090, "repository_size": 1038090, "wiki_size" : 0, "lfs_objects_size": 0, "job_artifacts_size": 0, "packages_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } }, { "id": 6, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:brightbox/puppet.git", "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "readme_url": "http://example.com/brightbox/puppet/blob/master/README.md", "tag_list": [ "example", "puppet" ], "owner": { "id": 4, "name": "Brightbox", "created_at": "2013-09-30T13:46:02Z" }, "name": "Puppet", "name_with_namespace": "Brightbox / Puppet", "path": "puppet", "path_with_namespace": "brightbox/puppet", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 4, "name": "Brightbox", "path": "brightbox", "kind": "group", "full_path": "brightbox" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": false, "avatar_url": null, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "ci_default_git_depth": 0, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "auto_devops_enabled": true, "auto_devops_deploy_strategy": "continuous", "repository_storage": "default", "approvals_before_merge": 0, "mirror": false, "mirror_user_id": 45, "mirror_trigger_builds": false, "only_mirror_protected_branches": false, "mirror_overwrites_diverged_branches": false, "external_authorization_classification_label": null, "packages_enabled": true, "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, "repository_size": 2066080, "wiki_size" : 0, "lfs_objects_size": 0, "job_artifacts_size": 0, "packages_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ] ``` ## List projects starred by a user[](#list-projects-starred-by-a-user "Permalink") 获取给定用户拥有的可见项目的列表. 在未经身份验证的情况下访问时,仅返回公共项目. ``` GET /users/:user_id/starred_projects ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `user_id` | string | yes | 用户的 ID 或用户名. | | `archived` | boolean | no | 受存档状态限制. | | `visibility` | string | no | 受`public` , `internal`或`private`可见性的限制. | | `order_by` | string | no | 返回按`id` , `name` , `path` , `created_at` , `updated_at`或`last_activity_at`字段排序的项目. 默认值为`created_at` . | | `sort` | string | no | 返回按`asc`或`desc`顺序排序的项目. 默认为`desc` . | | `search` | string | no | 返回符合搜索条件的项目列表. | | `simple` | boolean | no | 仅返回每个项目的有限字段. 这是没有身份验证的无操作操作,因为*仅*返回简单字段. | | `owned` | boolean | no | 受当前用户明确拥有的项目限制. | | `membership` | boolean | no | 受当前用户所属项目的限制. | | `starred` | boolean | no | 受当前用户加注星标的项目限制. | | `statistics` | boolean | no | 包括项目统计信息. | | `with_custom_attributes` | boolean | no | 在响应中包括[自定义属性](custom_attributes.html) (仅管理员). | | `with_issues_enabled` | boolean | no | 受启用的问题限制功能. | | `with_merge_requests_enabled` | boolean | no | 通过启用的合并请求限制功能. | | `min_access_level` | integer | no | 受当前用户的最小[访问权限](members.html)限制. | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/5/starred_projects" ``` 响应示例: ``` [ { "id": 4, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git", "web_url": "http://example.com/diaspora/diaspora-client", "readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md", "tag_list": [ "example", "disapora client" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Client", "name_with_namespace": "Diaspora / Diaspora Client", "path": "diaspora-client", "path_with_namespace": "diaspora/diaspora-client", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": false, "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png", "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "statistics": { "commit_count": 37, "storage_size": 1038090, "repository_size": 1038090, "lfs_objects_size": 0, "job_artifacts_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } }, { "id": 6, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:brightbox/puppet.git", "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "readme_url": "http://example.com/brightbox/puppet/blob/master/README.md", "tag_list": [ "example", "puppet" ], "owner": { "id": 4, "name": "Brightbox", "created_at": "2013-09-30T13:46:02Z" }, "name": "Puppet", "name_with_namespace": "Brightbox / Puppet", "path": "puppet", "path_with_namespace": "brightbox/puppet", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 4, "name": "Brightbox", "path": "brightbox", "kind": "group", "full_path": "brightbox" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": false, "avatar_url": null, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "auto_devops_enabled": true, "auto_devops_deploy_strategy": "continuous", "repository_storage": "default", "approvals_before_merge": 0, "mirror": false, "mirror_user_id": 45, "mirror_trigger_builds": false, "only_mirror_protected_branches": false, "mirror_overwrites_diverged_branches": false, "external_authorization_classification_label": null, "packages_enabled": true, "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, "suggestion_commit_message": null, "statistics": { "commit_count": 12, "storage_size": 2066080, "repository_size": 2066080, "lfs_objects_size": 0, "job_artifacts_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ] ``` ## Get single project[](#get-single-project "Permalink") 获取一个特定的项目. 如果可以公开访问该项目,则无需身份验证即可访问该端点. ``` GET /projects/:id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `statistics` | boolean | no | 包括项目统计 | | `license` | boolean | no | 包括项目许可证数据 | | `with_custom_attributes` | boolean | no | 在响应中包括[自定义属性](custom_attributes.html) (仅管理员) | ``` { "id": 3, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "container_expiration_policy": { "cadence": "7d", "enabled": false, "keep_n": null, "older_than": null, "name_regex": null, // to be deprecated in GitLab 13.0 in favor of `name_regex_delete` "name_regex_delete": null, "name_regex_keep": null, "next_run_at": "2020-01-07T21:42:58.658Z" }, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora", "avatar_url": "http://localhost:3000/uploads/group/avatar/3/foo.jpg", "web_url": "http://localhost:3000/groups/diaspora" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": false, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE", "license": { "key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "nickname": "GNU LGPLv3", "html_url": "http://choosealicense.com/licenses/lgpl-3.0/", "source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt" }, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [ { "group_id": 4, "group_name": "Twitter", "group_full_path": "twitter", "group_access_level": 30 }, { "group_id": 3, "group_name": "Gitlab Org", "group_full_path": "gitlab-org", "group_access_level": 10 } ], "repository_storage": "default", "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "printing_merge_requests_link_enabled": true, "request_access_enabled": false, "merge_method": "merge", "auto_devops_enabled": true, "auto_devops_deploy_strategy": "continuous", "repository_storage": "default", "approvals_before_merge": 0, "mirror": false, "mirror_user_id": 45, "mirror_trigger_builds": false, "only_mirror_protected_branches": false, "mirror_overwrites_diverged_branches": false, "external_authorization_classification_label": null, "packages_enabled": true, "service_desk_enabled": false, "service_desk_address": null, "autoclose_referenced_issues": true, "suggestion_commit_message": null, "marked_for_deletion_at": "2020-04-03", // Deprecated and will be removed in API v5 in favor of marked_for_deletion_on "marked_for_deletion_on": "2020-04-03", "compliance_frameworks": [ "sox" ], "statistics": { "commit_count": 37, "storage_size": 1038090, "repository_size": 1038090, "wiki_size" : 0, "lfs_objects_size": 0, "job_artifacts_size": 0, "packages_size": 0 }, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ``` 在 GitLab 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 3, "description": null, "approvals_before_merge": 0, ... } ``` **注意** :GitLab 11.11 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/27427)了`namespace`上的`web_url`和`avatar_url`属性. 如果项目是 fork,并且您提供了有效的令牌进行身份验证,则`forked_from_project`字段将出现在响应中. ``` { "id":3, ... "forked_from_project":{ "id":13083, "description":"GitLab Community Edition", "name":"GitLab Community Edition", "name_with_namespace":"GitLab.org / GitLab Community Edition", "path":"gitlab-foss", "path_with_namespace":"gitlab-org/gitlab-foss", "created_at":"2013-09-26T06:02:36.000Z", "default_branch":"master", "tag_list":[], "ssh_url_to_repo":"git@gitlab.com:gitlab-org/gitlab-foss.git", "http_url_to_repo":"https://gitlab.com/gitlab-org/gitlab-foss.git", "web_url":"https://gitlab.com/gitlab-org/gitlab-foss", "avatar_url":"https://assets.gitlab-static.net/uploads/-/system/project/avatar/13083/logo-extra-whitespace.png", "license_url": "https://gitlab.com/gitlab-org/gitlab/blob/master/LICENSE", "license": { "key": "mit", "name": "MIT License", "nickname": null, "html_url": "http://choosealicense.com/licenses/mit/", "source_url": "https://opensource.org/licenses/MIT", }, "star_count":3812, "forks_count":3561, "last_activity_at":"2018-01-02T11:40:26.570Z", "namespace": { "id": 72, "name": "GitLab.org", "path": "gitlab-org", "kind": "group", "full_path": "gitlab-org", "parent_id": null } } ... } ``` ## Get project users[](#get-project-users "Permalink") 获取项目的用户列表. ``` GET /projects/:id/users ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `search` | string | no | 搜索特定用户 | | `skip_users` | 整数数组 | no | 筛选出具有指定 ID 的用户 | ``` [ { "id": 1, "username": "john_smith", "name": "John Smith", "state": "active", "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg", "web_url": "http://localhost:3000/john_smith" }, { "id": 2, "username": "jack_smith", "name": "Jack Smith", "state": "blocked", "avatar_url": "http://gravatar.com/../e32131cd8.jpeg", "web_url": "http://localhost:3000/jack_smith" } ] ``` ## Get project events[](#get-project-events "Permalink") 请参考[Events API 文档](events.html#list-a-projects-visible-events) . ## Create project[](#create-project "Permalink") 创建一个经过身份验证的用户拥有的新项目. ``` POST /projects ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `name` | string | 是,如果未提供路径 | 新项目的名称. 如果未提供,则等于路径. | | `path` | string | 是,如果未提供名称 | 新项目的存储库名称. 如果未提供,则根据名称生成(生成的小写字母加短划线). | | `namespace_id` | integer | no | 新项目的命名空间(默认为当前用户的命名空间) | | `default_branch` | string | no | `master`默认 | | `description` | string | no | 简短的项目说明 | | `issues_enabled` | boolean | no | (不建议使用)为此项目启用问题. 改用`issues_access_level` | | `merge_requests_enabled` | boolean | no | (不建议使用)为此项目启用合并请求. 改用`merge_requests_access_level` | | `jobs_enabled` | boolean | no | (不建议使用)为此项目启用作业. 改用`builds_access_level` | | `wiki_enabled` | boolean | no | (已弃用)为此项目启用 Wiki. 改用`wiki_access_level` | | `snippets_enabled` | boolean | no | (不建议使用)为此项目启用摘要. 请改用`snippets_access_level` | | `issues_access_level` | string | no | `disabled` , `private`或`enabled` | | `repository_access_level` | string | no | `disabled` , `private`或`enabled` | | `merge_requests_access_level` | string | no | `disabled` , `private`或`enabled` | | `forking_access_level` | string | no | `disabled` , `private`或`enabled` | | `builds_access_level` | string | no | `disabled` , `private`或`enabled` | | `wiki_access_level` | string | no | `disabled` , `private`或`enabled` | | `snippets_access_level` | string | no | `disabled` , `private`或`enabled` | | `pages_access_level` | string | no | `disabled` , `private` , `enabled`或`public` | | `emails_disabled` | boolean | no | 禁用电子邮件通知 | | `show_default_award_emojis` | boolean | no | 显示默认的奖励表情符号 | | `resolve_outdated_diff_discussions` | boolean | no | 自动解决合并请求差异讨论(通过推送更改) | | `container_registry_enabled` | boolean | no | 为该项目启用容器注册表 | | `container_expiration_policy_attributes` | hash | no | 更新此项目的图像过期策略. 接受: `cadence` (字符串), `keep_n` (字符串), `older_than` (字符串), `name_regex` (字符串), `name_regex_delete` (字符串), `name_regex_keep` (字符串), `enabled` (布尔值) | | `shared_runners_enabled` | boolean | no | 为此项目启用共享跑步者 | | `visibility` | string | no | See [project visibility level](#project-visibility-level) | | `import_url` | string | no | 从中导入存储库的 URL | | `public_builds` | boolean | no | 如果为`true` ,则非项目成员可以查看作业 | | `only_allow_merge_if_pipeline_succeeds` | boolean | no | 设置是否只能将合并请求与成功的作业合并 | | `allow_merge_on_skipped_pipeline` | boolean | no | 设置是否可以将合并请求与跳过的作业合并 | | `only_allow_merge_if_all_discussions_are_resolved` | boolean | no | 设置是否仅在所有讨论都解决后才能合并合并请求 | | `merge_method` | string | no | 设置使用的[合并方法](#project-merge-method) | | `autoclose_referenced_issues` | boolean | no | 设置是否自动关闭默认分支上的引用问题 | | `remove_source_branch_after_merge` | boolean | no | 默认情况下,为所有新合并请求启用" `Delete source branch`选项 | | `lfs_enabled` | boolean | no | 启用 LFS | | `request_access_enabled` | boolean | no | 允许用户请求成员访问 | | `tag_list` | array | no | 项目标签列表; 放置标签数组,这些标签应最终分配给项目 | | `avatar` | mixed | no | 项目头像的图像文件 | | `printing_merge_request_link_enabled` | boolean | no | 从命令行推送时显示创建/查看合并请求的链接 | | `build_git_strategy` | string | no | Git 策略. 默认为`fetch` | | `build_timeout` | integer | no | 作业可以运行的最长时间(以分钟为单位)(以秒为单位) | | `auto_cancel_pending_pipelines` | string | no | 自动取消挂起的管道(注意:这不是布尔值,但已启用/禁用 | | `build_coverage_regex` | string | no | 测试覆盖率解析 | | `ci_config_path` | string | no | CI 配置文件的路径 | | `auto_devops_enabled` | boolean | no | 为该项目启用 Auto DevOps | | `auto_devops_deploy_strategy` | string | no | 自动部署策略( `continuous` , `manual`或`timed_incremental` ) | | `repository_storage` | string | no | 存储库位于哪个存储分片上. 仅适用于管理员 | | `approvals_before_merge` | integer | no | 默认情况下,应有多少个批准者批准合并请求 | | `external_authorization_classification_label` | string | no | 项目的分类标签 | | `mirror` | boolean | no | 在项目中启用拉镜像 | | `mirror_trigger_builds` | boolean | no | 拉镜像触发器构建 | | `initialize_with_readme` | boolean | no | 默认为`false` | | `template_name` | string | no | 不使用`use_custom_template` ,为[内置项目模板的名称](../gitlab-basics/create-project.html#built-in-templates) . 与`use_custom_template`使用时,自定义项目模板的名称 | | `template_project_id` | integer | no | 与`use_custom_template`使用时,是自定义项目模板的项目 ID. 这比使用`template_name`更可取,因为`template_name`可能含糊. | | `use_custom_template` | boolean | no | 使用自定义[实例](../user/admin_area/custom_project_templates.html)或[组](../user/group/custom_project_templates.html) (带有`group_with_project_templates_id` )项目模板 | | `group_with_project_templates_id` | integer | no | 对于组级别的自定义模板,指定所有自定义项目模板所源自的组的 ID. 将实例级模板留空. 要求`use_custom_template`为 true | | `packages_enabled` | boolean | no | 启用或禁用软件包存储库功能 | **注意:**如果您的 HTTP 存储库不可公开访问,请将身份验证信息添加到 URL: `https://username:password@gitlab.company.com/group/project.git` ,其中`password`是启用了`api`范围的公共访问密钥. ## Create project for user[](#create-project-for-user "Permalink") 创建一个由指定用户拥有的新项目. 仅适用于管理员. ``` POST /projects/user/:user_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `user_id` | integer | yes | 项目所有者的用户标识 | | `name` | string | yes | 新项目的名称 | | `path` | string | no | 新项目的自定义存储库名称. 默认情况下根据名称生成 | | `namespace_id` | integer | no | Namespace for the new project (defaults to the current user’s namespace) | | `description` | string | no | 简短的项目说明 | | `issues_enabled` | boolean | no | (不建议使用)为此项目启用问题. 改用`issues_access_level` | | `merge_requests_enabled` | boolean | no | (不建议使用)为此项目启用合并请求. 改用`merge_requests_access_level` | | `jobs_enabled` | boolean | no | (不建议使用)为此项目启用作业. 改用`builds_access_level` | | `wiki_enabled` | boolean | no | (已弃用)为此项目启用 Wiki. 改用`wiki_access_level` | | `snippets_enabled` | boolean | no | (不建议使用)为此项目启用摘要. 请改用`snippets_access_level` | | `issues_access_level` | string | no | `disabled` , `private`或`enabled` | | `repository_access_level` | string | no | `disabled` , `private`或`enabled` | | `merge_requests_access_level` | string | no | `disabled` , `private`或`enabled` | | `forking_access_level` | string | no | `disabled` , `private`或`enabled` | | `builds_access_level` | string | no | `disabled` , `private`或`enabled` | | `wiki_access_level` | string | no | `disabled` , `private`或`enabled` | | `snippets_access_level` | string | no | `disabled` , `private`或`enabled` | | `pages_access_level` | string | no | `disabled` , `private` , `enabled`或`public` | | `emails_disabled` | boolean | no | 禁用电子邮件通知 | | `show_default_award_emojis` | boolean | no | 显示默认的奖励表情符号 | | `resolve_outdated_diff_discussions` | boolean | no | 自动解决合并请求差异讨论(通过推送更改) | | `container_registry_enabled` | boolean | no | 为该项目启用容器注册表 | | `shared_runners_enabled` | boolean | no | 为此项目启用共享跑步者 | | `visibility` | string | no | See [project visibility level](#project-visibility-level) | | `import_url` | string | no | 从中导入存储库的 URL | | `public_builds` | boolean | no | 如果为`true` ,则非项目成员可以查看作业 | | `only_allow_merge_if_pipeline_succeeds` | boolean | no | 设置是否只能将合并请求与成功的作业合并 | | `allow_merge_on_skipped_pipeline` | boolean | no | 设置是否可以将合并请求与跳过的作业合并 | | `only_allow_merge_if_all_discussions_are_resolved` | boolean | no | 设置是否仅在所有讨论都解决后才能合并合并请求 | | `merge_method` | string | no | 设置使用的[合并方法](#project-merge-method) | | `autoclose_referenced_issues` | boolean | no | 设置是否自动关闭默认分支上的引用问题 | | `suggestion_commit_message` | string | no | 用于应用合并请求建议的提交消息 | | `remove_source_branch_after_merge` | boolean | no | 默认情况下,为所有新合并请求启用" `Delete source branch`选项 | | `lfs_enabled` | boolean | no | 启用 LFS | | `request_access_enabled` | boolean | no | 允许用户请求成员访问 | | `tag_list` | array | no | 项目标签列表; 放置标签数组,这些标签应最终分配给项目 | | `avatar` | mixed | no | 项目头像的图像文件 | | `printing_merge_request_link_enabled` | boolean | no | 从命令行推送时显示创建/查看合并请求的链接 | | `build_git_strategy` | string | no | Git 策略. 默认为`fetch` | | `build_timeout` | integer | no | 作业可以运行的最长时间(以分钟为单位)(以秒为单位) | | `auto_cancel_pending_pipelines` | string | no | 自动取消挂起的管道(注意:这不是布尔值,但已启用/禁用 | | `build_coverage_regex` | string | no | 测试覆盖率解析 | | `ci_config_path` | string | no | CI 配置文件的路径 | | `auto_devops_enabled` | boolean | no | 为该项目启用 Auto DevOps | | `auto_devops_deploy_strategy` | string | no | 自动部署策略( `continuous` , `manual`或`timed_incremental` ) | | `repository_storage` | string | no | 存储库位于哪个存储分片上. 仅适用于管理员 | | `approvals_before_merge` | integer | no | 默认情况下,应有多少个批准者批准合并请求 | | `external_authorization_classification_label` | string | no | 项目的分类标签 | | `mirror` | boolean | no | 在项目中启用拉镜像 | | `mirror_trigger_builds` | boolean | no | 拉镜像触发器构建 | | `initialize_with_readme` | boolean | no | 默认为`false` | | `template_name` | string | no | 不使用`use_custom_template` ,为[内置项目模板的名称](../gitlab-basics/create-project.html#built-in-templates) . 与`use_custom_template`使用时,自定义项目模板的名称 | | `use_custom_template` | boolean | no | Use either custom [instance](../user/admin_area/custom_project_templates.html) or [group](../user/group/custom_project_templates.html) (with `group_with_project_templates_id`) project template | | `group_with_project_templates_id` | integer | no | 对于组级别的自定义模板,指定所有自定义项目模板所源自的组的 ID. 将实例级模板留空. 要求`use_custom_template`为 true | | `packages_enabled` | boolean | no | 启用或禁用软件包存储库功能 | **注意:**如果您的 HTTP 存储库不可公开访问,请将身份验证信息添加到 URL: `https://username:password@gitlab.company.com/group/project.git` ,其中`password`是启用了`api`范围的公共访问密钥. ## Edit project[](#edit-project "Permalink") 更新现有项目. ``` PUT /projects/:id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `name` | string | no | 项目名称 | | `path` | string | no | 项目的自定义存储库名称. 默认情况下根据名称生成 | | `default_branch` | string | no | `master`默认 | | `description` | string | no | 简短的项目说明 | | `issues_enabled` | boolean | no | (不建议使用)为此项目启用问题. 改用`issues_access_level` | | `merge_requests_enabled` | boolean | no | (不建议使用)为此项目启用合并请求. 改用`merge_requests_access_level` | | `jobs_enabled` | boolean | no | (不建议使用)为此项目启用作业. 改用`builds_access_level` | | `wiki_enabled` | boolean | no | (已弃用)为此项目启用 Wiki. 改用`wiki_access_level` | | `snippets_enabled` | boolean | no | (不建议使用)为此项目启用摘要. 请改用`snippets_access_level` | | `issues_access_level` | string | no | `disabled` , `private`或`enabled` | | `repository_access_level` | string | no | `disabled` , `private`或`enabled` | | `merge_requests_access_level` | string | no | `disabled` , `private`或`enabled` | | `forking_access_level` | string | no | `disabled` , `private`或`enabled` | | `builds_access_level` | string | no | `disabled` , `private`或`enabled` | | `wiki_access_level` | string | no | `disabled` , `private`或`enabled` | | `snippets_access_level` | string | no | `disabled` , `private`或`enabled` | | `pages_access_level` | string | no | `disabled` , `private` , `enabled`或`public` | | `emails_disabled` | boolean | no | 禁用电子邮件通知 | | `show_default_award_emojis` | boolean | no | 显示默认的奖励表情符号 | | `resolve_outdated_diff_discussions` | boolean | no | 自动解决合并请求差异讨论(通过推送更改) | | `container_registry_enabled` | boolean | no | 为该项目启用容器注册表 | | `container_expiration_policy_attributes` | hash | no | 更新此项目的图像过期策略. 接受: `cadence` (字符串), `keep_n` (字符串), `older_than` (字符串), `name_regex` (字符串), `name_regex_delete` (字符串), `name_regex_keep` (字符串), `enabled` (布尔值) | | `shared_runners_enabled` | boolean | no | 为此项目启用共享跑步者 | | `visibility` | string | no | See [project visibility level](#project-visibility-level) | | `import_url` | string | no | 从中导入存储库的 URL | | `public_builds` | boolean | no | 如果为`true` ,则非项目成员可以查看作业 | | `only_allow_merge_if_pipeline_succeeds` | boolean | no | 设置是否只能将合并请求与成功的作业合并 | | `allow_merge_on_skipped_pipeline` | boolean | no | 设置是否可以将合并请求与跳过的作业合并 | | `only_allow_merge_if_all_discussions_are_resolved` | boolean | no | 设置是否仅在所有讨论都解决后才能合并合并请求 | | `merge_method` | string | no | 设置使用的[合并方法](#project-merge-method) | | `autoclose_referenced_issues` | boolean | no | 设置是否自动关闭默认分支上的引用问题 | | `suggestion_commit_message` | string | no | 用于应用合并请求建议的提交消息 | | `remove_source_branch_after_merge` | boolean | no | 默认情况下,为所有新合并请求启用" `Delete source branch`选项 | | `lfs_enabled` | boolean | no | 启用 LFS | | `request_access_enabled` | boolean | no | 允许用户请求成员访问 | | `tag_list` | array | no | 项目标签列表; 放置标签数组,这些标签应最终分配给项目 | | `avatar` | mixed | no | 项目头像的图像文件 | | `build_git_strategy` | string | no | Git 策略. 默认为`fetch` | | `build_timeout` | integer | no | 作业可以运行的最长时间(以分钟为单位)(以秒为单位) | | `auto_cancel_pending_pipelines` | string | no | 自动取消挂起的管道(注意:这不是布尔值,但已启用/禁用 | | `build_coverage_regex` | string | no | 测试覆盖率解析 | | `ci_config_path` | string | no | CI 配置文件的路径 | | `ci_default_git_depth` | integer | no | [浅克隆的](../ci/pipelines/settings.html#git-shallow-clone)默认修订版本数 | | `auto_devops_enabled` | boolean | no | 为该项目启用 Auto DevOps | | `auto_devops_deploy_strategy` | string | no | 自动部署策略( `continuous` , `manual`或`timed_incremental` ) | | `repository_storage` | string | no | 存储库位于哪个存储分片上. 仅适用于管理员 | | `approvals_before_merge` | integer | no | How many approvers should approve merge request by default | | `external_authorization_classification_label` | string | no | 项目的分类标签 | | `mirror` | boolean | no | 在项目中启用拉镜像 | | `mirror_user_id` | integer | no | 用户负责拉镜事件周围的所有活动. 只能由管理员设置. | | `mirror_trigger_builds` | boolean | no | 拉镜像触发器构建 | | `only_mirror_protected_branches` | boolean | no | 仅镜像保护的分支 | | `mirror_overwrites_diverged_branches` | boolean | no | 拉镜将覆盖分散的分支 | | `packages_enabled` | boolean | no | 启用或禁用软件包存储库功能 | | `service_desk_enabled` | boolean | no | 启用或禁用服务台功能 | **注意:**如果您的 HTTP 存储库不可公开访问,请将身份验证信息添加到 URL: `https://username:password@gitlab.company.com/group/project.git` ,其中`password`是启用了`api`范围的公共访问密钥. ## Fork project[](#fork-project "Permalink") 将项目派生到已认证用户或提供的用户的用户名称空间中. 项目的分叉操作是异步的,并在后台作业中完成. 该请求将立即返回. 要确定项目的分支是否已完成,请查询`import_status`以获取新项目. ``` POST /projects/:id/fork ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `namespace` | integer/string | no | (不建议使用)项目将分叉到的名称空间的 ID 或路径 | | `namespace_id` | integer | no | 项目将分叉到的名称空间的 ID | | `namespace_path` | string | no | 项目将分叉到的名称空间的路径 | | `path` | string | no | 分叉后将分配给结果项目的路径 | | `name` | string | no | 分叉后将分配给结果项目的名称 | ## List Forks of a project[](#list-forks-of-a-project "Permalink") **注意:**此功能是在 GitLab 10.1 中引入的. 列出呼叫用户可访问的与指定项目具有已建立的分叉关系的项目 ``` GET /projects/:id/forks ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `archived` | boolean | no | 受存档状态限制 | | `visibility` | string | no | 受`public` , `internal`或`private`可见性的限制 | | `order_by` | string | no | 返回按`id` , `name` , `path` , `created_at` , `updated_at`或`last_activity_at`字段排序的项目. 默认为`created_at` | | `sort` | string | no | 返回按`asc`或`desc`顺序排序的项目. 默认为`desc` | | `search` | string | no | 返回符合搜索条件的项目列表 | | `simple` | boolean | no | 仅返回每个项目的有限字段. 这是没有身份验证的无操作操作,因为这样*只会*返回简单的字段. | | `owned` | boolean | no | 受当前用户明确拥有的项目限制 | | `membership` | boolean | no | 受当前用户是其成员的项目的限制 | | `starred` | boolean | no | 受当前用户加注星标的项目限制 | | `statistics` | boolean | no | 包括项目统计 | | `with_custom_attributes` | boolean | no | 在响应中包括[自定义属性](custom_attributes.html) (仅管理员) | | `with_issues_enabled` | boolean | no | 受启用的问题限制功能 | | `with_merge_requests_enabled` | boolean | no | 通过启用的合并请求限制功能 | | `min_access_level` | integer | no | 受当前用户的最小[访问权限](members.html)限制 | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/forks" ``` 响应示例: ``` [ { "id": 3, "description": null, "default_branch": "master", "visibility": "internal", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": true, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "shared_runners_enabled": true, "forks_count": 0, "star_count": 1, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ] ``` ## Star a project[](#star-a-project "Permalink") 明星给定的项目. 如果项目已加星标,则返回状态码`304` . ``` POST /projects/:id/star ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/star" ``` 响应示例: ``` { "id": 3, "description": null, "default_branch": "master", "visibility": "internal", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": true, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE", "license": { "key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "nickname": "GNU LGPLv3", "html_url": "http://choosealicense.com/licenses/lgpl-3.0/", "source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt" }, "shared_runners_enabled": true, "forks_count": 0, "star_count": 1, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ``` ## Unstar a project[](#unstar-a-project "Permalink") 取消给定项目的星标. 如果项目未加星标,则返回状态码`304` . ``` POST /projects/:id/unstar ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/unstar" ``` 响应示例: ``` { "id": 3, "description": null, "default_branch": "master", "visibility": "internal", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "archived": true, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE", "license": { "key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "nickname": "GNU LGPLv3", "html_url": "http://choosealicense.com/licenses/lgpl-3.0/", "source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt" }, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ``` ## List Starrers of a project[](#list-starrers-of-a-project "Permalink") 列出为指定项目加注星标的用户. ``` GET /projects/:id/starrers ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `search` | string | no | 搜索特定用户. | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/starrers" ``` 响应示例: ``` [ { "starred_since": "2019-01-28T14:47:30.642Z", "user": { "id": 1, "username": "jane_smith", "name": "Jane Smith", "state": "active", "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg", "web_url": "http://localhost:3000/jane_smith" } }, "starred_since": "2018-01-02T11:40:26.570Z", "user": { "id": 2, "username": "janine_smith", "name": "Janine Smith", "state": "blocked", "avatar_url": "http://gravatar.com/../e32131cd8.jpeg", "web_url": "http://localhost:3000/janine_smith" } ] ``` ## Languages[](#languages "Permalink") 获取具有百分比值的项目中使用的语言. ``` GET /projects/:id/languages ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/languages" ``` 响应示例: ``` { "Ruby": 66.69, "JavaScript": 22.98, "HTML": 7.91, "CoffeeScript": 2.42 } ``` ## Archive a project[](#archive-a-project "Permalink") 如果用户是该项目的管理员或项目所有者,则归档该项目. 此操作是幂等的,因此归档已归档的项目不会更改该项目. ``` POST /projects/:id/archive ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/archive" ``` 响应示例: ``` { "id": 3, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": true, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE", "license": { "key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "nickname": "GNU LGPLv3", "html_url": "http://choosealicense.com/licenses/lgpl-3.0/", "source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt" }, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ``` ## Unarchive a project[](#unarchive-a-project "Permalink") 如果用户是该项目的管理员或项目所有者,则取消归档该项目. 此操作是幂等的,因此取消存档未存档的项目不会更改该项目. ``` POST /projects/:id/unarchive ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/unarchive" ``` 响应示例: ``` { "id": 3, "description": null, "default_branch": "master", "visibility": "private", "ssh_url_to_repo": "git@example.com:diaspora/diaspora-project-site.git", "http_url_to_repo": "http://example.com/diaspora/diaspora-project-site.git", "web_url": "http://example.com/diaspora/diaspora-project-site", "readme_url": "http://example.com/diaspora/diaspora-project-site/blob/master/README.md", "tag_list": [ "example", "disapora project" ], "owner": { "id": 3, "name": "Diaspora", "created_at": "2013-09-30T13:46:02Z" }, "name": "Diaspora Project Site", "name_with_namespace": "Diaspora / Diaspora Project Site", "path": "diaspora-project-site", "path_with_namespace": "diaspora/diaspora-project-site", "issues_enabled": true, "open_issues_count": 1, "merge_requests_enabled": true, "jobs_enabled": true, "wiki_enabled": true, "snippets_enabled": false, "can_create_merge_request_in": true, "resolve_outdated_diff_discussions": false, "container_registry_enabled": false, "created_at": "2013-09-30T13:46:02Z", "last_activity_at": "2013-09-30T13:46:02Z", "creator_id": 3, "namespace": { "id": 3, "name": "Diaspora", "path": "diaspora", "kind": "group", "full_path": "diaspora" }, "import_status": "none", "import_error": null, "permissions": { "project_access": { "access_level": 10, "notification_level": 3 }, "group_access": { "access_level": 50, "notification_level": 3 } }, "archived": false, "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png", "license_url": "http://example.com/diaspora/diaspora-client/blob/master/LICENSE", "license": { "key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "nickname": "GNU LGPLv3", "html_url": "http://choosealicense.com/licenses/lgpl-3.0/", "source_url": "http://www.gnu.org/licenses/lgpl-3.0.txt" }, "shared_runners_enabled": true, "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, "allow_merge_on_skipped_pipeline": false, "only_allow_merge_if_all_discussions_are_resolved": false, "remove_source_branch_after_merge": false, "request_access_enabled": false, "merge_method": "merge", "autoclose_referenced_issues": true, "suggestion_commit_message": null, "_links": { "self": "http://example.com/api/v4/projects", "issues": "http://example.com/api/v4/projects/1/issues", "merge_requests": "http://example.com/api/v4/projects/1/merge_requests", "repo_branches": "http://example.com/api/v4/projects/1/repository_branches", "labels": "http://example.com/api/v4/projects/1/labels", "events": "http://example.com/api/v4/projects/1/events", "members": "http://example.com/api/v4/projects/1/members" } } ``` ## Remove project[](#remove-project "Permalink") 该端点: * 删除包含所有相关资源(问题,合并请求等)的项目. * 从[Premium 或 Silver](https://about.gitlab.com/pricing/)或更高级别的[GitLab 12.6](https://gitlab.com/gitlab-org/gitlab/-/issues/32935)开始,将项目标记为删除. 实际删除发生在[实例设置中](../user/admin_area/settings/visibility_and_access_controls.html#default-deletion-adjourned-period-premium-only)指定的天数之后. ``` DELETE /projects/:id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ## Restore project marked for deletion[](#restore-project-marked-for-deletion-premium "Permalink") 在 GitLab 12.6 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/32935) . 恢复标记为删除的项目. ``` POST /projects/:id/restore ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ## Upload a file[](#upload-a-file "Permalink") 将文件上载到指定的项目,以在发布或合并请求描述或注释中使用. ``` POST /projects/:id/uploads ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `file` | string | yes | 要上传的文件 | 要从文件系统上载文件,请使用`--form`参数. 这将导致 cURL 使用标题`Content-Type: multipart/form-data` . `file=`参数必须指向文件系统上的文件,并以`@`开头. 例如: ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "file=@dk.png" "https://gitlab.example.com/api/v4/projects/5/uploads" ``` Returned object: ``` { "alt": "dk", "url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png", "full_path": "/namespace1/project1/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png", "markdown": "![dk](/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png)" } ``` > **注意** :返回的`url`是相对于项目路径的. 返回的`full_path`是文件的绝对路径. 在 Markdown 上下文中,当使用`markdown`的格式时,链接会自动展开. ## Share project with group[](#share-project-with-group "Permalink") 允许与小组共享项目. ``` POST /projects/:id/share ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `group_id` | integer | yes | 与之共享的组的 ID | | `group_access` | integer | yes | 授予组的[权限级别](members.html) | | `expires_at` | string | no | ISO 8601 格式的股份到期日:2016-09-26 | ## Delete a shared project link within a group[](#delete-a-shared-project-link-within-a-group "Permalink") 从小组取消共享项目. 返回`204` ,成功则不返回任何内容. ``` DELETE /projects/:id/share/:group_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `group_id` | integer | yes | 组的 ID | ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/share/17" ``` ## Hooks[](#hooks "Permalink") 也称为 Project Hooks 和 Webhooks. 对于系统范围的[系统挂钩](system_hooks.html) ,这些是不同的. ### List project hooks[](#list-project-hooks "Permalink") 获取项目挂钩的列表. ``` GET /projects/:id/hooks ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ### Get project hook[](#get-project-hook "Permalink") 获取项目的特定挂钩. ``` GET /projects/:id/hooks/:hook_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `hook_id` | integer | yes | 项目挂钩的 ID | ``` { "id": 1, "url": "http://example.com/hook", "project_id": 3, "push_events": true, "push_events_branch_filter": "", "issues_events": true, "confidential_issues_events": true, "merge_requests_events": true, "tag_push_events": true, "note_events": true, "confidential_note_events": true, "job_events": true, "pipeline_events": true, "wiki_page_events": true, "enable_ssl_verification": true, "created_at": "2012-10-12T17:04:47Z" } ``` ### Add project hook[](#add-project-hook "Permalink") 将钩子添加到指定项目. ``` POST /projects/:id/hooks ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `url` | string | yes | 挂钩网址 | | `push_events` | boolean | no | 在推送事件上触发钩子 | | `push_events_branch_filter` | string | no | 触发推送事件上的钩子,仅用于匹配分支 | | `issues_events` | boolean | no | 触发问题事件挂钩 | | `confidential_issues_events` | boolean | no | 触发机密问题事件的钩子 | | `merge_requests_events` | boolean | no | 触发合并请求事件的钩子 | | `tag_push_events` | boolean | no | 触发标签推送事件的钩子 | | `note_events` | boolean | no | 在音符事件上触发钩子 | | `confidential_note_events` | boolean | no | 触发机密笔记事件的钩子 | | `job_events` | boolean | no | 触发工作事件挂钩 | | `pipeline_events` | boolean | no | 触发管道事件钩子 | | `wiki_page_events` | boolean | no | 触发 Wiki 事件的钩子 | | `enable_ssl_verification` | boolean | no | 触发挂钩时执行 SSL 验证 | | `token` | string | no | 用于验证收到的有效载荷的秘密令牌; 这将不会在响应中返回 | ### Edit project hook[](#edit-project-hook "Permalink") Edits a hook for a specified project. ``` PUT /projects/:id/hooks/:hook_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `hook_id` | integer | yes | 项目挂钩的 ID | | `url` | string | yes | 挂钩网址 | | `push_events` | boolean | no | 在推送事件上触发钩子 | | `push_events_branch_filter` | string | no | 触发推送事件上的钩子,仅用于匹配分支 | | `issues_events` | boolean | no | Trigger hook on issues events | | `confidential_issues_events` | boolean | no | 触发机密问题事件的钩子 | | `merge_requests_events` | boolean | no | 触发合并请求事件的钩子 | | `tag_push_events` | boolean | no | 触发标签推送事件的钩子 | | `note_events` | boolean | no | 在音符事件上触发钩子 | | `confidential_note_events` | boolean | no | 触发机密笔记事件的钩子 | | `job_events` | boolean | no | 触发工作事件挂钩 | | `pipeline_events` | boolean | no | 触发管道事件钩子 | | `wiki_events` | boolean | no | 触发 Wiki 事件的钩子 | | `enable_ssl_verification` | boolean | no | 触发挂钩时执行 SSL 验证 | | `token` | string | no | 用于验证收到的有效载荷的秘密令牌; 这将不会在响应中返回 | ### Delete project hook[](#delete-project-hook "Permalink") 从项目中删除一个钩子. 这是幂等方法,可以多次调用. 挂钩是否可用. ``` DELETE /projects/:id/hooks/:hook_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `hook_id` | integer | yes | 项目挂钩的 ID | 请注意,无论挂钩是否可用,JSON 响应都会有所不同. 如果项目挂钩在 JSON 响应中返回之前可用,或者返回空响应. ## Fork relationship[](#fork-relationship "Permalink") 允许修改现有项目之间的分支关系. 仅适用于项目所有者和管理员. ### Create a forked from/to relation between existing projects[](#create-a-forked-fromto-relation-between-existing-projects "Permalink") ``` POST /projects/:id/fork/:forked_from_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `forked_from_id` | ID | yes | 分叉的项目的 ID | ### Delete an existing forked from relationship[](#delete-an-existing-forked-from-relationship "Permalink") ``` DELETE /projects/:id/fork ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ## Search for projects by name[](#search-for-projects-by-name "Permalink") 通过名称搜索可通过身份验证的用户访问的项目. 如果可以公开访问该项目,则无需身份验证即可访问该端点. ``` GET /projects ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `search` | string | yes | 项目名称中包含的字符串 | | `order_by` | string | no | 返回按`id` , `name` , `created_at`或`last_activity_at`字段排序的请求 | | `sort` | string | no | 返回请求按`asc`或`desc`排序 | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects?search=test" ``` ## Start the Housekeeping task for a Project[](#start-the-housekeeping-task-for-a-project "Permalink") 在 GitLab 9.0 中引入. ``` POST /projects/:id/housekeeping ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目或 NAMESPACE / PROJECT_NAME 的 ID | ## Push Rules[](#push-rules-starter "Permalink") ### Get project push rules[](#get-project-push-rules "Permalink") 获取项目的推送规则. ``` GET /projects/:id/push_rule ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目或 NAMESPACE / PROJECT_NAME 的 ID | ``` { "id": 1, "project_id": 3, "commit_message_regex": "Fixes \d+\..*", "commit_message_negative_regex": "ssh\:\/\/", "branch_name_regex": "", "deny_delete_tag": false, "created_at": "2012-10-12T17:04:47Z", "member_check": false, "prevent_secrets": false, "author_email_regex": "", "file_name_regex": "", "max_file_size": 5, "commit_committer_check": false, "reject_unsigned_commits": false } ``` 使用 GitLab [Premium,Silver 或更高版本的用户](https://about.gitlab.com/pricing/)还将看到`commit_committer_check`和`reject_unsigned_commits`参数: ``` { "id": 1, "project_id": 3, "commit_committer_check": false, "reject_unsigned_commits": false ... } ``` ### Add project push rule[](#add-project-push-rule "Permalink") 将推送规则添加到指定项目. ``` POST /projects/:id/push_rule ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目或 NAMESPACE / PROJECT_NAME 的 ID | | `deny_delete_tag` | boolean | no | 拒绝删除标签 | | `member_check` | boolean | no | 限制作者(电子邮件)对现有 GitLab 用户的提交 | | `prevent_secrets` | boolean | no | GitLab 将拒绝任何可能包含机密的文件 | | `commit_message_regex` | string | no | 所有提交消息都必须与此匹配,例如`Fixed \d+\..*` | | `commit_message_negative_regex` | string | no | 不允许任何提交消息与此匹配,例如`ssh\:\/\/` | | `branch_name_regex` | string | no | 所有分支名称必须与此匹配,例如`(feature&#124;hotfix)\/*` | | `author_email_regex` | string | no | 所有提交作者的电子邮件都必须与此匹配,例如`@my-company.com$` | | `file_name_regex` | string | no | 所有提交的文件名都**不能**与此匹配,例如`(jar&#124;exe)$` | | `max_file_size` | integer | no | 档案大小上限(MB) | | `commit_committer_check` | boolean | no | 用户只能将使用自己的已验证电子邮件之一提交的提交推送到该存储库. | | `reject_unsigned_commits` | boolean | no | 如果未通过 GPG 签名,则拒绝提交. | ### Edit project push rule[](#edit-project-push-rule "Permalink") 编辑指定项目的推送规则. ``` PUT /projects/:id/push_rule ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目或 NAMESPACE / PROJECT_NAME 的 ID | | `deny_delete_tag` | boolean | no | 拒绝删除标签 | | `member_check` | boolean | no | 限制作者(电子邮件)对现有 GitLab 用户的提交 | | `prevent_secrets` | boolean | no | GitLab will reject any files that are likely to contain secrets | | `commit_message_regex` | string | no | 所有提交消息都必须与此匹配,例如`Fixed \d+\..*` | | `commit_message_negative_regex` | string | no | 不允许任何提交消息与此匹配,例如`ssh\:\/\/` | | `branch_name_regex` | string | no | 所有分支名称必须与此匹配,例如`(feature&#124;hotfix)\/*` | | `author_email_regex` | string | no | 所有提交作者的电子邮件都必须与此匹配,例如`@my-company.com$` | | `file_name_regex` | string | no | 所有提交的文件名都**不能**与此匹配,例如`(jar&#124;exe)$` | | `max_file_size` | integer | no | 档案大小上限(MB) | | `commit_committer_check` | boolean | no | 用户只能将使用自己的已验证电子邮件之一提交的提交推送到该存储库. | | `reject_unsigned_commits` | boolean | no | 没有 GPG 签名时拒绝提交. | ### Delete project push rule[](#delete-project-push-rule "Permalink") 在[GitLab Starter](https://about.gitlab.com/pricing/) 9.0 中引入. 从项目中删除推送规则. 这是幂等方法,可以多次调用. 推送规则是否可用. ``` DELETE /projects/:id/push_rule ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ## Transfer a project to a new namespace[](#transfer-a-project-to-a-new-namespace "Permalink") 在 GitLab 11.1 中引入. ``` PUT /projects/:id/transfer ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `namespace` | integer/string | yes | 要转移到项目的名称空间的 ID 或路径 | ## Branches[](#branches "Permalink") 在" [分支机构"](branches.html)文档中了解更多信息. ## Project Import/Export[](#project-importexport "Permalink") 在[项目导入/导出](project_import_export.html)文档中了解更多信息. ## Project members[](#project-members "Permalink") 在[项目成员](members.html)文档中了解更多信息. ## Start the pull mirroring process for a Project[](#start-the-pull-mirroring-process-for-a-project-starter "Permalink") 在[GitLab Starter](https://about.gitlab.com/pricing/) 10.3 中引入. ``` POST /projects/:id/mirror/pull ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/mirror/pull" ``` ## Project badges[](#project-badges "Permalink") 在[Project Badges](project_badges.html)文档中了解更多信息. ## Issue and merge request description templates[](#issue-and-merge-request-description-templates "Permalink") 非默认的[问题和合并请求描述模板](../user/project/description_templates.html)在项目的存储库中进行管理. 因此,您可以通过[Repositories API](repositories.html)和[Repository Files API](repository_files.html)通过 API 管理它们. ## Download snapshot of a Git repository[](#download-snapshot-of-a-git-repository "Permalink") 在 GitLab 10.7 中引入 该端点只能由管理用户访问. 下载项目(或 Wiki,如果需要)Git 存储库的快照. 该快照始终为未压缩的[tar](https://en.wikipedia.org/wiki/Tar_(computing))格式. 如果存储库损坏到`git clone`不起作用的程度,则快照可能允许检索某些数据. ``` GET /projects/:id/snapshot ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | | `wiki` | boolean | no | 是否下载 Wiki,而不是项目存储库 |