Esta versão do GitHub Enterprise foi descontinuada em 2022-10-12. Nenhum lançamento de patch será feito, mesmo para questões críticas de segurança. Para obter melhor desempenho, segurança aprimorada e novos recursos, atualize para a última versão do GitHub Enterprise. Para obter ajuda com a atualização, entre em contato com o suporte do GitHub Enterprise.
We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.
Políticas de branch de implantação
A API de políticas de branch de implantação permite que você gerencie essas políticas personalizadas.
Sobre a API de políticas de branch de implantação
A API de políticas de branch de implantação permite que você especifique padrões de nome personalizados aos quais os branches devem corresponder para a implantação em um ambiente. A propriedade deployment_branch_policy.custom_branch_policies do ambiente deve ser definida como true para usar esses pontos de extremidade. Para atualizar o ambiente deployment_branch_policy, confira "Criar ou atualizar um ambiente". 
Para obter mais informações sobre como restringir implantações de ambiente a determinados branches, confira "Como usar ambientes para implantação".
List deployment branch policies
Lists the deployment branch policies for an environment.
Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.
Parâmetros
| Headers | 
|---|
| Name, Type, Description | 
| acceptstringSetting to  | 
| Path parameters | 
| Name, Type, Description | 
| ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | 
| repostringRequiredThe name of the repository. The name is not case sensitive. | 
| environment_namestringRequiredThe name of the environment. | 
| Query parameters | 
| Name, Type, Description | 
| per_pageintegerThe number of results per page (max 100). Default:  | 
| pageintegerPage number of the results to fetch. Default:  | 
Códigos de status de resposta HTTP
| Código de status | Descrição | 
|---|---|
| 200 | OK | 
Exemplos de código
curl \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policiesResponse
Status: 200{
  "total_count": 2,
  "branch_policies": [
    {
      "id": 361471,
      "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzE=",
      "name": "release/*"
    },
    {
      "id": 361472,
      "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzI=",
      "name": "main"
    }
  ]
}Create a deployment branch policy
Creates a deployment branch policy for an environment.
You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the administration:write permission for the repository to use this endpoint.
Parâmetros
| Headers | 
|---|
| Name, Type, Description | 
| acceptstringSetting to  | 
| Path parameters | 
| Name, Type, Description | 
| ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | 
| repostringRequiredThe name of the repository. The name is not case sensitive. | 
| environment_namestringRequiredThe name of the environment. | 
| Body parameters | 
| Name, Type, Description | 
| namestringRequiredThe name pattern that branches must match in order to deploy to the environment. Wildcard characters will not match  | 
Códigos de status de resposta HTTP
| Código de status | Descrição | 
|---|---|
| 200 | OK | 
| 303 | Response if the same branch name pattern already exists | 
| 404 | Not Found or  | 
Exemplos de código
curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \
  -d '{"name":"release/*"}'Response
Status: 200{
  "id": 364662,
  "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
  "name": "release/*"
}Get a deployment branch policy
Gets a deployment branch policy for an environment.
Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the repo scope. GitHub Apps must have the actions:read permission to use this endpoint.
Parâmetros
| Headers | 
|---|
| Name, Type, Description | 
| acceptstringSetting to  | 
| Path parameters | 
| Name, Type, Description | 
| ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | 
| repostringRequiredThe name of the repository. The name is not case sensitive. | 
| environment_namestringRequiredThe name of the environment. | 
| branch_policy_idintegerRequiredThe unique identifier of the branch policy. | 
Códigos de status de resposta HTTP
| Código de status | Descrição | 
|---|---|
| 200 | OK | 
Exemplos de código
curl \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_IDResponse
Status: 200{
  "id": 364662,
  "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
  "name": "release/*"
}Update a deployment branch policy
Updates a deployment branch policy for an environment.
You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the administration:write permission for the repository to use this endpoint.
Parâmetros
| Headers | 
|---|
| Name, Type, Description | 
| acceptstringSetting to  | 
| Path parameters | 
| Name, Type, Description | 
| ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | 
| repostringRequiredThe name of the repository. The name is not case sensitive. | 
| environment_namestringRequiredThe name of the environment. | 
| branch_policy_idintegerRequiredThe unique identifier of the branch policy. | 
| Body parameters | 
| Name, Type, Description | 
| namestringRequiredThe name pattern that branches must match in order to deploy to the environment. Wildcard characters will not match  | 
Códigos de status de resposta HTTP
| Código de status | Descrição | 
|---|---|
| 200 | OK | 
Exemplos de código
curl \
  -X PUT \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID \
  -d '{"name":"release/*"}'Response
Status: 200{
  "id": 364662,
  "node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
  "name": "release/*"
}Delete a deployment branch policy
Deletes a deployment branch policy for an environment.
You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the administration:write permission for the repository to use this endpoint.
Parâmetros
| Headers | 
|---|
| Name, Type, Description | 
| acceptstringSetting to  | 
| Path parameters | 
| Name, Type, Description | 
| ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | 
| repostringRequiredThe name of the repository. The name is not case sensitive. | 
| environment_namestringRequiredThe name of the environment. | 
| branch_policy_idintegerRequiredThe unique identifier of the branch policy. | 
Códigos de status de resposta HTTP
| Código de status | Descrição | 
|---|---|
| 204 | No Content | 
Exemplos de código
curl \
  -X DELETE \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_IDResponse
Status: 204