gitcode_api.resources.misc

Classes for resource groups: releases, tags, and webhooks.

class AsyncReleasesResource(client: AsyncAPIClient)

Bases: AsyncResource, AbstractReleasesResource

Asynchronous release endpoints.

Mirrors ReleasesResource; see that class for parameters (Release API in docs/rest_api).

Bind the resource to an asynchronous API client.

async create(*, tag: str, name: str, body: str, owner: str | None = None, repo: str | None = None, target_commitish: str | None = None, release_status: str | None = None) Release

Create a repository release.

Parameters:
  • tag – Tag name for the release.

  • name – Release title.

  • body – Release description.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • target_commitish – Branch name or commit SHA for creating a missing tag.

  • release_status – Release status, such as pre or latest.

Returns:

Created release payload.

async update(*, tag: str, name: str, body: str, owner: str | None = None, repo: str | None = None, release_status: str | None = None) Release

Update a repository release.

Parameters:
  • tag – Tag name in the release URL path.

  • name – Release name.

  • body – Release description.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • release_status – Release status, such as pre or latest.

Returns:

Updated release payload.

async get_upload_url(*, tag: str, file_name: str, owner: str | None = None, repo: str | None = None) ReleaseUploadURL

Get a pre-signed URL for uploading a release attachment.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name to upload.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Upload URL and required headers.

async upload(*, tag: str, file_name: str, content: bytes | str, owner: str | None = None, repo: str | None = None, upload_timeout: float | None = 300.0) None

Upload a release attachment through the pre-signed upload URL.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name to upload.

  • content – Attachment bytes, or a local file path to read as bytes.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • upload_timeout – Timeout for upload operation. Default to 300 (5 minutes).

async get_by_tag(*, tag: str, owner: str | None = None, repo: str | None = None) Release

Get a repository release by tag name.

Parameters:
  • tag – Git tag the release is attached to.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Release metadata for that tag.

async list(*, owner: str | None = None, repo: str | None = None, direction: str | None = None, page: int | None = None, per_page: int | None = None) List[Release]

List releases for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • direction – Sort direction, for example asc or desc.

  • page – Page number.

  • per_page – Page size, up to 100.

Returns:

Releases ordered as returned by the API.

async get_latest(*, owner: str | None = None, repo: str | None = None, type: str | None = None) Release

Get the latest repository release.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • type – Selection type, either updated or latest.

Returns:

Latest release metadata.

async get(*, tag: str, owner: str | None = None, repo: str | None = None, temp_download_url: bool | str | None = None) Release

Get a repository release by tag path.

Parameters:
  • tag – Tag name in the release URL path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • temp_download_url – Whether to return temporary source package and attachment URLs.

Returns:

Release metadata.

async download_attachment(*, tag: str, file_name: str, owner: str | None = None, repo: str | None = None) bytes

Download a release attachment as bytes.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Attachment bytes.

class AsyncTagsResource(client: AsyncAPIClient)

Bases: AsyncResource, AbstractTagsResource

Asynchronous tag endpoints.

Mirrors TagsResource; see that class and docs/rest_api/repos/tag for semantics.

Bind the resource to an asynchronous API client.

async list(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[Tag]

List tags for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Tags.

async create(*, refs: str, tag_name: str, owner: str | None = None, repo: str | None = None, tag_message: str | None = None) Tag

Create a tag for a repository.

Parameters:
  • refs – Object SHA or ref the tag should point to.

  • tag_name – Name of the new tag.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • tag_message – Optional annotated tag message.

Returns:

Created tag.

async list_protected(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[ProtectedTag]

List protected tags for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Protected tag rules.

async delete_protected(*, tag_name: str, owner: str | None = None, repo: str | None = None) None

Delete a protected tag rule.

Parameters:
  • tag_name – Protected tag name in the URL path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

async get_protected(*, tag_name: str, owner: str | None = None, repo: str | None = None) ProtectedTag

Get details for a protected tag rule.

Parameters:
  • tag_name – Tag name in the path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Protected tag configuration.

async create_protected(*, name: str, owner: str | None = None, repo: str | None = None, create_access_level: int | None = None) ProtectedTag

Create a protected tag rule.

Parameters:
  • name – Tag name or pattern to protect.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • create_access_level – Minimum access level required to create matching tags (API-specific integer).

Returns:

Created rule.

async update_protected(*, name: str, create_access_level: int, owner: str | None = None, repo: str | None = None) ProtectedTag

Update a protected tag rule.

class AsyncWebhooksResource(client: AsyncAPIClient)

Bases: AsyncResource, AbstractWebhooksResource

Asynchronous webhook endpoints.

Mirrors WebhooksResource; see that class and docs/rest_api/repos/webhooks.

Bind the resource to an asynchronous API client.

async list(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[Webhook]

List webhooks for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Hook configurations.

async create(*, url: str, owner: str | None = None, repo: str | None = None, **payload) Webhook

Create a repository webhook.

Parameters:
  • url – Payload URL GitCode should POST events to.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • payload – Additional fields from the Webhooks API (events list, secret, content type, etc.).

Returns:

Created webhook.

async get(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) Webhook

Get a repository webhook by identifier.

Parameters:
  • hook_id – Webhook id from the API.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Webhook configuration.

async update(*, hook_id: int | str, url: str, owner: str | None = None, repo: str | None = None, **payload) Webhook

Update a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • url – New payload URL (merged into the JSON body).

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • payload – Other mutable webhook fields accepted by the API.

Returns:

Updated webhook.

async delete(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) None

Delete a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

async test(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) None

Send a test delivery for a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

class ReleasesResource(client: SyncAPIClient)

Bases: SyncResource, AbstractReleasesResource

Synchronous release endpoints.

Bind the resource to a synchronous API client.

create(*, tag: str, name: str, body: str, owner: str | None = None, repo: str | None = None, target_commitish: str | None = None, release_status: str | None = None) Release

Create a repository release.

Parameters:
  • tag – Tag name for the release.

  • name – Release title.

  • body – Release description.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • target_commitish – Branch name or commit SHA for creating a missing tag.

  • release_status – Release status, such as pre or latest.

Returns:

Created release payload.

update(*, tag: str, name: str, body: str, owner: str | None = None, repo: str | None = None, release_status: str | None = None) Release

Update a repository release.

Parameters:
  • tag – Tag name in the release URL path.

  • name – Release name.

  • body – Release description.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • release_status – Release status, such as pre or latest.

Returns:

Updated release payload.

get_upload_url(*, tag: str, file_name: str, owner: str | None = None, repo: str | None = None) ReleaseUploadURL

Get a pre-signed URL for uploading a release attachment.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name to upload.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Upload URL and required headers.

upload(*, tag: str, file_name: str, content: bytes | str, owner: str | None = None, repo: str | None = None, upload_timeout: float | None = 300.0) None

Upload a release attachment through the pre-signed upload URL.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name to upload.

  • content – Attachment bytes, or a local file path to read as bytes.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • upload_timeout – Timeout for upload operation. Default to 300 (5 minutes).

get_by_tag(*, tag: str, owner: str | None = None, repo: str | None = None) Release

Get a repository release by tag name.

Parameters:
  • tag – Git tag the release is attached to.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Release metadata for that tag.

list(*, owner: str | None = None, repo: str | None = None, direction: str | None = None, page: int | None = None, per_page: int | None = None) List[Release]

List releases for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • direction – Sort direction, for example asc or desc.

  • page – Page number.

  • per_page – Page size, up to 100.

Returns:

Releases ordered as returned by the API.

get_latest(*, owner: str | None = None, repo: str | None = None, type: str | None = None) Release

Get the latest repository release.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • type – Selection type, either updated or latest.

Returns:

Latest release metadata.

get(*, tag: str, owner: str | None = None, repo: str | None = None, temp_download_url: bool | str | None = None) Release

Get a repository release by tag path.

Parameters:
  • tag – Tag name in the release URL path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • temp_download_url – Whether to return temporary source package and attachment URLs.

Returns:

Release metadata.

download_attachment(*, tag: str, file_name: str, owner: str | None = None, repo: str | None = None) bytes

Download a release attachment as bytes.

Parameters:
  • tag – Tag name in the release URL path.

  • file_name – Attachment file name.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Attachment bytes.

class TagsResource(client: SyncAPIClient)

Bases: SyncResource, AbstractTagsResource

Synchronous tag endpoints.

Bind the resource to a synchronous API client.

list(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[Tag]

List tags for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Tags.

create(*, refs: str, tag_name: str, owner: str | None = None, repo: str | None = None, tag_message: str | None = None) Tag

Create a tag for a repository.

Parameters:
  • refs – Object SHA or ref the tag should point to.

  • tag_name – Name of the new tag.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • tag_message – Optional annotated tag message.

Returns:

Created tag.

list_protected(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[ProtectedTag]

List protected tags for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Protected tag rules.

delete_protected(*, tag_name: str, owner: str | None = None, repo: str | None = None) None

Delete a protected tag rule.

Parameters:
  • tag_name – Protected tag name in the URL path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

get_protected(*, tag_name: str, owner: str | None = None, repo: str | None = None) ProtectedTag

Get details for a protected tag rule.

Parameters:
  • tag_name – Tag name in the path.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Protected tag configuration.

create_protected(*, name: str, owner: str | None = None, repo: str | None = None, create_access_level: int | None = None) ProtectedTag

Create a protected tag rule.

Parameters:
  • name – Tag name or pattern to protect.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • create_access_level – Minimum access level required to create matching tags (API-specific integer).

Returns:

Created rule.

update_protected(*, name: str, create_access_level: int, owner: str | None = None, repo: str | None = None) ProtectedTag

Update a protected tag rule.

class WebhooksResource(client: SyncAPIClient)

Bases: SyncResource, AbstractWebhooksResource

Synchronous webhook endpoints.

Bind the resource to a synchronous API client.

list(*, owner: str | None = None, repo: str | None = None, page: int | None = None, per_page: int | None = None) List[Webhook]

List webhooks for a repository.

Parameters:
  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • page – Page number.

  • per_page – Page size.

Returns:

Hook configurations.

create(*, url: str, owner: str | None = None, repo: str | None = None, **payload) Webhook

Create a repository webhook.

Parameters:
  • url – Payload URL GitCode should POST events to.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • payload – Additional fields from the Webhooks API (events list, secret, content type, etc.).

Returns:

Created webhook.

get(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) Webhook

Get a repository webhook by identifier.

Parameters:
  • hook_id – Webhook id from the API.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

Returns:

Webhook configuration.

update(*, hook_id: int | str, url: str, owner: str | None = None, repo: str | None = None, **payload) Webhook

Update a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • url – New payload URL (merged into the JSON body).

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

  • payload – Other mutable webhook fields accepted by the API.

Returns:

Updated webhook.

delete(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) None

Delete a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.

test(*, hook_id: int | str, owner: str | None = None, repo: str | None = None) None

Send a test delivery for a repository webhook.

Parameters:
  • hook_id – Webhook id.

  • owner – Repository owner path. Uses the client default when omitted.

  • repo – Repository path. Uses the client default when omitted.