{"meta":{"title":"代码质量的 REST API 端点","intro":"使用 REST API 管理代码质量配置。","product":"REST API","breadcrumbs":[{"href":"/zh/rest","title":"REST API"},{"href":"/zh/rest/code-quality","title":"代码质量"},{"href":"/zh/rest/code-quality/code-quality","title":"代码质量"}],"documentType":"article"},"body":"# 代码质量的 REST API 端点\n\n使用 REST API 管理代码质量配置。\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.\n\n## List code quality findings for a repository\n\n```\nGET /repos/{owner}/{repo}/code-quality/findings\n```\n\nLists code quality findings for a repository.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with private or public repositories, or the public_repo scope to use this endpoint with only public repositories.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n- **`direction`** (string)\n  The direction to sort the results by.\n  Default: `desc`\n  Can be one of: `asc`, `desc`\n\n- **`before`** (string)\n  A cursor, as given in the Link header. If specified, the query only searches for results before this cursor. For more information, see \"Using pagination in the REST API.\"\n\n- **`after`** (string)\n  A cursor, as given in the Link header. If specified, the query only searches for results after this cursor. For more information, see \"Using pagination in the REST API.\"\n\n- **`state`** (string)\n  If specified, only code quality findings with this state will be returned.\n  Can be one of: `open`, `dismissed`\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **403** - Response if the user is not authorized to access Code quality for this repository.\n\n- **404** - Resource not found\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/code-quality/findings\n```\n\n**Response schema (Status: 200):**\n\nArray of objects:\n  * `number`: required, integer\n  * `state`: required, string, enum: `open`, `dismissed`\n  * `url`: required, string, format: uri\n  * `rule`: required, object:\n    * `id`: required, string\n    * `title`: required, string\n    * `description`: required, string\n    * `help`: string\n    * `severity`: required, string, enum: `error`, `warning`, `note`, `none`\n    * `category`: required, string, enum: `none`, `maintainability`, `reliability`\n  * `location`: required, object:\n    * `path`: required, string\n    * `start_line`: integer\n    * `start_column`: integer\n    * `end_line`: integer\n    * `end_column`: integer\n  * `message`: required, object:\n    * `text`: required, string\n    * `markdown`: required, string\n  * `created_at`: string, format: date-time\n\n## Get a code quality finding\n\n```\nGET /repos/{owner}/{repo}/code-quality/findings/{finding_number}\n```\n\nGets a single code quality finding.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with private or public repositories, or the public_repo scope to use this endpoint with only public repositories.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`finding_number`** (integer) (required)\n  The number that identifies a finding.\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **403** - Response if the user is not authorized to access Code quality for this repository.\n\n- **404** - Resource not found\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/code-quality/findings/FINDING_NUMBER\n```\n\n**Response schema (Status: 200):**\n\n* `number`: required, integer\n* `state`: required, string, enum: `open`, `dismissed`\n* `url`: required, string, format: uri\n* `rule`: required, object:\n  * `id`: required, string\n  * `title`: required, string\n  * `description`: required, string\n  * `help`: string\n  * `severity`: required, string, enum: `error`, `warning`, `note`, `none`\n  * `category`: required, string, enum: `none`, `maintainability`, `reliability`\n* `location`: required, object:\n  * `path`: required, string\n  * `start_line`: integer\n  * `start_column`: integer\n  * `end_line`: integer\n  * `end_column`: integer\n* `message`: required, object:\n  * `text`: required, string\n  * `markdown`: required, string\n* `created_at`: string, format: date-time\n\n## Get a code quality setup configuration\n\n```\nGET /repos/{owner}/{repo}/code-quality/setup\n```\n\nGets a code quality setup configuration.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with private or public repositories, or the public_repo scope to use this endpoint with only public repositories.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **403** - Response if the user is not authorized to access Code quality for this repository.\n\n- **404** - Resource not found\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/code-quality/setup\n```\n\n**Response schema (Status: 200):**\n\n* `state`: string, enum: `configured`, `not-configured`\n* `languages`: array of string, enum: `csharp`, `go`, `java-kotlin`, `javascript-typescript`, `python`, `ruby`, `rust`\n* `runner_type`: string or null, enum: `standard`, `labeled`, `null`\n* `runner_label`: string or null\n* `updated_at`: string or null, format: date-time\n* `schedule`: string or null, enum: `weekly`, `null`\n\n## Update a code quality setup configuration\n\n```\nPATCH /repos/{owner}/{repo}/code-quality/setup\n```\n\nUpdates a code quality setup configuration.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with private or public repositories, or the public_repo scope to use this endpoint with only public repositories.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n#### Body parameters\n\n- **`state`** (string)\n  The desired state of code quality setup.\n  Can be one of: `configured`, `not-configured`\n\n- **`runner_type`** (string)\n  Runner type to be used.\n  Can be one of: `standard`, `labeled`\n\n- **`runner_label`** (string or null)\n  Runner label to be used if the runner type is labeled.\n\n- **`languages`** (array of strings)\n  Languages to be analyzed.\nSupported values are: csharp, go, java-kotlin, javascript-typescript, python, ruby\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **202** - Accepted\n\n- **403** - Response if the repository is archived or if Code quality is not enabled for this repository\n\n- **404** - Resource not found\n\n- **409** - Response if there is already a code quality setup configuration update in progress\n\n- **422** - Response if the configuration change cannot be made\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/repos/OWNER/REPO/code-quality/setup \\\n  -d '{\n  \"state\": \"configured\",\n  \"languages\": [\n    \"javascript-typescript\",\n    \"python\",\n    \"ruby\"\n  ]\n}'\n```\n\n**Response schema (Status: 202):**\n\n* `run_id`: integer\n* `run_url`: string"}