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

自定义属性的 REST API 终结点

使用 REST API 为组织创建和管理自定义属性。

关于自定义属性

您可以使用 REST API 为组织创建和管理自定义属性。 您可以使用自定义属性将元数据添加到组织中的存储库。 有关详细信息,请参阅“管理组织中存储库的自定义属性”。

Get all custom properties for an organization

Gets all custom properties defined for an organization. Organization members can read these properties.

“Get all custom properties for an organization”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:read

“Get all custom properties for an organization”的参数

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

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

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

The organization name. The name is not case sensitive.

“Get all custom properties for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

403

Forbidden

404

Resource not found

“Get all custom properties for an organization”的示例代码

请求示例

get/orgs/{org}/properties/schema
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/orgs/ORG/properties/schema

Response

Status: 200
[ { "property_name": "environment", "value_type": "single_select", "required": true, "default_value": "production", "description": "Prod or dev environment", "allowed_values": [ "production", "development" ], "values_editable_by": "org_actors" }, { "property_name": "service", "value_type": "string" }, { "property_name": "team", "value_type": "string", "description": "Team owning the repository" } ]

Create or update custom properties for an organization

Creates new or updates existing custom properties defined for an organization in a batch.

To use this endpoint, the authenticated user must be one of:

  • An administrator for the organization.
  • A user, or a user on a team, with the fine-grained permission of custom_properties_org_definitions_manager in the organization.

“Create or update custom properties for an organization”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:admin

“Create or update custom properties for an organization”的参数

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

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

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

The organization name. The name is not case sensitive.

正文参数
名称, 类型, 说明
properties array of objects 必须

The array of custom properties to create or update.

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

The name of the property

value_type string 必须

The type of the value for the property

可以是以下选项之一: string, single_select

required boolean

Whether the property is required.

default_value null or string or array

Default value of the property

description string or null

Short description of the property

allowed_values array of strings or null

An ordered list of the allowed values of the property. The property can have up to 200 allowed values.

values_editable_by string or null

Who can edit the values of the property

可以是以下选项之一: org_actors, org_and_repo_actors, null

“Create or update custom properties for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

403

Forbidden

404

Resource not found

“Create or update custom properties for an organization”的示例代码

请求示例

patch/orgs/{org}/properties/schema
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/properties/schema \ -d '{"properties":[{"property_name":"environment","value_type":"single_select","required":true,"default_value":"production","description":"Prod or dev environment","allowed_values":["production","development"],"values_editable_by":"org_actors"},{"property_name":"service","value_type":"string"},{"property_name":"team","value_type":"string","description":"Team owning the repository"}]}'

Response

Status: 200
[ { "property_name": "environment", "value_type": "single_select", "required": true, "default_value": "production", "description": "Prod or dev environment", "allowed_values": [ "production", "development" ], "values_editable_by": "org_actors" }, { "property_name": "service", "value_type": "string" }, { "property_name": "team", "value_type": "string", "description": "Team owning the repository" } ]

Get a custom property for an organization

Gets a custom property that is defined for an organization. Organization members can read these properties.

“Get a custom property for an organization”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:read

“Get a custom property for an organization”的参数

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

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

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

The organization name. The name is not case sensitive.

custom_property_name string 必须

The custom property name. The name is case sensitive.

“Get a custom property for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

403

Forbidden

404

Resource not found

“Get a custom property for an organization”的示例代码

请求示例

get/orgs/{org}/properties/schema/{custom_property_name}
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/orgs/ORG/properties/schema/CUSTOM_PROPERTY_NAME

Response

Status: 200
{ "property_name": "environment", "value_type": "single_select", "required": true, "default_value": "production", "description": "Prod or dev environment", "allowed_values": [ "production", "development" ] }

Create or update a custom property for an organization

Creates a new or updates an existing custom property that is defined for an organization.

To use this endpoint, the authenticated user must be one of:

  • An administrator for the organization.
  • A user, or a user on a team, with the fine-grained permission of custom_properties_org_definitions_manager in the organization.

“Create or update a custom property for an organization”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:admin

“Create or update a custom property for an organization”的参数

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

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

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

The organization name. The name is not case sensitive.

custom_property_name string 必须

The custom property name. The name is case sensitive.

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

The type of the value for the property

可以是以下选项之一: string, single_select

required boolean

Whether the property is required.

default_value null or string or array

Default value of the property

description string or null

Short description of the property

allowed_values array of strings or null

An ordered list of the allowed values of the property. The property can have up to 200 allowed values.

“Create or update a custom property for an organization”的 HTTP 响应状态代码

状态代码说明
200

OK

403

Forbidden

404

Resource not found

“Create or update a custom property for an organization”的示例代码

请求示例

put/orgs/{org}/properties/schema/{custom_property_name}
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/orgs/ORG/properties/schema/CUSTOM_PROPERTY_NAME \ -d '{"value_type":"single_select","required":true,"default_value":"production","description":"Prod or dev environment","allowed_values":["production","development"]}'

Response

Status: 200
{ "property_name": "environment", "value_type": "single_select", "required": true, "default_value": "production", "description": "Prod or dev environment", "allowed_values": [ "production", "development" ] }

Remove a custom property for an organization

Removes a custom property that is defined for an organization.

To use this endpoint, the authenticated user must be one of:

  • An administrator for the organization.
  • A user, or a user on a team, with the fine-grained permission of custom_properties_org_definitions_manager in the organization.

“Remove a custom property for an organization”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:admin

“Remove a custom property for an organization”的参数

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

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

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

The organization name. The name is not case sensitive.

custom_property_name string 必须

The custom property name. The name is case sensitive.

“Remove a custom property for an organization”的 HTTP 响应状态代码

状态代码说明
204

A header with no content is returned.

403

Forbidden

404

Resource not found

“Remove a custom property for an organization”的示例代码

请求示例

delete/orgs/{org}/properties/schema/{custom_property_name}
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/orgs/ORG/properties/schema/CUSTOM_PROPERTY_NAME

A header with no content is returned.

Status: 204

List custom property values for organization repositories

Lists organization repositories with all of their custom property values. Organization members can read these properties.

“List custom property values for organization repositories”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:read

“List custom property values for organization repositories”的参数

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

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

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

The organization name. The name is not case sensitive.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

默认: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

默认: 1

repository_query string

Finds repositories in the organization with a query containing one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as the web interface for GitHub. To learn more about the format of the query, see Constructing a search query. See "Searching for repositories" for a detailed list of qualifiers.

“List custom property values for organization repositories”的 HTTP 响应状态代码

状态代码说明
200

OK

403

Forbidden

404

Resource not found

“List custom property values for organization repositories”的示例代码

请求示例

get/orgs/{org}/properties/values
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/orgs/ORG/properties/values

Response

Status: 200
[ { "repository_id": 1296269, "repository_name": "Hello-World", "repository_full_name": "octocat/Hello-World", "properties": [ { "property_name": "environment", "value": "production" }, { "property_name": "service", "value": "web" }, { "property_name": "team", "value": "octocat" } ] } ]

Create or update custom property values for organization repositories

Create new or update existing custom property values for repositories in a batch that belong to an organization. Each target repository will have its custom property values updated to match the values provided in the request.

A maximum of 30 repositories can be updated in a single request.

Using a value of null for a custom property will remove or 'unset' the property value from the repository.

To use this endpoint, the authenticated user must be one of:

  • An administrator for the organization.
  • A user, or a user on a team, with the fine-grained permission of custom_properties_org_values_editor in the organization.

“Create or update custom property values for organization repositories”的细粒度访问令牌

此终结点适用于以下令牌类型:

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

  • organization_custom_properties:write

“Create or update custom property values for organization repositories”的参数

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

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

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

The organization name. The name is not case sensitive.

正文参数
名称, 类型, 说明
repository_names array of strings 必须

The names of repositories that the custom property values will be applied to.

properties array of objects 必须

List of custom property names and associated values to apply to the repositories.

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

The name of the property

value null or string or array 必须

The value assigned to the property

“Create or update custom property values for organization repositories”的 HTTP 响应状态代码

状态代码说明
204

No Content when custom property values are successfully created or updated

403

Forbidden

404

Resource not found

422

Validation failed, or the endpoint has been spammed.

“Create or update custom property values for organization repositories”的示例代码

请求示例

patch/orgs/{org}/properties/values
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/properties/values \ -d '{"repository_names":["Hello-World","octo-repo"],"properties":[{"property_name":"environment","value":"production"},{"property_name":"service","value":"web"},{"property_name":"team","value":"octocat"}]}'

No Content when custom property values are successfully created or updated

Status: 204