Project snippets
Project snippets
GitLab 中的片段可以是私有的,内部的或公共的. 您可以使用代码段中的字段进行设置.
摘要可见性级别的常量为:
注意:从 2019 年 7 月开始,GitLab.com 上的新项目,组和摘要的`
Internal可见性''设置被禁用. 使用"
Internal`可见性”设置的现有项目,组和摘录保留此设置. 您可以在阅读有关更改的更多信息.
List snippets
获取项目摘要列表.
Parameters:
id
(必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
Single snippet
获得一个项目片段.
GET /projects/:id/snippets/:snippet_id
Parameters:
snippet_id
(必填)-项目代码段的 ID
{ "id": 1, "title": "test", "file_name": "add.rb", "description": "Ruby test snippet", "author": { "id": 1, "username": "john_smith", "email": "john@example.com", "name": "John Smith", "state": "active", "created_at": "2012-05-23T08:00:58Z" }, "updated_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z", "project_id": 1, "web_url": "http://example.com/example/example/snippets/1", "raw_url": "http://example.com/example/example/snippets/1/raw" }
创建一个新的项目片段. 用户必须具有创建新代码段的权限.
POST /projects/:id/snippets
id
(必填)-经过身份验证的用户拥有的项目的 ID 或title
(required) - The title of a snippetfile_name
(必填)-代码段文件的名称description
(可选)-代码段的说明content
(必填)-代码段的内容visibility
(必填)-代码段的可见性
请求示例:
curl --request POST "https://gitlab.com/api/v4/projects/:id/snippets" \
--header "Content-Type: application/json" \
-d @snippet.json
上面的示例请求中使用的snippet.json
:
{ "title" : "Example Snippet Title", "description" : "More verbose snippet description", "file_name" : "example.txt", "content" : "source code \n with multiple lines\n", "visibility" : "private" }
Update snippet
更新现有的项目代码段. 用户必须具有更改现有代码段的权限.
Parameters:
id
(必填)-经过身份验证的用户拥有的 ID 或URL 编码路径snippet_id
(必填)-项目代码段的 IDtitle
(可选)-摘要的标题file_name
(可选)-代码段文件的名称description
(可选)-代码段的说明content
(可选)-代码段的内容visibility
(可选)-代码段的可见性
请求示例:
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
-d @snippet.json
上面的示例请求中使用的snippet.json
:
{ "title" : "Updated Snippet Title", "description" : "More verbose snippet description", "file_name" : "new_filename.txt", "content" : "updated source code \n with multiple lines\n", "visibility" : "private" }
Delete snippet
删除现有项目片段. 如果操作成功,则返回204 No Content
状态代码;如果找不到资源,则返回 .
DELETE /projects/:id/snippets/:snippet_id
Parameters:
id
(必填)-经过身份验证的用户拥有的项目的 ID 或snippet_id
(必填)-项目代码段的 ID
curl --request DELETE "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id" \
--header "PRIVATE-TOKEN: <your_access_token>"
以纯文本形式返回原始项目代码段.
GET /projects/:id/snippets/:snippet_id/raw
Parameters:
id
(必填)-经过身份验证的用户拥有的项目的 ID 或snippet_id
(必填)-项目代码段的 ID
请求示例:
Snippet repository file content
以纯文本形式返回原始文件的内容.
GET /projects/:id/snippets/:snippet_id/files/:ref/:file_path/raw
Parameters:
id
(必填)-经过身份验证的用户拥有的 ID 或URL 编码路径snippet_id
(必填)-项目代码段的 IDref
(必填)-分支,标记或提交的名称,例如 masterfile_path
(必填)-文件的 URL 编码路径,例如 snippet%2Erb
请求示例:
curl "https://gitlab.com/api/v4/projects/1/snippets/2/files/master/snippet%2Erb/raw" \
--header "PRIVATE-TOKEN: <your_access_token>"
Get user agent details
在 GitLab 9.4 中引入 .
仅适用于管理员.
GET /projects/:id/snippets/:snippet_id/user_agent_detail
Attribute | Type | Required | Description |
---|---|---|---|
id |
Integer | yes | 项目 ID |
snippet_id |
Integer | yes | 片段的 ID |
响应示例: