aedev.project_manager.codeberg

helpers to access codeberg.org via its V1 API

Codeberg is based on Forgejo (a fork of Gitea) and its API (documented at `https://codeberg.org/api/swagger`__).

this module is a first start, currently only to allow an initial push of a repo to codeberg.org, used as 2nd mirror. (similar to GitHub, also not allowing initial pushes of a new repository). the plan is to move all my repositories from GitLab to Codeberg (and then using GitLab as mirror).

created this module because the Python libraries pygitea (https://github.com/jo-nas/pygitea and https://github.com/h44z/pygitea) were in 2026 no longer maintained (since ~2019).

another api endpoint example to determine the repo url:

url = f’https://codeberg.org/api/v1/repos/{user_or_org_name}/{repo_name}’ response = requests.get(url, headers={“Authorization”: f”token {token}”, “Accept”: “application/json”}, timeout=10) if response.status_code == 200:

return response.json()[‘clone_url’]

Functions

ensure_repo(user_or_group_name, repo_name, token)

check if the repository exists for the specified user or organisation/group and create it if it doesn't.

set_main_branch(user_or_group_name, ...[, ...])

wait until the initial post/upload got finished to set the main/default branch.

class _RequestsKwargs[source]

Bases: TypedDict

type of the used arguments of the requests package methods (get/patch/post/..).

headers: Mapping[str, str]
timeout: float | tuple[float, float]
__optional_keys__ = frozenset({'headers', 'timeout'})
__orig_bases__ = (<function TypedDict>,)
__required_keys__ = frozenset({})
__total__ = False
_headers(token)[source]

compile the standard header fields to be sent to codeberg (with authentication token).

Parameters:

token (str) – private access token of the pushing user.

Return type:

Mapping[str, str]

Returns:

header fields mapping.

ensure_repo(user_or_group_name, repo_name, token, desc='', private=False)[source]

check if the repository exists for the specified user or organisation/group and create it if it doesn’t.

Parameters:
  • user_or_group_name (str) – name of the codeberg user or organisation/repo-group.

  • repo_name (str) – name of the repository/project.

  • token (str) – personell access token of the pushing user.

  • desc (str) – optional repo description.

  • private (bool) – pass True to make the repository private.

Return type:

str

Returns:

error message if repo is not accessible or could not be created, else empty string.

set_main_branch(user_or_group_name, repo_name, token, main_branch, timeout=69.0)[source]

wait until the initial post/upload got finished to set the main/default branch.

Parameters:
  • user_or_group_name (str) – name of the codeberg user or organisation/repo-group.

  • repo_name (str) – name of the repository/project.

  • token (str) – personell access token of the pushing user.

  • main_branch (str) – name of the main branch.

  • timeout (float) – optional timeout (default is 69 seconds).

Return type:

str

Returns:

error message if default branch could not set, else an empty string.