{{< details >}}

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

{{< /details >}}

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

列出 wiki 页面

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

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

示例响应:

[
  {
    "content" : "Here is an instruction how to deploy this project.",
    "format" : "markdown",
    "slug" : "deploy",
    "title" : "deploy",
    "encoding": "UTF-8"
  },
  {
    "content" : "Our development process is described here.",
    "format" : "markdown",
    "slug" : "development",
    "title" : "development",
    "encoding": "UTF-8"
  },{
    "content" : "*  [Deploy](deploy)\n*  [Development](development)",
    "format" : "markdown",
    "slug" : "home",
    "title" : "home",
    "encoding": "UTF-8"
  }
]

获取一个 wiki 页面

获取给定项目的 wiki 页面。

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

示例响应:

{
  "content" : "home page",
  "format" : "markdown",
  "slug" : "home",
  "title" : "home",
  "encoding": "UTF-8"
}

创建一个新的 wiki 页面

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

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

示例响应:

{
  "content" : "Hello world",
  "format" : "markdown",
  "slug" : "Hello",
  "title" : "Hello",
  "encoding": "UTF-8"
}

编辑现有的 wiki 页面

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

PUT /projects/:id/wikis/:slug
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
content string 是,如果 title 未提供 wiki 页面的内容。
title string 是,如果 content 未提供 wiki 页面的标题。
format string wiki 页面的格式。可用格式为:markdown(默认),rdocasciidocorg
slug string wiki 页面 URL 编码的 slug(唯一字符串),例如 dir%2Fpage_name
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"

示例响应:

{
  "content" : "documentation",
  "format" : "markdown",
  "slug" : "Docs",
  "title" : "Docs",
  "encoding": "UTF-8"
}

删除一个 wiki 页面

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

DELETE /projects/:id/wikis/:slug
属性 类型 必需 描述
id integer/string 项目的 ID 或 URL 编码路径
slug string wiki 页面 URL 编码的 slug(唯一字符串),例如 dir%2Fpage_name
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 文件夹。

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

要从文件系统上传文件,请使用 --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/1/wikis/attachments"

示例响应:

{
  "file_name" : "dk.png",
  "file_path" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
  "branch" : "main",
  "link" : {
    "url" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
    "markdown" : "![A description of the attachment](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)"
  }
}