项目 wikis API

  • Tier: 基础版,专业版,旗舰版
  • Offering: JihuLab.com,私有化部署

极狐GitLab 项目 wikis API 仅在 APIv4 中可用。一个用于 群组 wikis 的 API 也可用。

列出 wiki 页面#

获取给定项目的所有 wiki 页面。

plaintext
GET /projects/:id/wikis
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
with_contentboolean包含页面的内容。
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis?with_content=1"

示例响应:

json
1[ 2 { 3 "content" : "Here is an instruction how to deploy this project.", 4 "format" : "markdown", 5 "slug" : "deploy", 6 "title" : "deploy", 7 "encoding": "UTF-8" 8 }, 9 { 10 "content" : "Our development process is described here.", 11 "format" : "markdown", 12 "slug" : "development", 13 "title" : "development", 14 "encoding": "UTF-8" 15 },{ 16 "content" : "* [Deploy](deploy)\n* [Development](development)", 17 "format" : "markdown", 18 "slug" : "home", 19 "title" : "home", 20 "encoding": "UTF-8" 21 } 22]

获取一个 wiki 页面#

获取给定项目的 wiki 页面。

plaintext
GET /projects/:id/wikis/:slug
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
slugstringwiki 页面 URL 编码的 slug(唯一字符串),例如 dir%2Fpage_name
render_htmlboolean返回 wiki 页面渲染后的 HTML。
versionstringwiki 页面版本 SHA。
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/home"

示例响应:

json
1{ 2 "content" : "home page", 3 "format" : "markdown", 4 "slug" : "home", 5 "title" : "home", 6 "encoding": "UTF-8" 7}

创建一个新的 wiki 页面#

为给定的仓库创建一个新的 wiki 页面,并指定标题、slug 和内容。

plaintext
POST /projects/:id/wikis
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
contentstringwiki 页面的内容。
titlestringwiki 页面的标题。
formatstringwiki 页面的格式。可用格式为:markdown(默认),rdocasciidocorg
shell
curl --data "format=rdoc&title=Hello&content=Hello world" \ --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis"

示例响应:

json
1{ 2 "content" : "Hello world", 3 "format" : "markdown", 4 "slug" : "Hello", 5 "title" : "Hello", 6 "encoding": "UTF-8" 7}

编辑现有的 wiki 页面#

更新现有的 wiki 页面。至少需要一个参数来更新 wiki 页面。

plaintext
PUT /projects/:id/wikis/:slug
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
contentstring是,如果 title 未提供wiki 页面的内容。
titlestring是,如果 content 未提供wiki 页面的标题。
formatstringwiki 页面的格式。可用格式为:markdown(默认),rdocasciidocorg
slugstringwiki 页面 URL 编码的 slug(唯一字符串),例如 dir%2Fpage_name
shell
curl --request PUT --data "format=rdoc&content=documentation&title=Docs" \ --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo"

示例响应:

json
1{ 2 "content" : "documentation", 3 "format" : "markdown", 4 "slug" : "Docs", 5 "title" : "Docs", 6 "encoding": "UTF-8" 7}

删除一个 wiki 页面#

删除具有给定 slug 的 wiki 页面。

plaintext
DELETE /projects/:id/wikis/:slug
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
slugstringwiki 页面 URL 编码的 slug(唯一字符串),例如 dir%2Fpage_name
shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo"

如果成功,则预期返回 204 No Content HTTP 响应,并且响应体为空。

上传附件到 wiki 仓库#

将文件上传到 wiki 仓库中的附件文件夹。附件文件夹是 uploads 文件夹。

plaintext
POST /projects/:id/wikis/attachments
属性类型必需描述
idinteger/string项目的 ID 或 URL 编码路径
filestring要上传的附件。
branchstring分支的名称。默认为 wiki 仓库的默认分支。

要从文件系统上传文件,请使用 --form 参数。这会导致 cURL 使用 Content-Type: multipart/form-data 头发送数据。file= 参数必须指向文件系统中的一个文件,并以 @ 为前缀。例如:

shell
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ --form "file=@dk.png" "https://gitlab.example.com/api/v4/projects/1/wikis/attachments"

示例响应:

json
1{ 2 "file_name" : "dk.png", 3 "file_path" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png", 4 "branch" : "main", 5 "link" : { 6 "url" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png", 7 "markdown" : "![A description of the attachment](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)" 8 } 9}