Release
Learn and practice the functionalities of release in the GitHub API.
We'll cover the following
Overview
A GitHub release is a deployable iteration of software packaged with binary files and release notes. It acts the same way as an application update. The binary files help users find a specific version of the application. The release notes include all the details of upgrades or features added to the product in that release. Releases are based on Git tags denoting a point in the repository’s history. These tags are essential in defining a release. The tag date will vary from the release date if they are created on different dates.
Create a release
A user must have push
access to the repository to create a release. The table below shows the parameters in the body to create a release.
Parameters for creating a release
Name | Type | Present In | Description |
| string | body | This is the name of the tag. |
| string | body | This is the value calculated based on where the Git tag is created from. |
| string | body | This is the release name. |
| string | body | This is the description of the tag’s contents. |
| boolean | body | This is |
| boolean | body | This is |
| string | body | This is the discussion of the category linked to the release, if specified. |
| boolean | body | This is |
Let’s try creating a release by specifying <tag-name>
in line 7. We extract and save the release ID to be used later in the lesson.
headers = {'Authorization': 'token {{ACCESS_TOKEN}}','Accept': 'application/vnd.github.v3+json'}data = json.dumps({'tag_name': '<tag-name>'})url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/releases'response = requests.post(url, headers=headers, data=data)print(json.dumps(response.json(), indent=4))
List releases
The releases that are published are available to everyone. However, draft releases are only available to users with the push
access.
headers = {'Authorization': 'token {{ACCESS_TOKEN}}','Accept': 'application/vnd.github.v3+json'}url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/releases'response = requests.get(url, headers=headers)print(json.dumps(response.json(), indent=4))
Get a release
Let’s run this endpoint to see if we get the release we just created:
headers = {'Authorization': 'token {{ACCESS_TOKEN}}','Accept': 'application/vnd.github.v3+json'}url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/releases/{{RELEASE_ID}}'response = requests.get(url, headers=headers)print(json.dumps(response.json(), indent=4))
Update a release
This is very similar to creating a release. Let’s run the code below to update the tag name of the release we created earlier. Don't forget to specify the new tag name in the place of <new-tag-name>
in line 7.
headers = {'Authorization': 'token {{ACCESS_TOKEN}}','Accept': 'application/vnd.github.v3+json'}data = json.dumps({'tag_name': '<new-tag-name>'})url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/releases/{{RELEASE_ID}}'response = requests.patch(url, headers=headers, data=data)print(json.dumps(response.json(), indent=4))
Delete a release
Finally, we’ll delete the release we’ve created in this lesson. Any user with push
access can perform the delete operation.
headers = {'Authorization': 'token {{ACCESS_TOKEN}}','Accept': 'application/vnd.github.v3+json'}url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/releases/{{RELEASE_ID}}'response = requests.delete(url, headers=headers)if response.status_code == 204:print('The release was deleted successfully.')else:print('Something went wrong.')