environments
Creates, updates, deletes, gets or lists an environments resource.
Overview
| Name | environments |
| Type | Resource |
| Id | github.repos.environments |
Fields
The following fields are returned by SELECT queries:
- get_environment
- get_all_environments
Response
| Name | Datatype | Description |
|---|---|---|
id | integer (int64) | The id of the environment. |
name | string | The name of the environment. (example: staging) |
node_id | string | (example: MDExOkVudmlyb25tZW50NTY3ODA0Mjg=) |
created_at | string (date-time) | The time that the environment was created, in ISO 8601 format. (example: 2020-11-23T22:00:40Z) |
deployment_branch_policy | object | The type of deployment branch policy for this environment. To allow all branches to deploy, set to null. |
html_url | string | (example: https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging) |
protection_rules | array | Built-in deployment protection rules for the environment. |
updated_at | string (date-time) | The time that the environment was last updated, in ISO 8601 format. (example: 2020-11-23T22:00:40Z) |
url | string | (example: https://api.github.com/repos/github/hello-world/environments/staging) |
Response
| Name | Datatype | Description |
|---|---|---|
environments | array | |
total_count | integer | The number of environments in this repository |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_environment | select | owner, repo, environment_name | > [!NOTE] > To get information about name patterns that branches must match in order to deploy to this environment, see "Get a deployment branch policy." Anyone with read access to the repository can use this endpoint. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository. | |
get_all_environments | select | owner, repo | per_page, page | Lists the environments for a repository. Anyone with read access to the repository can use this endpoint. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository. |
create_or_update_environment | insert | owner, repo, environment_name | Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments." > [!NOTE] > To create or update name patterns that branches must match in order to deploy to this environment, see "Deployment branch policies." > [!NOTE] > To create or update secrets for an environment, see "GitHub Actions secrets." OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. | |
delete_an_environment | delete | owner, repo, environment_name | OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
environment_name | string | The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F. |
owner | string | The account owner of the repository. The name is not case sensitive. |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
page | integer | The page number of the results to fetch. For more information, see "Using pagination in the REST API." |
per_page | integer | The number of results per page (max 100). For more information, see "Using pagination in the REST API." |
SELECT examples
- get_environment
- get_all_environments
> [!NOTE]
> To get information about name patterns that branches must match in order to deploy to this environment, see "Get a deployment branch policy."
Anyone with read access to the repository can use this endpoint.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
SELECT
id,
name,
node_id,
created_at,
deployment_branch_policy,
html_url,
protection_rules,
updated_at,
url
FROM github.repos.environments
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND environment_name = '{{ environment_name }}' -- required
;
Lists the environments for a repository.
Anyone with read access to the repository can use this endpoint.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
SELECT
environments,
total_count
FROM github.repos.environments
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND per_page = '{{ per_page }}'
AND page = '{{ page }}'
;
INSERT examples
- create_or_update_environment
- Manifest
Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments."
> [!NOTE]
> To create or update name patterns that branches must match in order to deploy to this environment, see "Deployment branch policies."
> [!NOTE]
> To create or update secrets for an environment, see "GitHub Actions secrets."
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
INSERT INTO github.repos.environments (
wait_timer,
prevent_self_review,
reviewers,
deployment_branch_policy,
owner,
repo,
environment_name
)
SELECT
{{ wait_timer }},
{{ prevent_self_review }},
'{{ reviewers }}',
'{{ deployment_branch_policy }}',
'{{ owner }}',
'{{ repo }}',
'{{ environment_name }}'
RETURNING
id,
name,
node_id,
created_at,
deployment_branch_policy,
html_url,
protection_rules,
updated_at,
url
;
# Description fields are for documentation purposes
- name: environments
props:
- name: owner
value: "{{ owner }}"
description: Required parameter for the environments resource.
- name: repo
value: "{{ repo }}"
description: Required parameter for the environments resource.
- name: environment_name
value: "{{ environment_name }}"
description: Required parameter for the environments resource.
- name: wait_timer
value: {{ wait_timer }}
description: |
The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days).
- name: prevent_self_review
value: {{ prevent_self_review }}
description: |
Whether or not a user who created the job is prevented from approving their own job.
- name: reviewers
description: |
The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed.
value:
- type: "{{ type }}"
id: {{ id }}
- name: deployment_branch_policy
description: |
The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.
value:
protected_branches: {{ protected_branches }}
custom_branch_policies: {{ custom_branch_policies }}
DELETE examples
- delete_an_environment
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
DELETE FROM github.repos.environments
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND environment_name = '{{ environment_name }}' --required
;