Skip to main content

代码空间计算机

代码空间计算机 API 允许用户确定哪些计算机类型可用于在给定存储库上或作为经过身份验证的用户创建代码空间。

关于代码空间计算机 API

代码空间计算机 API 允许用户确定哪些计算机类型可用于在给定存储库上或作为经过身份验证的用户创建代码空间。 更多信息请参阅“关于计算机类型”。

您也可以通过更新其 machine 属性来更改现有代码空间的计算机时使用此信息。 计算机更新将在下次重新启动代码空间时进行。 更多信息请参阅“更改代码空间的计算机类型”。

List available machine types for a repository

List the machine types available for a given repository based on its configuration.

You must authenticate using an access token with the codespace scope to use this endpoint.

GitHub Apps must have write access to the codespaces_metadata repository permission to use this endpoint.

参数

标头
名称, 类型, 描述
acceptstring

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

路径参数
名称, 类型, 描述
ownerstring必选

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

repostring必选

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

查询参数
名称, 类型, 描述
locationstring

The location to check for available machines. Assigned by IP if not provided.

client_ipstring

IP for location auto-detection when proxying a request

HTTP 响应状态代码

状态代码描述
200

OK

304

Not modified

401

Requires authentication

403

Forbidden

404

Resource not found

500

Internal Error

代码示例

get/repos/{owner}/{repo}/codespaces/machines
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <TOKEN>" \ https://api.github.com/repos/OWNER/REPO/codespaces/machines

Response

Status: 200
{ "total_count": 2, "machines": [ { "name": "standardLinux", "display_name": "4 cores, 8 GB RAM, 64 GB storage", "operating_system": "linux", "storage_in_bytes": 68719476736, "memory_in_bytes": 8589934592, "cpus": 4 }, { "name": "premiumLinux", "display_name": "8 cores, 16 GB RAM, 64 GB storage", "operating_system": "linux", "storage_in_bytes": 68719476736, "memory_in_bytes": 17179869184, "cpus": 8 } ] }

List machine types for a codespace

List the machine types a codespace can transition to use.

You must authenticate using an access token with the codespace scope to use this endpoint.

GitHub Apps must have read access to the codespaces_metadata repository permission to use this endpoint.

参数

标头
名称, 类型, 描述
acceptstring

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

路径参数
名称, 类型, 描述
codespace_namestring必选

The name of the codespace.

HTTP 响应状态代码

状态代码描述
200

OK

304

Not modified

401

Requires authentication

403

Forbidden

404

Resource not found

500

Internal Error

代码示例

get/user/codespaces/{codespace_name}/machines
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <TOKEN>" \ https://api.github.com/user/codespaces/CODESPACE_NAME/machines

Response

Status: 200
{ "total_count": 2, "machines": [ { "name": "standardLinux", "display_name": "4 cores, 8 GB RAM, 64 GB storage", "operating_system": "linux", "storage_in_bytes": 68719476736, "memory_in_bytes": 8589934592, "cpus": 4 }, { "name": "premiumLinux", "display_name": "8 cores, 16 GB RAM, 64 GB storage", "operating_system": "linux", "storage_in_bytes": 68719476736, "memory_in_bytes": 17179869184, "cpus": 8 } ] }