Skip to main content
Skip to content

用于许可证合规性的 REST API 端点

使用 REST API 根据仓库的许可证合规策略检查包。

Get the license compliance policy for an enterprise

Gets the license compliance policy for an enterprise.

Currently, only the policy with the ID default is supported.

The authenticated user must be an enterprise owner, or have the "View enterprise license policy" or "Edit enterprise license policy" fine-grained permission on the enterprise.

“Get the license compliance policy for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

细粒度令牌必须具有以下权限集:

  • "Enterprise license policy" enterprise permissions (read)

“”Get the license compliance policy for an enterprise 的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name.

policy_id string 必须

The unique identifier of the policy within the enterprise. Currently, only default is supported.

“Get the license compliance policy for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

404

Resource not found

503

Service unavailable

“Get the license compliance policy for an enterprise”的代码示例

如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。

请求示例

get/enterprises/{enterprise}/license-compliance/policies/{policy_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/enterprises/ENTERPRISE/license-compliance/policies/POLICY_ID

Response

Status: 200
{ "created_at": "2026-09-22T12:00:00Z", "licenses": { "allowed": [ { "spdx_id": "MIT", "added_at": "2026-09-22T12:00:00Z" } ] }, "packages": [ { "package_manager": "npm", "name": "example-package", "action": "allowed", "reason": "Approved exception.", "extra_allowed_spdx_ids": [ "MIT" ], "added_at": "2026-09-22T12:00:00Z" } ] }

Set the license compliance policy for an enterprise

Sets the license compliance policy for an enterprise.

Currently, only the policy with the ID default is supported.

The authenticated user must be an enterprise owner, or have the "Edit enterprise license policy" fine-grained permission on the enterprise.

“Set the license compliance policy for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

细粒度令牌必须具有以下权限集:

  • "Enterprise license policy" enterprise permissions (write)

“”Set the license compliance policy for an enterprise 的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name.

policy_id string 必须

The unique identifier of the policy within the enterprise. Currently, only default is supported.

主体参数
名称, 类型, 说明
licenses object 必须
名称, 类型, 说明
allowed array of objects 必须

The licenses allowed by this policy.

名称, 类型, 说明
spdx_id string 必须

The SPDX identifier of the license.

added_at string or null 必须

The time the license was added to the policy.

packages array of objects 必须

The package-level exceptions in this policy.

名称, 类型, 说明
package_manager string 必须

The package manager the package belongs to.

可以是以下选项之一: unknown, rubygems, npm, pip, maven, nuget, composer, gomod, rust, actions, pub, swift

name string 必须

The name of the package.

action string 必须

How the package is treated by the policy.

可以是以下选项之一: unknown, allowed, private

reason string 必须

The reason the exception was added.

extra_allowed_spdx_ids array of strings 必须

Additional SPDX identifiers allowed for this package.

added_at string or null 必须

The time the exception was added to the policy.

“Set the license compliance policy for an enterprise”的 HTTP 响应状态代码

状态代码说明
204

A header with no content is returned.

404

Resource not found

422

Validation failed, or the endpoint has been spammed.

503

Service unavailable

“Set the license compliance policy for an enterprise”的代码示例

如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。

请求示例

put/enterprises/{enterprise}/license-compliance/policies/{policy_id}
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/enterprises/ENTERPRISE/license-compliance/policies/POLICY_ID \ -d '{"licenses":{"allowed":[{"spdx_id":"MIT","added_at":"2026-09-22T12:00:00Z"}]},"packages":[{"package_manager":"npm","name":"example-package","action":"allowed","reason":"Approved exception.","extra_allowed_spdx_ids":["MIT"],"added_at":"2026-09-22T12:00:00Z"}]}'

A header with no content is returned.

Status: 204

Check license compliance for packages

Checks whether packages identified by the supplied package URLs (PURLs) are allowed by the repository's license compliance policy.

For requests made on behalf of a user, that user must have write access to the repository or the "View repository license policy" permission. OAuth apps and classic personal access tokens require the repo scope.

“Check license compliance for packages”的细粒度访问令牌

此端点支持以下精细令牌类型:

细粒度令牌必须具有以下权限集:

  • "Repository license policy" repository permissions (read)

“”Check license compliance for packages 的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

主体参数
名称, 类型, 说明
purls array of strings 必须

Up to 40 package URLs to check against the license compliance policy. Duplicate package URLs count toward the limit but are checked once.

“Check license compliance for packages”的 HTTP 响应状态代码

状态代码说明
200

Package license compliance results.

403

Forbidden

404

License compliance policy not found.

422

Validation failed, or the endpoint has been spammed.

503

Service unavailable

“Check license compliance for packages”的代码示例

如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。

请求示例

post/repos/{owner}/{repo}/license-compliance/package-checks
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/repos/OWNER/REPO/license-compliance/package-checks \ -d '{"purls":["pkg:npm/lodash@4.17.21"]}'

Package license compliance results.

Status: 200
{ "purls": { "pkg:npm/lodash@4.17.21": { "status": "allowed", "license": "MIT", "reason": "allowed_license" } } }