Help us learn about your current experience with the documentation. Take the survey.
项目模板 API
- 层级:免费版、专业版、旗舰版
- 提供方式:GitLab.com、GitLab 自托管、GitLab 专用
此 API 是这些端点的项目特定版本:
它已弃用这些端点,这些端点计划在 API 版本 5 中移除。
除了整个实例通用的模板外,此 API 端点还提供项目特定的模板。
同时也支持组文件模板。
获取特定类型的所有模板
GET /projects/:id/templates/:type| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
type |
string | 是 | 模板的类型。可接受的值有:dockerfiles、gitignores、gitlab_ci_ymls、licenses、issues 或 merge_requests。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/templates/licenses"示例响应(许可证):
[
{
"key": "epl-1.0",
"name": "Eclipse Public License 1.0"
},
{
"key": "lgpl-3.0",
"name": "GNU Lesser General Public License v3.0"
},
{
"key": "unlicense",
"name": "The Unlicense"
},
{
"key": "agpl-3.0",
"name": "GNU Affero General Public License v3.0"
},
{
"key": "gpl-3.0",
"name": "GNU General Public License v3.0"
},
{
"key": "bsd-3-clause",
"name": "BSD 3-clause \"New\" or \"Revised\" License"
},
{
"key": "lgpl-2.1",
"name": "GNU Lesser General Public License v2.1"
},
{
"key": "mit",
"name": "MIT License"
},
{
"key": "apache-2.0",
"name": "Apache License 2.0"
},
{
"key": "bsd-2-clause",
"name": "BSD 2-clause \"Simplified\" License"
},
{
"key": "mpl-2.0",
"name": "Mozilla Public License 2.0"
},
{
"key": "gpl-2.0",
"name": "GNU General Public License v2.0"
}
]获取特定类型的单个模板
GET /projects/:id/templates/:type/:name| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
name |
string | 是 | 模板的键,从集合端点获取。 |
type |
string | 是 | 模板的类型。可选值:dockerfiles、gitignores、gitlab_ci_ymls、licenses、issues 或 merge_requests。 |
fullname |
string | 否 | 用于在模板中扩展占位符的版权持有者全名。仅影响许可证。 |
project |
string | 否 | 用于在模板中扩展占位符的项目名称。仅影响许可证。 |
source_template_project_id |
integer | 否 | 存储给定模板的项目 ID。当来自不同项目的多个模板具有相同名称时很有用。如果多个模板具有相同名称且未指定 source_template_project_id,则返回来自 closest ancestor 的匹配项。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/templates/dockerfiles/Binary"示例响应(Dockerfile):
{
"name": "Binary",
"content": "# This file is a template, and might need editing before it works on your project.\n# This Dockerfile installs a compiled binary into a bare system.\n# You must either commit your compiled binary into source control (not recommended)\n# or build the binary first as part of a CI/CD pipeline.\n\nFROM buildpack-deps:buster\n\nWORKDIR /usr/local/bin\n\n# Change `app` to whatever your binary is called\nAdd app .\nCMD [\"./app\"]\n"
}示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/templates/licenses/mit"示例响应(许可证):
{
"key": "mit",
"name": "MIT License",
"nickname": null,
"popular": true,
"html_url": "http://choosealicense.com/licenses/mit/",
"source_url": "https://opensource.org/licenses/MIT",
"description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.",
"conditions": [
"include-copyright"
],
"permissions": [
"commercial-use",
"modifications",
"distribution",
"private-use"
],
"limitations": [
"liability",
"warranty"
],
"content": "MIT License\n\nCopyright (c) 2018 [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
}