许可证 API

  • Tier: Free, Premium, Ultimate
  • Offering: JihuLab.com, 私有化部署

在极狐GitLab中,有一个 API 端点可用于处理各种开源许可证模板。

具有访客角色的用户无法访问许可证模板。有关详细信息,请参阅项目和群组可见性

列出许可证模板#

获取所有许可证模板。

plaintext
GET /templates/licenses
属性类型必需描述
popularbooleanno如果传递,返回仅流行的许可证

示例请求:

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

示例响应:

json
1[ 2 { 3 "key":"apache-2.0", 4 "name":"Apache License 2.0", 5 "nickname":null, 6 "featured":true, 7 "html_url":"http://choosealicense.com/licenses/apache-2.0/", 8 "source_url":"http://www.apache.org/licenses/LICENSE-2.0.html", 9 "description":"A permissive license that also provides an express grant of patent rights from contributors to users.", 10 "conditions":[ 11 "include-copyright", 12 "document-changes" 13 ], 14 "permissions":[ 15 "commercial-use", 16 "modifications", 17 "distribution", 18 "patent-use", 19 "private-use" 20 ], 21 "limitations":[ 22 "trademark-use", 23 "no-liability" 24 ], 25 "content":" Apache License\n Version 2.0, January 2004\n [...]" 26 }, 27 { 28 "key":"gpl-3.0", 29 "name":"GNU General Public License v3.0", 30 "nickname":"GNU GPLv3", 31 "featured":true, 32 "html_url":"http://choosealicense.com/licenses/gpl-3.0/", 33 "source_url":"http://www.gnu.org/licenses/gpl-3.0.txt", 34 "description":"The GNU GPL is the most widely used free software license and has a strong copyleft requirement. When distributing derived works, the source code of the work must be made available under the same license.", 35 "conditions":[ 36 "include-copyright", 37 "document-changes", 38 "disclose-source", 39 "same-license" 40 ], 41 "permissions":[ 42 "commercial-use", 43 "modifications", 44 "distribution", 45 "patent-use", 46 "private-use" 47 ], 48 "limitations":[ 49 "no-liability" 50 ], 51 "content":" GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n [...]" 52 }, 53 { 54 "key":"mit", 55 "name":"MIT License", 56 "nickname":null, 57 "featured":true, 58 "html_url":"http://choosealicense.com/licenses/mit/", 59 "source_url":"http://opensource.org/licenses/MIT", 60 "description":"A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.", 61 "conditions":[ 62 "include-copyright" 63 ], 64 "permissions":[ 65 "commercial-use", 66 "modifications", 67 "distribution", 68 "private-use" 69 ], 70 "limitations":[ 71 "no-liability" 72 ], 73 "content":"The MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n [...]" 74 } 75]

单个许可证模板#

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

plaintext
GET /templates/licenses/:key
属性类型必需描述
keystringyes许可证模板的键
projectstringno受版权保护的项目名称
fullnamestringno版权持有者的全名
如果您省略了 `fullname` 参数但验证了您的请求,则认证用户的姓名将替换版权持有者占位符。

示例请求:

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

示例响应:

json
1{ 2 "key":"mit", 3 "name":"MIT License", 4 "nickname":null, 5 "featured":true, 6 "html_url":"http://choosealicense.com/licenses/mit/", 7 "source_url":"http://opensource.org/licenses/MIT", 8 "description":"A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.", 9 "conditions":[ 10 "include-copyright" 11 ], 12 "permissions":[ 13 "commercial-use", 14 "modifications", 15 "distribution", 16 "private-use" 17 ], 18 "limitations":[ 19 "no-liability" 20 ], 21 "content":"The MIT License (MIT)\n\nCopyright (c) 2016 John Doe\n [...]" 22}