Help us learn about your current experience with the documentation. Take the survey.

项目 Wiki API

  • 层级:Free, Premium, Ultimate
  • 提供方式:GitLab.com, GitLab Self-Managed, GitLab Dedicated

项目 wikis API 仅在 APIv4 中可用。 还有 group wikis 的 API 可用。

列出 Wiki 页面

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

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

示例响应:

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

创建新的 Wiki 页面

使用给定的标题、slug 和内容为给定仓库创建新的 Wiki 页面。

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>" \
  --url "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>" \
  --url "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>" \
  --url "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" \
  --url "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)"
  }
}

Wiki 页面评论

Wiki 评论被称为 notes。您可以使用 Notes API 与它们交互。