ocebuild.sources.github#

Methods for formatting and retrieving GitHub source URLs.

Module Contents#

Functions#

github_api_request(→ any)

Gets a GitHub API request.

github_rate_limit(→ int)

Gets the GitHub API rate limit.

get_latest_commit(repository[, branch])

Get the latest commit of a branch in a GitHub repository.

github_suite_id(→ Union[int, None])

Gets the GitHub check suite ID for a given commit.

github_tag_names(→ Union[List[str], Tuple[List[str], ...)

Returns a list of all repository tags.

github_release_catalog(→ dict)

Gets the catalog entry for a given release.

github_file_url(→ str)

Formats a GitHub file URL.

github_archive_url(→ str)

Formats a GitHub archive URL.

github_release_url(→ str)

Formats a GitHub release URL.

github_artifacts_url(→ Union[str, Tuple[str, str], None])

Formats a GitHub artifacts URL.

ocebuild.sources.github.github_api_request(endpoint: str | None = None, url: str | None = None) any[source]#

Gets a GitHub API request.

This method will automatically add the GitHub token from the environment.

Parameters:

endpoint – GitHub API endpoint.

Returns:

API response.

ocebuild.sources.github.github_rate_limit(kind: str = 'core', raise_error: float = False) int[source]#

Gets the GitHub API rate limit.

Parameters:
  • kind – The kind of GitHub API request to query.

  • raise_error – Raise an exception if the rate limit has been exceeded.

Returns:

Remaining API calls allowed.

Raises:

Exception – If the rate limit has been exceeded.

ocebuild.sources.github.get_latest_commit(repository: str, branch: str = 'main')[source]#

Get the latest commit of a branch in a GitHub repository.

ocebuild.sources.github.github_suite_id(repository: str, commit: str, workflow_id: int, status: str | None = 'completed') int | None[source]#

Gets the GitHub check suite ID for a given commit.

Parameters:
  • repository – GitHub repository name.

  • commit – Commit hash.

Returns:

Check suite ID.

ocebuild.sources.github.github_tag_names(repository: str, get_commits=False) List[str] | Tuple[List[str], List[str]][source]#

Returns a list of all repository tags.

Parameters:
  • repository – GitHub repository name.

  • get_commits – If True, additionally returns a list of commit hashes.

Returns:

List of repository tags.

ocebuild.sources.github.github_release_catalog(url: str) dict[source]#

Gets the catalog entry for a given release.

Parameters:

url – GitHub release catalog URL.

Returns:

Release catalog.

ocebuild.sources.github.github_file_url(repository: str, path: str, branch: str = 'main', tag: str | None = None, commit: str | None = None, raw: bool = False) str[source]#

Formats a GitHub file URL.

Parameters:
  • repository – GitHub repository name.

  • path – Relative path to file.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

  • raw – If True, returns the raw URL.

Returns:

URL of the file.

Example

>>> github_file_url('foo/bar', path='file.json')
# -> "https://github.com/foo/bar/blob/main/file.json"
>>> github_file_url('foo/bar', path='file.json', branch='dev')
# -> "https://github.com/foo/bar/blob/dev/file.json"
>>> github_file_url('foo/bar', path='file.json', tag='v1.0.0')
# -> "https://github.com/foo/bar/blob/v1.0.0/file.json"
>>> github_file_url('foo/bar', path='file.json', commit='c0ffee')
# -> "https://github.com/foo/bar/blob/c0ffee/file.json"
>>> github_file_url('foo/bar', path='file.json', raw=True)
# -> "https://raw.githubusercontent.com/foo/bar/main/file.json"
ocebuild.sources.github.github_archive_url(repository: str, branch: str = 'main', tag: str | None = None, commit: str | None = None) str[source]#

Formats a GitHub archive URL.

Parameters:
  • repository – GitHub repository name.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

Returns:

URL of the archive.

Example

>>> github_archive_url('foo/bar')
# -> "https://github.com/foo/bar/archive/refs/heads/main.tar.gz"
>>> github_archive_url('foo/bar', branch='dev')
# -> "https://github.com/foo/bar/archive/refs/heads/dev.tar.gz"
>>> github_archive_url('foo/bar', tag='v1.0.0')
# -> "https://github.com/foo/bar/archive/refs/tags/v1.0.0.tar.gz"
>>> github_archive_url('foo/bar', commit='c0ffee')
# -> "https://github.com/foo/bar/archive/c0ffee.tar.gz"
ocebuild.sources.github.github_release_url(repository: str, tag: str | None = None) str[source]#

Formats a GitHub release URL.

Parameters:
  • repository – GitHub repository name.

  • tag – Tag name.

Returns:

URL of the release.

Example

>>> github_release_url('foo/bar')
# -> "https://github.com/foo/bar/releases/latest/v2.0.0"
>>> github_release_url('foo/bar', tag='v1.0.0')
# -> "https://github.com/foo/bar/releases/tag/v1.0.0"
ocebuild.sources.github.github_artifacts_url(repository: str, branch: str | None = None, workflow: str | None = None, commit: str | None = None, get_commit=False) str | Tuple[str, str] | None[source]#

Formats a GitHub artifacts URL.

Parameters:
  • repository – GitHub repository name.

  • branch – Branch name.

  • tag – Tag name.

  • commit – Commit hash.

  • get_commit – If True, additionally returns the commit hash.

Returns:

URL of the artifacts archive.