Release

Learn and practice the functionalities of release in the GitHub API.

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

tag_name

string

body

This is the name of the tag.

target_commitish

string

body

This is the value calculated based on where the Git tag is created from.

name

string

body

This is the release name.

body

string

body

This is the description of the tag’s contents.

draft

boolean

body

This is true if draft creation is enabled. Otherwise, it’s false.

prerelease

boolean

body

This is true if the release is identified as prerelease. It is false if the release is identified as a full release.

discussion_category_name

string

body

This is the discussion of the category linked to the release, if specified.

generate_release_notes

boolean

body

This is true if the name and body of the release is to be automatically generated. Otherwise, it is false.

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.

Press + to interact
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.

Press + to interact
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:

Press + to interact
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.

Press + to interact
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.

Press + to interact
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.')