Points de terminaison d’API REST pour les règles de protection
Utilisez l’API REST pour créer, configurer et supprimer des règles de protection de déploiement.
Get all deployment protection rules for an environment
Gets all custom deployment protection rules that are enabled for an environment. Anyone with read access to the repository can use this endpoint. For more information about environments, see "Using environments for deployment."
For more information about the app that is providing this custom deployment rule, see the documentation for the GET /apps/{app_slug}
endpoint.
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint with a private repository.
Jetons d’accès affinés pour « Get all deployment protection rules for an environment »
Ce point de terminaison fonctionne avec les types de jetons précis suivants:
- Jetons d’accès utilisateur d’application GitHub
- Jetons d’accès d’installation d’application GitHub
- Jetons d’accès personnel affiné
Le jeton précis doit avoir l’ensemble d’autorisations suivant:
- "Actions" repository permissions (read)
Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.
Paramètres pour « Get all deployment protection rules for an environment »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
environment_name string ObligatoireThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with |
repo string ObligatoireThe name of the repository without the |
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
Codes d’état de la réponse HTTP pour « Get all deployment protection rules for an environment »
Code d’état | Description |
---|---|
200 | List of deployment protection rules |
Exemples de code pour « Get all deployment protection rules for an environment »
Exemple de requête
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules
List of deployment protection rules
Status: 200
{
"total_count": 2,
"custom_deployment_protection_rules": [
{
"id": 3,
"node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv",
"enabled": true,
"app": {
"id": 1,
"node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy",
"slug": "a-custom-app",
"integration_url": "https://HOSTNAME/apps/a-custom-app"
}
},
{
"id": 4,
"node_id": "MDE2OkRlcGxveW1lbnRTdHJ41128",
"enabled": true,
"app": {
"id": 1,
"node_id": "UHVE67RlcGxveW1lbnRTdTY!jfeuy",
"slug": "another-custom-app",
"integration_url": "https://HOSTNAME/apps/another-custom-app"
}
}
]
}
Create a custom deployment protection rule on an environment
Enable a custom deployment protection rule for an environment.
The authenticated user must have admin or owner permissions to the repository to use this endpoint.
For more information about the app that is providing this custom deployment rule, see the documentation for the GET /apps/{app_slug}
endpoint.
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint.
Jetons d’accès affinés pour « Create a custom deployment protection rule on an environment »
Ce point de terminaison fonctionne avec les types de jetons précis suivants:
- Jetons d’accès utilisateur d’application GitHub
- Jetons d’accès d’installation d’application GitHub
- Jetons d’accès personnel affiné
Le jeton précis doit avoir l’ensemble d’autorisations suivant:
- "Administration" repository permissions (write)
Paramètres pour « Create a custom deployment protection rule on an environment »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
environment_name string ObligatoireThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with |
repo string ObligatoireThe name of the repository without the |
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
Nom, Type, Description |
---|
integration_id integer The ID of the custom app that will be enabled on the environment. |
Codes d’état de la réponse HTTP pour « Create a custom deployment protection rule on an environment »
Code d’état | Description |
---|---|
201 | The enabled custom deployment protection rule |
Exemples de code pour « Create a custom deployment protection rule on an environment »
Exemple de requête
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules \
-d '{"integration_id":5}'
The enabled custom deployment protection rule
Status: 201
{
"id": 3,
"node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv",
"enabled": true,
"app": {
"id": 1,
"node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy",
"slug": "a-custom-app",
"integration_url": "https://HOSTNAME/apps/a-custom-app"
}
}
List custom deployment rule integrations available for an environment
Gets all custom deployment protection rule integrations that are available for an environment.
The authenticated user must have admin or owner permissions to the repository to use this endpoint.
For more information about environments, see "Using environments for deployment."
For more information about the app that is providing this custom deployment rule, see "GET an app".
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint with a private repository.
Jetons d’accès affinés pour « List custom deployment rule integrations available for an environment »
Ce point de terminaison fonctionne avec les types de jetons précis suivants:
- Jetons d’accès utilisateur d’application GitHub
- Jetons d’accès d’installation d’application GitHub
- Jetons d’accès personnel affiné
Le jeton précis doit avoir l’ensemble d’autorisations suivant:
- "Administration" repository permissions (read)
Paramètres pour « List custom deployment rule integrations available for an environment »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
environment_name string ObligatoireThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with |
repo string ObligatoireThe name of the repository without the |
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
Nom, Type, Description |
---|
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Default: |
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Default: |
Codes d’état de la réponse HTTP pour « List custom deployment rule integrations available for an environment »
Code d’état | Description |
---|---|
200 | A list of custom deployment rule integrations available for this environment. |
Exemples de code pour « List custom deployment rule integrations available for an environment »
Exemple de requête
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/apps
A list of custom deployment rule integrations available for this environment.
Status: 200
[
{
"total_count": 2
},
{
"available_custom_deployment_protection_rule_integrations": [
{
"id": 1,
"node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy",
"slug": "a-custom-app",
"integration_url": "https://HOSTNAME/apps/a-custom-app"
},
{
"id": 2,
"node_id": "UHVE67RlcGxveW1lbnRTdTY!jfeuy",
"slug": "another-custom-app",
"integration_url": "https://HOSTNAME/apps/another-custom-app"
}
]
}
]
Get a custom deployment protection rule
Gets an enabled custom deployment protection rule for an environment. Anyone with read access to the repository can use this endpoint. For more information about environments, see "Using environments for deployment."
For more information about the app that is providing this custom deployment rule, see GET /apps/{app_slug}
.
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint with a private repository.
Jetons d’accès affinés pour « Get a custom deployment protection rule »
Ce point de terminaison fonctionne avec les types de jetons précis suivants:
- Jetons d’accès utilisateur d’application GitHub
- Jetons d’accès d’installation d’application GitHub
- Jetons d’accès personnel affiné
Le jeton précis doit avoir l’ensemble d’autorisations suivant:
- "Actions" repository permissions (read)
Ce point de terminaison peut être utilisé sans authentification ou sans les autorisations mentionnées ci-dessus si seules les ressources publiques sont demandées.
Paramètres pour « Get a custom deployment protection rule »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
repo string ObligatoireThe name of the repository without the |
environment_name string ObligatoireThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with |
protection_rule_id integer ObligatoireThe unique identifier of the protection rule. |
Codes d’état de la réponse HTTP pour « Get a custom deployment protection rule »
Code d’état | Description |
---|---|
200 | OK |
Exemples de code pour « Get a custom deployment protection rule »
Exemple de requête
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/PROTECTION_RULE_ID
Response
Status: 200
{
"id": 3,
"node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv",
"enabled": true,
"app": {
"id": 1,
"node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy",
"slug": "a-custom-app",
"integration_url": "https://HOSTNAME/apps/a-custom-app"
}
}
Disable a custom protection rule for an environment
Disables a custom deployment protection rule for an environment.
The authenticated user must have admin or owner permissions to the repository to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint.
Jetons d’accès affinés pour « Disable a custom protection rule for an environment »
Ce point de terminaison fonctionne avec les types de jetons précis suivants:
- Jetons d’accès utilisateur d’application GitHub
- Jetons d’accès d’installation d’application GitHub
- Jetons d’accès personnel affiné
Le jeton précis doit avoir l’ensemble d’autorisations suivant:
- "Administration" repository permissions (write)
Paramètres pour « Disable a custom protection rule for an environment »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
environment_name string ObligatoireThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with |
repo string ObligatoireThe name of the repository without the |
owner string ObligatoireThe account owner of the repository. The name is not case sensitive. |
protection_rule_id integer ObligatoireThe unique identifier of the protection rule. |
Codes d’état de la réponse HTTP pour « Disable a custom protection rule for an environment »
Code d’état | Description |
---|---|
204 | No Content |
Exemples de code pour « Disable a custom protection rule for an environment »
Exemple de requête
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/PROTECTION_RULE_ID
Response
Status: 204