{"meta":{"title":"リポジトリの pre-receive フック用の REST API エンドポイント","intro":"REST API を使用して、リポジトリで使用可能な pre-receive フックの適用を表示および変更します。","product":"REST API","breadcrumbs":[{"href":"/ja/enterprise-server@3.17/rest","title":"REST API"},{"href":"/ja/enterprise-server@3.17/rest/enterprise-admin","title":"企業管理"},{"href":"/ja/enterprise-server@3.17/rest/enterprise-admin/repo-pre-receive-hooks","title":"リポジトリの事前受け取りフック"}],"documentType":"article"},"body":"# リポジトリの pre-receive フック用の REST API エンドポイント\n\nREST API を使用して、リポジトリで使用可能な pre-receive フックの適用を表示および変更します。\n\n## リポジトリの pre-receive フックについて\n\n> \\[!NOTE]\n> これらのエンドポイントでは、personal access token (classic) を使う認証のみがサポートされます。 詳しくは、「[個人用アクセス トークンを管理する](/ja/enterprise-server@3.17/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)」をご覧ください。\n\n| 名前                  | タイプ      | 説明                     |\n| ------------------- | -------- | ---------------------- |\n| `name`              | `string` | フックの名前。                |\n| `enforcement`       | `string` | このリポジトリでのフックの適用状態。     |\n| `configuration_url` | `string` | 適用設定されているエンドポイントの URL。 |\n\n\\_適用\\_に使用できる値は `enabled`、`disabled`と`testing`です。\n`disabled` は、pre-receive フックが実行されないことを示します。\n`enabled` は、実行時に結果がゼロ以外のステータスとなった場合にプッシュを拒否することを示しています。\n`testing` は、スクリプトは実行されるが、プッシュが拒否されないことを示します。\n\n`configuration_url` は、このリポジトリ、その organization の所有者、またはグローバル設定へのリンクである場合があります。\n`configuration_url` のエンドポイントにアクセスする権限は、所有者またはサイト管理者レベルで決定されます。\n\n> \\[!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.\n\n## List pre-receive hooks for a repository\n\n```\nGET /repos/{owner}/{repo}/pre-receive-hooks\n```\n\nList all pre-receive hooks that are enabled or testing for this repository as well as any disabled hooks that are allowed to be enabled at the repository level. Pre-receive hooks that are disabled at a higher level and are not configurable will not be listed.\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* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n* **`direction`** (string)\n  The direction to sort the results by.\n  Default: `desc`\n  Can be one of: `asc`, `desc`\n\n* **`sort`** (string)\n  Default: `created`\n  Can be one of: `created`, `updated`, `name`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks\n```\n\n**Response schema (Status: 200):**\n\nArray of objects:\n\n* `id`: integer\n* `name`: string\n* `enforcement`: string\n* `configuration_url`: string\n\n## Get a pre-receive hook for a repository\n\n```\nGET /repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}\n```\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* **`pre_receive_hook_id`** (integer) (required)\n  The unique identifier of the pre-receive hook.\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID\n```\n\n**Response schema (Status: 200):**\n\n* `id`: integer\n* `name`: string\n* `enforcement`: string\n* `configuration_url`: string\n\n## Update pre-receive hook enforcement for a repository\n\n```\nPATCH /repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}\n```\n\nFor pre-receive hooks which are allowed to be configured at the repo level, you can set enforcement\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* **`pre_receive_hook_id`** (integer) (required)\n  The unique identifier of the pre-receive hook.\n\n#### Body parameters\n\n* **`enforcement`** (string)\n  The state of enforcement for the hook on this repository.\n  Can be one of: `enabled`, `disabled`, `testing`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \\\n  -d '{\n  \"enforcement\": \"enabled\"\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get a pre-receive hook for a repository](#get-a-pre-receive-hook-for-a-repository).\n\n## Remove pre-receive hook enforcement for a repository\n\n```\nDELETE /repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}\n```\n\nDeletes any overridden enforcement on this repository for the specified hook.\nResponds with effective values inherited from owner and/or global level.\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* **`pre_receive_hook_id`** (integer) (required)\n  The unique identifier of the pre-receive hook.\n\n### HTTP response status codes\n\n* **200** - Responds with effective values inherited from owner and/or global level.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get a pre-receive hook for a repository](#get-a-pre-receive-hook-for-a-repository)."}