semantic_release.hvcs module

HVCS

class semantic_release.hvcs.Base[source]

Bases: object

static api_url() str[source]
static check_build_status(owner: str, repo: str, ref: str) bool[source]
static domain() str[source]
classmethod post_release_changelog(owner: str, repo: str, version: str, changelog: str) bool[source]
static token() Optional[str][source]
classmethod upload_dists(owner: str, repo: str, version: str, path: str) bool[source]
class semantic_release.hvcs.Gitea[source]

Bases: Base

Gitea helper class

DEFAULT_API_PATH = '/api/v1'
DEFAULT_DOMAIN = 'gitea.com'
static api_url() str[source]

Gitea api_url property

Returns:

The Gitea API URL

static auth() Optional[TokenAuth][source]

Gitea token property

Returns:

The Gitea token environment variable (GITEA_TOKEN) value

static check_build_status(owner: str, repo: str, ref: str) bool[source]

Check build status

https://gitea.com/api/swagger#/repository/repoCreateStatus

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • ref – The sha1 hash of the commit ref

Returns:

Was the build status success?

classmethod create_release(owner: str, repo: str, tag: str, changelog: str) bool[source]

Create a new release

https://gitea.com/api/swagger#/repository/repoCreateRelease

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • tag – Tag to create release for

  • changelog – The release notes for this version

Returns:

Whether the request succeeded

static domain() str[source]

Gitea domain property

Returns:

The Gitea domain

classmethod edit_release(owner: str, repo: str, id: int, changelog: str) bool[source]

Edit a release with updated change notes

https://gitea.com/api/swagger#/repository/repoEditRelease

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • id – ID of release to update

  • changelog – The release notes for this version

Returns:

Whether the request succeeded

classmethod get_release(owner: str, repo: str, tag: str) Optional[int][source]

Get a release by its tag name

https://gitea.com/api/swagger#/repository/repoGetReleaseByTag

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • tag – Tag to get release for

Returns:

ID of found release

classmethod post_release_changelog(owner: str, repo: str, version: str, changelog: str) bool[source]

Post release changelog

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • version – The version number

  • changelog – The release notes for this version

Returns:

The status of the request

static session(raise_for_status=True, retry: Union[Retry, bool, int] = True) Session[source]
static token() Optional[str][source]

Gitea token property

Returns:

The Gitea token environment variable (GITEA_TOKEN) value

classmethod upload_asset(owner: str, repo: str, release_id: int, file: str, label: str = None) bool[source]

Upload an asset to an existing release

https://gitea.com/api/swagger#/repository/repoCreateReleaseAttachment

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • release_id – ID of the release to upload to

  • file – Path of the file to upload

  • label – Custom label for this file

Returns:

The status of the request

classmethod upload_dists(owner: str, repo: str, version: str, path: str) bool[source]

Upload distributions to a release

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • version – Version to upload for

  • path – Path to the dist directory

Returns:

The status of the request

class semantic_release.hvcs.Github[source]

Bases: Base

Github helper class

DEFAULT_DOMAIN = 'github.com'
static api_url() str[source]

Github api_url property

Returns:

The Github API URL

static auth() Optional[TokenAuth][source]

Github token property

Returns:

The Github token environment variable (GH_TOKEN) value

static check_build_status(owner: str, repo: str, ref: str) bool[source]

Check build status

https://docs.github.com/rest/reference/repos#get-the-combined-status-for-a-specific-reference

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • ref – The sha1 hash of the commit ref

Returns:

Was the build status success?

classmethod create_release(owner: str, repo: str, tag: str, changelog: str) bool[source]

Create a new release

https://docs.github.com/rest/reference/repos#create-a-release

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • tag – Tag to create release for

  • changelog – The release notes for this version

Returns:

Whether the request succeeded

static domain() str[source]

Github domain property

Returns:

The Github domain

classmethod edit_release(owner: str, repo: str, id: int, changelog: str) bool[source]

Edit a release with updated change notes

https://docs.github.com/rest/reference/repos#update-a-release

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • id – ID of release to update

  • changelog – The release notes for this version

Returns:

Whether the request succeeded

classmethod get_asset_upload_url(owner: str, repo: str, release_id: str) Optional[str][source]

Get the correct upload url for a release

https://docs.github.com/en/enterprise-server@3.5/rest/releases/releases#get-a-release

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • release_id – ID of the release to upload to

Returns:

URL found to upload for a release

classmethod get_release(owner: str, repo: str, tag: str) Optional[int][source]

Get a release by its tag name

https://docs.github.com/rest/reference/repos#get-a-release-by-tag-name

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • tag – Tag to get release for

Returns:

ID of found release

classmethod post_release_changelog(owner: str, repo: str, version: str, changelog: str) bool[source]

Post release changelog

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • version – The version number

  • changelog – The release notes for this version

Returns:

The status of the request

static session(raise_for_status=True, retry: Union[Retry, bool, int] = True) Session[source]
static token() Optional[str][source]

Github token property

Returns:

The Github token environment variable (GH_TOKEN) value

classmethod upload_asset(owner: str, repo: str, release_id: int, file: str, label: str = None) bool[source]

Upload an asset to an existing release

https://docs.github.com/rest/reference/repos#upload-a-release-asset

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • release_id – ID of the release to upload to

  • file – Path of the file to upload

  • label – Custom label for this file

Returns:

The status of the request

classmethod upload_dists(owner: str, repo: str, version: str, path: str) bool[source]

Upload distributions to a release

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • version – Version to upload for

  • path – Path to the dist directory

Returns:

The status of the request

class semantic_release.hvcs.Gitlab[source]

Bases: Base

Gitlab helper class

static api_url() str[source]

Gitlab api_url property

Returns:

The Gitlab instance API url

static check_build_status(owner: str, repo: str, ref: str) bool[source]

Check last build status

Parameters:
  • owner – The owner namespace of the repository. It includes all groups and subgroups.

  • repo – The repository name

  • ref – The sha1 hash of the commit ref

Returns:

the status of the pipeline (False if a job failed)

static domain() str[source]

Gitlab domain property

Returns:

The Gitlab instance domain

classmethod post_release_changelog(owner: str, repo: str, version: str, changelog: str) bool[source]

Post release changelog

Parameters:
  • owner – The owner namespace of the repository

  • repo – The repository name

  • version – The version number

  • changelog – The release notes for this version

Returns:

The status of the request

static token() Optional[str][source]

Gitlab token property

Returns:

The Gitlab token environment variable (GL_TOKEN) value

class semantic_release.hvcs.TokenAuth(token)[source]

Bases: AuthBase

requests Authentication for token based authorization

semantic_release.hvcs.check_build_status(owner: str, repository: str, ref: str) bool[source]

Checks the build status of a commit on the api from your hosted version control provider.

Parameters:
  • owner – The owner of the repository

  • repository – The repository name

  • ref – Commit or branch reference

Returns:

A boolean with the build status

semantic_release.hvcs.check_token() bool[source]

Checks whether there exists a token or not.

Returns:

A boolean telling if there is a token.

semantic_release.hvcs.get_domain() Optional[str][source]

Returns the domain for the current VCS

Returns:

The domain in string form

semantic_release.hvcs.get_hvcs() Base[source]

Get HVCS helper class

Raises:

ImproperConfigurationError – if the hvcs option provided is not valid

semantic_release.hvcs.get_token() Optional[str][source]

Returns the token for the current VCS

Returns:

The token in string form

semantic_release.hvcs.post_changelog(owner: str, repository: str, version: str, changelog: str) bool[source]

Posts the changelog to the current hvcs release API

Parameters:
  • owner – The owner of the repository

  • repository – The repository name

  • version – A string with the new version

  • changelog – A string with the changelog in correct format

Returns:

a tuple with success status and payload from hvcs

semantic_release.hvcs.upload_to_release(owner: str, repository: str, version: str, path: str) bool[source]

Upload distributions to the current hvcs release API

Parameters:
  • owner – The owner of the repository

  • repository – The repository name

  • version – A string with the version to upload for

  • path – Path to dist directory

Returns:

Status of the request