Skip to main content
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

适用于存储库交互的 REST API 终结点

使用 REST API 临时限制哪类用户可以在公共存储库上发表评论、开设问题或创建拉取请求。

谁可以使用此功能?

People with owner or admin access to temporarily restrict which type of user can comment, open issues, or create pull requests in a public repository.

关于存储库交互

具有所有者或管理员访问权限的用户可以使用 REST API 临时限制哪类用户可以在公共存储库上发表评论、开设问题或创建拉取请求。 启用限制后,只有指定的 GitHub 用户类型才能参与交互。 限制在定义的期限后自动过期。 以下是有关 GitHub 用户类型的更多信息:

  • 仓库中的 现有用户:将互动限制为 existing_users 时,帐户未满 24 小时且以前没有贡献且不是协作者的新用户将被暂时限制。
  • 仓库中的 仅参与者:当你将交互限制为 contributors_only 时,以前未参与且不是协作者的用户将暂时受到限制。
  • 仓库中的 仅协作者:将交互限制为 collaborators_only 时,非协作者用户将暂时受到限制。

如果对拥有该仓库的用户或组织启用了交互限制,单个仓库的限制就不能更改。 而应使用用户组织交互终结点来更改交互限制。

Get interaction restrictions for a repository

Shows which type of GitHub user can interact with this repository and when the restriction expires. If there are no restrictions, you will see an empty response.

“Get interaction restrictions for a repository”的细粒度访问令牌

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

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

  • "Administration" repository permissions (read)

“Get interaction restrictions for a repository”的参数

标头
名称, 类型, 说明
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.

“Get interaction restrictions for a repository”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get interaction restrictions for a repository”的示例代码

请求示例

get/repos/{owner}/{repo}/interaction-limits
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/interaction-limits

Response

Status: 200
{ "limit": "collaborators_only", "origin": "repository", "expires_at": "2018-08-17T04:18:39Z" }

Set interaction restrictions for a repository

Temporarily restricts interactions to a certain type of GitHub user within the given repository. You must have owner or admin access to set these restrictions. If an interaction limit is set for the user or organization that owns this repository, you will receive a 409 Conflict response and will not be able to use this endpoint to change the interaction limit for a single repository.

“Set interaction restrictions for a repository”的细粒度访问令牌

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

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

  • "Administration" repository permissions (write)

“Set interaction restrictions for a repository”的参数

标头
名称, 类型, 说明
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.

正文参数
名称, 类型, 说明
limit string 必须

The type of GitHub user that can comment, open issues, or create pull requests while the interaction limit is in effect.

可以是以下选项之一: existing_users, contributors_only, collaborators_only

expiry string

The duration of the interaction restriction. Default: one_day.

可以是以下选项之一: one_day, three_days, one_week, one_month, six_months

“Set interaction restrictions for a repository”的 HTTP 响应状态代码

状态代码说明
200

OK

409

Conflict

“Set interaction restrictions for a repository”的示例代码

请求示例

put/repos/{owner}/{repo}/interaction-limits
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/interaction-limits \ -d '{"limit":"collaborators_only","expiry":"one_day"}'

Response

Status: 200
{ "limit": "collaborators_only", "origin": "repository", "expires_at": "2018-08-17T04:18:39Z" }

Remove interaction restrictions for a repository

Removes all interaction restrictions from the given repository. You must have owner or admin access to remove restrictions. If the interaction limit is set for the user or organization that owns this repository, you will receive a 409 Conflict response and will not be able to use this endpoint to change the interaction limit for a single repository.

“Remove interaction restrictions for a repository”的细粒度访问令牌

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

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

  • "Administration" repository permissions (write)

“Remove interaction restrictions for a repository”的参数

标头
名称, 类型, 说明
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.

“Remove interaction restrictions for a repository”的 HTTP 响应状态代码

状态代码说明
204

No Content

409

Conflict

“Remove interaction restrictions for a repository”的示例代码

请求示例

delete/repos/{owner}/{repo}/interaction-limits
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/interaction-limits

Response

Status: 204