群组 wikis API

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

群组 wiki API 仅在 APIv4 中可用。也可以使用项目 wiki的 API。

列出 wiki 页面#

列出给定群组的所有 wiki 页面。

plaintext
GET /groups/:id/wikis
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
with_contentbooleanNo包含页面内容。
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/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 /groups/:id/wikis/:slug
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
slugstringYeswiki 页面的 URL 编码 slug(唯一字符串),例如 dir%2Fpage_name
render_htmlbooleanNo返回 wiki 页面的渲染 HTML。
versionstringNowiki 页面版本 SHA。
shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/wikis/home"

示例响应:

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

创建新的 wiki 页面#

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

plaintext
POST /projects/:id/wikis
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
contentstringYeswiki 页面的内容。
titlestringYeswiki 页面的标题。
formatstringNowiki 页面的格式。可用格式包括:markdown(默认)、rdocasciidocorg
shell
curl --data "format=rdoc&title=Hello&content=Hello world" \ --header "PRIVATE-TOKEN: <your_access_token>" \ "https://gitlab.example.com/api/v4/groups/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 /groups/:id/wikis/:slug
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
contentstringYes, 如果没有提供 titlewiki 页面的内容。
titlestringYes, 如果没有提供 contentwiki 页面的标题。
formatstringNowiki 页面的格式。可用格式包括 markdown(默认)、rdocasciidocorg
slugstringYeswiki 页面的 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/groups/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 /groups/:id/wikis/:slug
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
slugstringYeswiki 页面的 URL 编码 slug(唯一字符串),例如 dir%2Fpage_name
shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/1/wikis/foo"

如果成功,预计会返回一个带有空体的 204 No Content HTTP 响应。

上传附件到 wiki 仓库#

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

plaintext
POST /groups/:id/wikis/attachments
属性类型必需描述
idinteger/stringYes群组的 ID 或URL 编码路径
filestringYes要上传的附件。
branchstringNo分支的名称。默认为 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/groups/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" : "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)" 8 } 9}