正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

プロジェクトテンプレートAPI

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated

このAPIは、これらのエンドポイントのプロジェクト固有バージョンです:

これはこれらのエンドポイントを非推奨とし、APIのバージョン5で削除される予定です。

インスタンス全体で共通のテンプレートに加えて、プロジェクト固有のテンプレートもこのAPIのエンドポイントから利用できます。

グループのファイルテンプレートのサポートも利用できます。

特定の種類のすべてのテンプレートを取得

プロジェクトの特定の種類のすべてのテンプレートを取得します。

GET /projects/:id/templates/:type

サポートされている属性は以下のとおりです:

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
type文字列はいテンプレートのタイプ。指定できる値は、dockerfilesgitignoresgitlab_ci_ymlslicensesissuesmerge_requestsです。

成功した場合、200 OKと次のレスポンス属性を返します:

属性説明
key文字列テンプレートの固有識別子。
name文字列テンプレートの人間が判読できる名前。

リクエスト例:

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"
  }
]

特定の種類の1つのテンプレートを取得

プロジェクトの特定のタイプの単一のテンプレートを取得します。

GET /projects/:id/templates/:type/:name

サポートされている属性は以下のとおりです:

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
name文字列はいコレクションエンドポイントから取得したテンプレートのキー。
type文字列はいテンプレートのタイプ。dockerfilesgitignoresgitlab_ci_ymlslicensesissues、またはmerge_requestsのいずれか。
fullname文字列いいえテンプレート内のプレースホルダーを展開するときに使用する著作権者のフルネーム。ライセンスのみに影響します。
project文字列いいえテンプレート内のプレースホルダーを展開するときに使用するプロジェクト名。ライセンスのみに影響します。
source_template_project_id整数いいえ特定のテンプレートが保存されているプロジェクトID。異なるプロジェクトの複数のテンプレートが同じ名前を持つ場合に役立ちます。複数のテンプレートが同じ名前を持つ場合、source_template_project_idが指定されていない場合は、最も近い祖先からのマージが返されます。

成功した場合、200 OKと次のレスポンス属性を返します:

属性説明
conditions配列ライセンス条件の配列。ライセンスでのみ使用可能です。
content文字列テンプレートのコンテンツ。
description文字列ライセンスの説明。ライセンスでのみ使用可能です。
html_url文字列ライセンス情報ページへのURL。ライセンスでのみ使用可能です。
key文字列テンプレートの固有識別子。ライセンスでのみ使用可能です。
limitations配列ライセンス制限の配列。ライセンスでのみ使用可能です。
name文字列テンプレートの人間が判読できる名前。
nickname文字列ライセンスの一般的なニックネーム。ライセンスでのみ使用可能です。
permissions配列ライセンス許可の配列。ライセンスでのみ使用可能です。
popularブール値trueの場合、これは一般的なライセンスであることを示します。ライセンスでのみ使用可能です。
source_url文字列ライセンスソースへのURL。ライセンスでのみ使用可能です。

リクエスト例:

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"
}