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

许可证 API

  • 层级:免费版、高级版、旗舰版
  • 提供方式:GitLab.com、GitLab 自托管、GitLab 专用

在 GitLab 中,有一个 API 端点可用于处理各种开源许可证模板。有关各种许可证条款的更多信息,请参阅 此网站 或其他众多在线资源。

具有 Guest 角色的用户无法访问许可证模板。更多信息,请参阅 项目和组可见性

列出许可证模板

获取所有许可证模板。

GET /templates/licenses
属性 类型 必需 描述
popular boolean 如果传入,仅返回热门许可证

示例请求:

curl "https://gitlab.example.com/api/v4/templates/licenses?popular=1"

示例响应:

[
  {
    "key":"apache-2.0",
    "name":"Apache License 2.0",
    "nickname":null,
    "featured":true,
    "html_url":"http://choosealicense.com/licenses/apache-2.0/",
    "source_url":"http://www.apache.org/licenses/LICENSE-2.0.html",
    "description":"一个宽松的许可证,同时也明确授予了贡献者向用户授予专利权利。",
    "conditions":[
      "include-copyright",
      "document-changes"
    ],
    "permissions":[
      "commercial-use",
      "modifications",
      "distribution",
      "patent-use",
      "private-use"
    ],
    "limitations":[
      "trademark-use",
      "no-liability"
    ],
    "content":"                                 Apache License\n                           Version 2.0, January 2004\n [...]"
  },
  {
    "key":"gpl-3.0",
    "name":"GNU General Public License v3.0",
    "nickname":"GNU GPLv3",
    "featured":true,
    "html_url":"http://choosealicense.com/licenses/gpl-3.0/",
    "source_url":"http://www.gnu.org/licenses/gpl-3.0.txt",
    "description":"GNU GPL 是使用最广泛的开源软件许可证,具有强烈的 copyleft 要求。在分发衍生作品时,必须使该作品的源代码在相同许可证下可用。",
    "conditions":[
      "include-copyright",
      "document-changes",
      "disclose-source",
      "same-license"
    ],
    "permissions":[
      "commercial-use",
      "modifications",
      "distribution",
      "patent-use",
      "private-use"
    ],
    "limitations":[
      "no-liability"
    ],
    "content":"                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n [...]"
  },
  {
    "key":"mit",
    "name":"MIT License",
    "nickname":null,
    "featured":true,
    "html_url":"http://choosealicense.com/licenses/mit/",
    "source_url":"http://opensource.org/licenses/MIT",
    "description":"一个简明扼要的宽松许可证。它允许人们在适当署名且无担保的情况下对您的代码进行任何操作。",
    "conditions":[
      "include-copyright"
    ],
    "permissions":[
      "commercial-use",
      "modifications",
      "distribution",
      "private-use"
    ],
    "limitations":[
      "no-liability"
    ],
    "content":"The MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n [...]"
  }
]

单个许可证模板

获取单个许可证模板。您可以传递参数来替换许可证占位符。

GET /templates/licenses/:key
属性 类型 必需 描述
key string 许可证模板的键
project string 版权项目名称
fullname string 版权持有者的全名

如果您省略 fullname 参数但验证了您的请求,已验证用户的名称将替换版权持有者占位符。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/templates/licenses/mit?project=My+Cool+Project"

示例响应:

{
  "key":"mit",
  "name":"MIT License",
  "nickname":null,
  "featured":true,
  "html_url":"http://choosealicense.com/licenses/mit/",
  "source_url":"http://opensource.org/licenses/MIT",
  "description":"一个简明扼要的宽松许可证。它允许人们在适当署名且无担保的情况下对您的代码进行任何操作。",
  "conditions":[
    "include-copyright"
  ],
  "permissions":[
    "commercial-use",
    "modifications",
    "distribution",
    "private-use"
  ],
  "limitations":[
    "no-liability"
  ],
  "content":"The MIT License (MIT)\n\nCopyright (c) 2016 John Doe\n [...]"
}