在Github中,当你设置一个项目时,你可以指定项目所在的许可证,以后可以在UI中检查它,或者通过REST API获取它。
在 Gitlab 中也可以做同样的事情吗?有没有我可以为此使用的 Java 库?我一直在浏览 REST API,但我似乎找不到这样的东西。在创建/设置存储库时,似乎也无法配置它。
这可以通过在项目 API 中添加标志许可证来完成。
启用此选项后,您将在响应 json 中获得"license_url"和"许可证"。另外关于这个问题,将许可证文件放在文件夹中,而不是在您的根目录中 - gitlab 会认为您没有项目的许可证,并且使用许可证标志获取会给您 NULL。
许可证格式无关紧要,即使从模板创建并尝试添加格式(.txt、.bat、.md 等(也很难,因为每个书面字符都会从表单字段中驱动license_name所以我认为大多数存储库最终都会只有 LICENSE。
例如,从 gitlab-org/gitlab 存储库(ID 278964(获取许可证:
curl https://gitlab.com/api/v4/projects/278964?license=yes
响应:
{
"id": 278964,
"description": "GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a container, or on a cloud provider.",
"name": "GitLab",
"name_with_namespace": "GitLab.org / GitLab",
...
"license_url": "https://gitlab.com/gitlab-org/gitlab/-/blob/master/LICENSE",
"license": {
"key": "other",
"name": "Other",
"nickname": "LICENSE",
"html_url": "http://choosealicense.com/licenses/other/",
"source_url": null
},
}
确实有一个GitLab API:
- https://docs.gitlab.com/ce/api/managed_licenses.html
- https://docs.gitlab.com/ce/api/templates/licenses.html
这里列出了所有客户端,并且有几个Java客户端:https://about.gitlab.com/partners/#api-clients