このバージョンの GitHub Enterprise サーバーはこの日付をもって終了となりました: 2024-03-26. 重大なセキュリティの問題に対してであっても、パッチリリースは作成されません。 パフォーマンスの向上、セキュリティの向上、新機能の向上を図るために、最新バージョンの GitHub Enterprise サーバーにアップグレードしてください。 アップグレードに関するヘルプについては、GitHub Enterprise サポートにお問い合わせください。
pre-receive フック用の REST API エンドポイント
REST API を使い、pre-receive フックを作成、一覧表示、更新、削除します。
pre-receiveフックについて
これらのエンドポイントは、認証されたサイト管理者のみが利用できます。 通常のユーザーは 404 応答を受け取ります。
オブジェクトの属性
pre-receive フック
| 名前 | 種類 | 説明 | 
|---|---|---|
name | string | フックの名前。 | 
script | string | フックが実行するスクリプト。 | 
script_repository | object | スクリプトが保存されているGitHubリポジトリ。 | 
environment | object | スクリプトが実行される pre-receive 環境。 | 
enforcement | string | このフックの適用状態。 | 
allow_downstream_configuration | boolean | 適用の Org レベルまたは repo レベルでのオーバーライドの可否。 | 
_適用_に使用できる値は enabled、disabledとtestingです。 disabled は、pre-receive フックが実行されないことを示します。 enabled は、それが実行され、ゼロ以外の状態になるプッシュを拒否することを示します。 testing は、スクリプトは実行されるが、プッシュが拒否されないことを示します。
List pre-receive hooks
"List pre-receive hooks" のパラメーター
| 名前, Type, 説明 | 
|---|
accept string Setting to   | 
| 名前, Type, 説明 | 
|---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Default:   | 
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Default:   | 
direction string The direction to sort the results by. Default:  次のいずれかにできます:   | 
sort string The property to sort the results by. Default:  次のいずれかにできます:   | 
"List pre-receive hooks" の HTTP 応答状態コード
| 状態コード | 説明 | 
|---|---|
200 | OK  | 
"List pre-receive hooks" のコード サンプル
要求の例
curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooksResponse
Status: 200[
  {
    "id": 1,
    "name": "Check Commits",
    "enforcement": "disabled",
    "script": "scripts/commmit_check.sh",
    "script_repository": {
      "id": 595,
      "full_name": "DevIT/hooks",
      "url": "https://github.example.com/api/v3/repos/DevIT/hooks",
      "html_url": "https://github.example.com/DevIT/hooks"
    },
    "environment": {
      "id": 2,
      "name": "DevTools Hook Env",
      "image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
      "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
      "html_url": "https://github.example.com/admin/pre-receive-environments/2",
      "default_environment": false,
      "created_at": "2016-05-20T11:35:45-05:00",
      "hooks_count": 1,
      "download": {
        "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
        "state": "success",
        "downloaded_at": "2016-05-26T07:42:53-05:00",
        "message": null
      }
    },
    "allow_downstream_configuration": false
  }
]Create a pre-receive hook
"Create a pre-receive hook" のパラメーター
| 名前, Type, 説明 | 
|---|
accept string Setting to   | 
| 名前, Type, 説明 | 
|---|
name string 必須The name of the hook.  | 
script string 必須The script that the hook runs.  | 
script_repository object 必須The GitHub repository where the script is kept.  | 
environment object 必須The pre-receive environment where the script is executed.  | 
enforcement string The state of enforcement for this hook. default:   | 
allow_downstream_configuration boolean Whether enforcement can be overridden at the org or repo level. default:   | 
"Create a pre-receive hook" の HTTP 応答状態コード
| 状態コード | 説明 | 
|---|---|
201 | Created  | 
"Create a pre-receive hook" のコード サンプル
要求の例
curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks \
  -d '{"name":"Check Commits","script":"scripts/commit_check.sh","enforcement":"disabled","allow_downstream_configuration":false,"script_repository":{"full_name":"DevIT/hooks"},"environment":{"id":2}}'Response
Status: 201{
  "id": 1,
  "name": "Check Commits",
  "enforcement": "disabled",
  "script": "scripts/commmit_check.sh",
  "script_repository": {
    "id": 595,
    "full_name": "DevIT/hooks",
    "url": "https://github.example.com/api/v3/repos/DevIT/hooks",
    "html_url": "https://github.example.com/DevIT/hooks"
  },
  "environment": {
    "id": 2,
    "name": "DevTools Hook Env",
    "image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
    "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
    "html_url": "https://github.example.com/admin/pre-receive-environments/2",
    "default_environment": false,
    "created_at": "2016-05-20T11:35:45-05:00",
    "hooks_count": 1,
    "download": {
      "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
      "state": "success",
      "downloaded_at": "2016-05-26T07:42:53-05:00",
      "message": null
    }
  },
  "allow_downstream_configuration": false
}Get a pre-receive hook
"Get a pre-receive hook" のパラメーター
| 名前, Type, 説明 | 
|---|
accept string Setting to   | 
| 名前, Type, 説明 | 
|---|
pre_receive_hook_id integer 必須The unique identifier of the pre-receive hook.  | 
"Get a pre-receive hook" の HTTP 応答状態コード
| 状態コード | 説明 | 
|---|---|
200 | OK  | 
"Get a pre-receive hook" のコード サンプル
要求の例
curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_IDResponse
Status: 200{
  "id": 1,
  "name": "Check Commits",
  "enforcement": "disabled",
  "script": "scripts/commmit_check.sh",
  "script_repository": {
    "id": 595,
    "full_name": "DevIT/hooks",
    "url": "https://github.example.com/api/v3/repos/DevIT/hooks",
    "html_url": "https://github.example.com/DevIT/hooks"
  },
  "environment": {
    "id": 2,
    "name": "DevTools Hook Env",
    "image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
    "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
    "html_url": "https://github.example.com/admin/pre-receive-environments/2",
    "default_environment": false,
    "created_at": "2016-05-20T11:35:45-05:00",
    "hooks_count": 1,
    "download": {
      "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
      "state": "success",
      "downloaded_at": "2016-05-26T07:42:53-05:00",
      "message": null
    }
  },
  "allow_downstream_configuration": false
}Update a pre-receive hook
"Update a pre-receive hook" のパラメーター
| 名前, Type, 説明 | 
|---|
accept string Setting to   | 
| 名前, Type, 説明 | 
|---|
pre_receive_hook_id integer 必須The unique identifier of the pre-receive hook.  | 
| 名前, Type, 説明 | 
|---|
name string The name of the hook.  | 
script string The script that the hook runs.  | 
script_repository object The GitHub repository where the script is kept.  | 
environment object The pre-receive environment where the script is executed.  | 
enforcement string The state of enforcement for this hook.  | 
allow_downstream_configuration boolean Whether enforcement can be overridden at the org or repo level.  | 
"Update a pre-receive hook" の HTTP 応答状態コード
| 状態コード | 説明 | 
|---|---|
200 | OK  | 
"Update a pre-receive hook" のコード サンプル
要求の例
curl -L \
  -X PATCH \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \
  -d '{"name":"Check Commits","environment":{"id":1},"allow_downstream_configuration":true}'Response
Status: 200{
  "id": 1,
  "name": "Check Commits",
  "enforcement": "disabled",
  "script": "scripts/commmit_check.sh",
  "script_repository": {
    "id": 595,
    "full_name": "DevIT/hooks",
    "url": "https://github.example.com/api/v3/repos/DevIT/hooks",
    "html_url": "https://github.example.com/DevIT/hooks"
  },
  "environment": {
    "id": 1,
    "name": "Default",
    "image_url": "githubenterprise://internal",
    "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1",
    "html_url": "https://github.example.com/admin/pre-receive-environments/1",
    "default_environment": true,
    "created_at": "2016-05-20T11:35:45-05:00",
    "hooks_count": 1,
    "download": {
      "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1/downloads/latest",
      "state": "success",
      "downloaded_at": "2016-05-26T07:42:53-05:00",
      "message": null
    }
  },
  "allow_downstream_configuration": true
}Delete a pre-receive hook
"Delete a pre-receive hook" のパラメーター
| 名前, Type, 説明 | 
|---|
accept string Setting to   | 
| 名前, Type, 説明 | 
|---|
pre_receive_hook_id integer 必須The unique identifier of the pre-receive hook.  | 
"Delete a pre-receive hook" の HTTP 応答状態コード
| 状態コード | 説明 | 
|---|---|
204 | No Content  | 
"Delete a pre-receive hook" のコード サンプル
要求の例
curl -L \
  -X DELETE \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_IDResponse
Status: 204