debian-mirror-gitlab/doc/api/project_templates.md

142 lines
6 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-10-24 23:57:45 +05:30
---
2021-03-11 19:13:27 +05:30
# Project templates API **(FREE)**
2018-12-05 23:21:45 +05:30
2018-12-13 13:39:08 +05:30
This API is a project-specific version of these endpoints:
2018-12-05 23:21:45 +05:30
- [Dockerfile templates](templates/dockerfiles.md)
- [Gitignore templates](templates/gitignores.md)
2020-06-23 00:09:42 +05:30
- [GitLab CI/CD Configuration templates](templates/gitlab_ci_ymls.md)
2018-12-05 23:21:45 +05:30
- [Open source license templates](templates/licenses.md)
2020-10-24 23:57:45 +05:30
- [Issue and merge request templates](../user/project/description_templates.md)
([introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37890) in GitLab 13.3)
2018-12-05 23:21:45 +05:30
2021-04-17 20:07:23 +05:30
It deprecates these endpoints, which are scheduled for removal in API version 5.
2018-12-05 23:21:45 +05:30
2018-12-13 13:39:08 +05:30
In addition to templates common to the entire instance, project-specific
templates are also available from this API endpoint.
2018-12-05 23:21:45 +05:30
2022-08-27 11:52:29 +05:30
Support is also available for [group-level file templates](../user/group/manage.md#group-file-templates). **(PREMIUM)**
2018-12-05 23:21:45 +05:30
## Get all templates of a particular type
2020-04-08 14:13:33 +05:30
```plaintext
2018-12-05 23:21:45 +05:30
GET /projects/:id/templates/:type
```
| Attribute | Type | Required | Description |
| ---------- | ------ | -------- | ----------- |
2022-10-11 01:57:18 +05:30
| `id` | integer or string | **{check-circle}** Yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding). |
| `type` | string | **{check-circle}** Yes | The type of the template. Accepted values are: `dockerfiles`, `gitignores`, `gitlab_ci_ymls`, `licenses`, `issues`, or `merge_requests`. |
2018-12-05 23:21:45 +05:30
Example response (licenses):
```json
[
{
"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 one template of a particular type
2020-04-08 14:13:33 +05:30
```plaintext
2021-03-11 19:13:27 +05:30
GET /projects/:id/templates/:type/:name
2018-12-05 23:21:45 +05:30
```
| Attribute | Type | Required | Description |
| ---------- | ------ | -------- | ----------- |
2022-10-11 01:57:18 +05:30
| `id` | integer or string | **{check-circle}** Yes | The ID or [URL-encoded path of the project](index.md#namespaced-path-encoding). |
| `name` | string | **{check-circle}** Yes | The key of the template, as obtained from the collection endpoint. |
| `type` | string | **{check-circle}** Yes | The type of the template. One of: `dockerfiles`, `gitignores`, `gitlab_ci_ymls`, `licenses`, `issues`, or `merge_requests`. |
| `fullname` | string | **{dotted-circle}** No | The full name of the copyright holder to use when expanding placeholders in the template. Affects only licenses. |
| `project` | string | **{dotted-circle}** No | The project name to use when expanding placeholders in the template. Affects only licenses. |
| `source_template_project_id` | integer | **{dotted-circle}** No | The project ID where a given template is being stored. Helpful when multiple templates from different projects have the same name. If multiple templates have the same name, the match from `closest ancestor` is returned if `source_template_project_id` is not specified, |
2018-12-05 23:21:45 +05:30
Example response (Dockerfile):
```json
{
"name": "Binary",
2020-11-24 15:15:51 +05:30
"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"
2018-12-05 23:21:45 +05:30
}
```
Example response (license):
```json
{
"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"
}
```