### Setup development environment with uv Source: https://github.com/harabat/pyforgejo/blob/main/README.md Commands to download project configuration, create a virtual environment, and install dependencies. ```shell wget https://codeberg.org/harabat/pyforgejo/raw/branch/main/pyproject.toml uv venv uv pip install -e '.[dev]' uv sync --dev uv run ruff format . ``` -------------------------------- ### Install pyforgejo Source: https://github.com/harabat/pyforgejo/blob/main/README.md Install the library using pip. ```shell pip install pyforgejo ``` -------------------------------- ### Initialize Fern Workspace Source: https://github.com/harabat/pyforgejo/blob/main/README.md Install Fern globally and initialize a new workspace using the converted OpenAPI specification. You will be prompted to enter your organization name. ```shell npm install -g fern-api fern init --openapi api_spec/openapi.json # Please enter your organization: pyforgejo ``` -------------------------------- ### List and Get Releases Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieve repository releases using filters or specific identifiers like tags. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List all releases releases = client.repository.repo_list_releases( owner="harabat", repo="pyforgejo", draft=False, pre_release=False, # Exclude pre-releases page=1, limit=20 ) for release in releases: print(f"{release.tag_name}: {release.name}") print(f" Published: {release.published_at}") print(f" Assets: {len(release.assets or [])}") # Get latest release latest = client.repository.repo_get_latest_release( owner="harabat", repo="pyforgejo" ) print(f"Latest: {latest.tag_name}") # Get release by tag release = client.repository.repo_get_release_by_tag( owner="harabat", repo="pyforgejo", tag="v2.0.0" ) ``` -------------------------------- ### Get User Settings Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves and prints the current user's settings, such as theme and language preferences. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Get user settings settings = client.user.get_user_settings() print(f"Theme: {settings.theme}") print(f"Language: {settings.language}") ``` -------------------------------- ### GET /repos/search Source: https://context7.com/harabat/pyforgejo/llms.txt Searches for repositories across the Forgejo instance with filtering and sorting options. ```APIDOC ## GET /repos/search ### Description Searches for repositories across the Forgejo instance with filtering and sorting options. ### Method GET ### Endpoint /repos/search ### Parameters #### Query Parameters - **q** (string) - Optional - Keyword to search for - **include_desc** (boolean) - Optional - Include description in search - **sort** (string) - Optional - Sort criteria (stars, created, updated, size) - **order** (string) - Optional - Sort order (asc, desc) - **page** (integer) - Optional - Page number - **limit** (integer) - Optional - Results per page - **archived** (boolean) - Optional - Filter by archived status - **private** (boolean) - Optional - Filter by private status - **mode** (string) - Optional - Filter by mode (source, fork, mirror, collaborative) ``` -------------------------------- ### GET /repos/{owner}/{repo} Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves detailed information about a specific repository including metadata, permissions, and settings. ```APIDOC ## GET /repos/{owner}/{repo} ### Description Retrieves detailed information about a specific repository including metadata, permissions, and settings. ### Method GET ### Endpoint /repos/{owner}/{repo} ### Parameters #### Path Parameters - **owner** (string) - Required - The owner of the repository - **repo** (string) - Required - The name of the repository ``` -------------------------------- ### GET /repos/{owner}/{repo}/contents Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves file or directory contents from a repository at a specific ref. ```APIDOC ## GET /repos/{owner}/{repo}/contents ### Description Retrieves file or directory contents from a repository at a specific ref (branch, tag, or commit). ### Method GET ### Endpoint /repos/{owner}/{repo}/contents ### Parameters #### Path Parameters - **owner** (string) - Required - The owner of the repository - **repo** (string) - Required - The name of the repository #### Query Parameters - **ref** (string) - Optional - Branch, tag, or commit SHA ``` -------------------------------- ### List and Get Organizations Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves a list of organizations accessible to the current user or details of a specific organization. Supports pagination. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List all organizations orgs = client.organization.org_get_all(page=1, limit=50) for org in orgs: print(f"{org.username}: {org.description}") # Get specific organization org = client.organization.org_get(org="forgejo") print(f"Name: {org.full_name}") print(f"Description: {org.description}") print(f"Location: {org.location}") print(f"Website: {org.website}") # List current user's organizations my_orgs = client.organization.org_list_current_user_orgs(page=1, limit=50) ``` -------------------------------- ### Get Pull Request Details with Pyforgejo Source: https://context7.com/harabat/pyforgejo/llms.txt Fetches comprehensive data for a specific pull request, including associated commits and modified files. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Get PR details pr = client.repository.repo_get_pull_request( owner="harabat", repo="pyforgejo", index=10 # PR number ) print(f"Title: {pr.title}") print(f"State: {pr.state}") print(f"Mergeable: {pr.mergeable}") print(f"Base: {pr.base.ref}") print(f"Head: {pr.head.ref}") # Get commits in PR commits = client.repository.repo_get_pull_request_commits( owner="harabat", repo="pyforgejo", index=10, page=1, limit=50 ) for commit in commits: print(f" {commit.sha[:8]}: {commit.commit.message.split(chr(10))[0]}") # Get changed files files = client.repository.repo_get_pull_request_files( owner="harabat", repo="pyforgejo", index=10 ) for f in files: print(f" {f.filename}: +{f.additions}/-{f.deletions}") ``` -------------------------------- ### Get Current User Information Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves and prints details about the currently authenticated user, including login, email, full name, avatar URL, and creation date. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Get current user user = client.user.get_current() print(f"Username: {user.login}") print(f"Email: {user.email}") print(f"Full Name: {user.full_name}") print(f"Avatar: {user.avatar_url}") print(f"Created: {user.created}") ``` -------------------------------- ### Initialize Pyforgejo Client Source: https://context7.com/harabat/pyforgejo/llms.txt Configure the client using environment variables, direct parameters, or initialize an asynchronous client. ```python from pyforgejo import PyforgejoApi, AsyncPyforgejoApi # Option 1: Using environment variables (create .env file) # BASE_URL=https://codeberg.org/api/v1 # API_KEY=your_api_key client = PyforgejoApi() # Option 2: Direct configuration client = PyforgejoApi( base_url="https://codeberg.org/api/v1", api_key="your_api_key", timeout=120.0, # Custom timeout in seconds follow_redirects=True ) # Option 3: Async client for asynchronous applications async_client = AsyncPyforgejoApi( base_url="https://codeberg.org/api/v1", api_key="your_api_key" ) ``` -------------------------------- ### Initialize Pyforgejo client Source: https://github.com/harabat/pyforgejo/blob/main/README.md Basic instantiation and usage of the PyforgejoApi client to fetch current user information. ```python # uv pip install ipython # uv run ipython from pyforgejo import PyforgejoApi client = PyforgejoApi() user = client.user.get_current() ``` -------------------------------- ### Initialize client and interact with API Source: https://github.com/harabat/pyforgejo/blob/main/README.md Instantiate the PyforgejoApi client to perform operations like fetching repository details and listing issues. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # get a specific repo repo = client.repository.repo_get(owner='harabat', repo='pyforgejo') repo # Repository(allow_fast_forward_only_merge=False, allow_merge_commits=True, allow_rebase=True, ...) repo.dict() # {'allow_fast_forward_only_merge': False, # 'allow_merge_commits': True, # 'allow_rebase': True, # ... # } # list issues for the repo issues = client.issue.list_issues(owner=repo.owner.login, repo=repo.name) [issue.title for issue in issues] # ['Normalize option model names', # 'Calling methods from client', # '`parsed` is None for most methods', # '`openapi-python-client` does not support `text/plain` requests'] ``` -------------------------------- ### Create, Update, and Batch File Operations Source: https://context7.com/harabat/pyforgejo/llms.txt Demonstrates creating, updating, and performing batch operations on files within a repository. ```python from pyforgejo import PyforgejoApi, ChangeFileOperation import base64 client = PyforgejoApi() # Create a new file new_file = client.repository.repo_create_file( owner="myuser", repo="my-repo", filepath="docs/example.md", content=base64.b64encode(b"# Example\n\nThis is an example file.").decode(), message="Add example documentation", branch="main" ) # Update an existing file (requires SHA of current file) updated_file = client.repository.repo_update_file( owner="myuser", repo="my-repo", filepath="docs/example.md", content=base64.b64encode(b"# Updated Example\n\nUpdated content.").decode(), sha="current_file_sha", # Get from repo_get_contents message="Update example documentation", branch="main" ) # Batch file operations response = client.repository.repo_change_files( owner="myuser", repo="my-repo", files=[ ChangeFileOperation( operation="create", path="file1.txt", content=base64.b64encode(b"Content 1").decode() ), ChangeFileOperation( operation="create", path="file2.txt", content=base64.b64encode(b"Content 2").decode() ) ], message="Add multiple files" ) ``` -------------------------------- ### Create New Repository Source: https://context7.com/harabat/pyforgejo/llms.txt Create a repository for a user or within an organization. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create a new repository for a user repo = client.repository.user_create_current_repo( name="my-new-repo", description="A new repository created via API", private=False, auto_init=True, # Initialize with README default_branch="main", gitignores="Python", # Add .gitignore template license="MIT", # Add license file readme="Default" ) print(f"Created: {repo.html_url}") # Create repository in an organization org_repo = client.organization.create_org_repo( org="my-organization", name="org-project", description="Organization project", private=True ) ``` -------------------------------- ### Create a Release Source: https://context7.com/harabat/pyforgejo/llms.txt Create a new repository release with body content and target commit information. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create a release release = client.repository.repo_create_release( owner="myuser", repo="my-repo", tag_name="v1.0.0", name="Version 1.0.0", body="""## What's New ### Features - Feature A - Feature B ### Bug Fixes - Fixed issue #10 - Fixed issue #15 ### Breaking Changes - API endpoint X changed """, target_commitish="main", # Branch or commit draft=False, prerelease=False ) print(f"Created release: {release.html_url}") ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/harabat/pyforgejo/blob/main/README.md Create a .env file in the generated client's directory (sdks/pyforgejo) to specify the BASE_URL and API_KEY for authentication. ```yml BASE_URL=https://codeberg.org/api/v1 API_KEY="token your_api_key" ``` -------------------------------- ### Create Organization Source: https://context7.com/harabat/pyforgejo/llms.txt Creates a new organization with specified details such as username, full name, description, contact email, location, website, and visibility. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create organization org = client.organization.org_create( username="my-organization", full_name="My Organization", description="An awesome organization", email="org@example.com", location="San Francisco, CA", website="https://example.com", visibility="public" # public, limited, or private ) print(f"Created org: {org.username}") ``` -------------------------------- ### Generate the Client Source: https://github.com/harabat/pyforgejo/blob/main/README.md Execute the 'fern generate' command to build the Python client. You may be prompted to log in to GitHub. ```shell fern generate # you'll have to login to GitHub ``` -------------------------------- ### Update Client Initialization Source: https://github.com/harabat/pyforgejo/blob/main/README.md Modify the PyforgejoApi and AsyncPyforgejoApi classes to load BASE_URL and API_KEY from environment variables using dotenv. ```diff # ... from .user.client import AsyncUserClient, UserClient +import os +from dotenv import load_dotenv + +load_dotenv() + +BASE_URL = os.getenv("BASE_URL", "") +API_KEY = os.getenv("API_KEY", "") class PyforgejoApi: # ... base_url : typing.Optional[str] - The base url to use for requests from the client. + The base url to use for requests from the client. Defaults to BASE_URL from .env file. # ... - api_key : str + api_key : typing.Optional[str] + The API key to use for authentication. Defaults to API_KEY from .env file. # ... def __init__( # ... - api_key: str, + api_key: typing.Optional[str] = None, # ... ): + base_url = base_url or BASE_URL + api_key = api_key or API_KEY + + if not base_url: + raise ValueError("base_url must be provided either as an .env variable or as an argument") + if not api_key: + raise ValueError("api_key must be provided either as an .env variable or as an argument") ``` -------------------------------- ### Manage Branches and Tags Source: https://context7.com/harabat/pyforgejo/llms.txt Lists, retrieves, and creates branches and tags in a repository. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List all branches branches = client.repository.repo_list_branches( owner="harabat", repo="pyforgejo", page=1, limit=50 ) for branch in branches: print(f"{branch.name}: {branch.commit.id[:8]}") # Get specific branch branch = client.repository.repo_get_branch( owner="harabat", repo="pyforgejo", branch="main" ) # Create a new branch new_branch = client.repository.repo_create_branch( owner="myuser", repo="my-repo", new_branch_name="feature/new-feature", old_ref_name="main" # Base branch or commit ) # List tags tags = client.repository.repo_list_tags( owner="harabat", repo="pyforgejo" ) for tag in tags: print(f"{tag.name}: {tag.commit.sha[:8]}") ``` -------------------------------- ### Retrieve Repository Details Source: https://context7.com/harabat/pyforgejo/llms.txt Fetch metadata and settings for a specific repository. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Get repository details repo = client.repository.repo_get(owner="harabat", repo="pyforgejo") print(f"Name: {repo.name}") print(f"Description: {repo.description}") print(f"Stars: {repo.stars_count}") print(f"Default Branch: {repo.default_branch}") print(f"Clone URL: {repo.clone_url}") print(f"Private: {repo.private}") # Access as dictionary repo_dict = repo.dict() ``` -------------------------------- ### Download and run tests Source: https://github.com/harabat/pyforgejo/blob/main/README.md Commands to fetch the test suite and execute client tests using pytest. ```shell wget https://codeberg.org/harabat/pyforgejo/archive/main:tests.zip unzip tests.zip rm tests.zip uv run pytest -v tests/test_client.py ``` -------------------------------- ### POST /user/repos Source: https://context7.com/harabat/pyforgejo/llms.txt Creates a new repository in a user's account. ```APIDOC ## POST /user/repos ### Description Creates a new repository in a user's account. ### Method POST ### Endpoint /user/repos ### Parameters #### Request Body - **name** (string) - Required - Repository name - **description** (string) - Optional - Repository description - **private** (boolean) - Optional - Whether the repo is private - **auto_init** (boolean) - Optional - Initialize with README - **default_branch** (string) - Optional - Default branch name - **gitignores** (string) - Optional - .gitignore template - **license** (string) - Optional - License file - **readme** (string) - Optional - README content ``` -------------------------------- ### List Repository Contents Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieve files and directories from a repository at a specific reference. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List root directory contents contents = client.repository.repo_get_contents_list( owner="harabat", repo="pyforgejo", ref="main" # Optional: branch, tag, or commit SHA ) for item in contents: print(f"{item.type}: {item.name}") ``` -------------------------------- ### List User Repositories Source: https://context7.com/harabat/pyforgejo/llms.txt Lists repositories for the current user or another specified user. Supports pagination and filtering for owned or starred repositories. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List current user's repos repos = client.user.current_list_repos( page=1, limit=50 ) for repo in repos: print(f"{repo.full_name}: {repo.description}") # List starred repos starred = client.user.current_list_starred( page=1, limit=50 ) # List repos of another user repos = client.user.user_list_repos( username="someuser", page=1, limit=50 ) ``` -------------------------------- ### Configure environment variables Source: https://github.com/harabat/pyforgejo/blob/main/README.md Define the base URL and API key in a .env file to authenticate and connect to the Forgejo instance. ```yaml BASE_URL=https://codeberg.org/api/v1 API_KEY=your_api_key ``` -------------------------------- ### Create Issue with Pyforgejo Source: https://context7.com/harabat/pyforgejo/llms.txt Initializes a new issue in a repository with optional metadata such as labels, assignees, and milestones. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create a new issue issue = client.issue.create_issue( owner="myuser", repo="my-repo", title="Bug: Application crashes on startup", body="""## Description The application crashes when starting with certain configurations. ## Steps to Reproduce 1. Set config option X to Y 2. Start application 3. Observe crash ## Expected Behavior Application should start normally. """, labels=[1, 2], # Label IDs assignees=["username"], milestone=1 # Milestone ID ) print(f"Created issue #{issue.number}: {issue.html_url}") ``` -------------------------------- ### Search Repositories Source: https://context7.com/harabat/pyforgejo/llms.txt Search for repositories with filtering and sorting options. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Search repositories by keyword results = client.repository.repo_search( q="python", include_desc=True, # Include description in search sort="stars", # Sort by stars, created, updated, size, etc. order="desc", # Ascending or descending page=1, limit=10 ) for repo in results.data: print(f"{repo.full_name}: {repo.stars_count} stars") # Search with filters results = client.repository.repo_search( q="cli", archived=False, # Exclude archived repos private=False, # Only public repos mode="source" # source, fork, mirror, or collaborative ) ``` -------------------------------- ### List system hooks Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves a paginated list of system hooks from the Forgejo instance. ```python hooks = client.admin.list_hooks(page=1, limit=50) ``` -------------------------------- ### Download Forgejo API Spec Source: https://github.com/harabat/pyforgejo/blob/main/README.md Use wget to download the Forgejo Swagger API specification and save it as openapi.json. ```shell mkdir api_spec wget https://converter.swagger.io/api/convert\?url\=https%3A%2F%2Fcode.forgejo.org%2Fswagger.v1.json --output-document=api_spec/openapi.json ``` -------------------------------- ### List Pull Request Reviews Source: https://context7.com/harabat/pyforgejo/llms.txt Lists all reviews for a given pull request. Iterates through the reviews and prints the reviewer's login and review state. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List reviews on a PR reviews = client.repository.repo_list_pull_reviews( owner="harabat", repo="pyforgejo", index=10 ) for review in reviews: print(f"{review.user.login}: {review.state}") if review.body: print(f" {review.body}") ``` -------------------------------- ### Handle API errors and exceptions Source: https://context7.com/harabat/pyforgejo/llms.txt Demonstrates catching specific library exceptions to handle common API failure scenarios like unauthorized access or missing resources. ```python from pyforgejo import PyforgejoApi from pyforgejo.errors import ( NotFoundError, UnauthorizedError, ForbiddenError, ConflictError, BadRequestError ) client = PyforgejoApi() try: repo = client.repository.repo_get(owner="nonexistent", repo="repo") except NotFoundError: print("Repository not found") except UnauthorizedError: print("Invalid API key") except ForbiddenError: print("Access denied - insufficient permissions") except ConflictError: print("Conflict - resource already exists") except BadRequestError as e: print(f"Bad request: {e}") except Exception as e: print(f"Unexpected error: {e}") ``` -------------------------------- ### List Pull Requests with Pyforgejo Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves a list of pull requests from a repository, supporting filters for state, sorting, and pagination. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List open pull requests prs = client.repository.repo_list_pull_requests( owner="harabat", repo="pyforgejo", state="open", # open, closed, all sort="created", # created, updated, priority, etc. page=1, limit=20 ) for pr in prs: print(f"#{pr.number}: {pr.title}") print(f" {pr.head.ref} -> {pr.base.ref}") print(f" Mergeable: {pr.mergeable}") ``` -------------------------------- ### Create Pull Request with Pyforgejo Source: https://context7.com/harabat/pyforgejo/llms.txt Opens a new pull request between two branches, allowing for title, description, and reviewer assignment. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create a pull request pr = client.repository.repo_create_pull_request( owner="myuser", repo="my-repo", title="Add new feature X", body="""## Summary This PR adds feature X as discussed in #42. ## Changes - Added new module for X - Updated documentation - Added tests ## Testing - [x] Unit tests pass - [x] Integration tests pass """, head="feature/new-feature", # Source branch base="main", # Target branch labels=[1, 2], assignees=["reviewer1"], milestone=1 ) print(f"Created PR #{pr.number}: {pr.html_url}") ``` -------------------------------- ### System Administration Source: https://context7.com/harabat/pyforgejo/llms.txt Manage system-level tasks such as cron jobs and email retrieval. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List cron jobs crons = client.admin.cron_list(page=1, limit=50) for cron in crons: print(f"{cron.name}: Next run at {cron.next}") # Run a cron job manually client.admin.cron_run(task="repo_health_check") # Get all emails emails = client.admin.get_all_emails(page=1, limit=100) ``` -------------------------------- ### Manage Users (Admin) Source: https://context7.com/harabat/pyforgejo/llms.txt Administrative functions for searching, creating, editing, and deleting users. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Search users (admin) users = client.admin.admin_search_users( q="john", page=1, limit=20 ) # Create a new user user = client.admin.admin_create_user( username="newuser", email="newuser@example.com", password="securepassword123", must_change_password=True, visibility="public" ) # Edit user client.admin.admin_edit_user( username="newuser", active=True, admin=False, login_name="newuser" ) # Delete user client.admin.admin_delete_user(username="olduser") ``` -------------------------------- ### Create Pull Request Review Source: https://context7.com/harabat/pyforgejo/llms.txt Creates a new review for a pull request, optionally including a body and an event like 'APPROVE'. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Create a review review = client.repository.repo_create_pull_review( owner="myuser", repo="my-repo", index=10, body="LGTM! Nice work on the refactoring.", event="APPROVE" # APPROVE, REQUEST_CHANGES, COMMENT ) ``` -------------------------------- ### Configure Security Definitions Source: https://github.com/harabat/pyforgejo/blob/main/README.md Modify the API specification to include 'AuthorizationHeaderToken' for API key authentication. ```json "securityDefinitions": { "AuthorizationHeaderToken": { "description": "API tokens must be prepended with \"token\" followed by a space.", "type": "apiKey", "name": "Authorization", "in": "header" } }, "security": [ { "AuthorizationHeaderToken": [] } ] ``` -------------------------------- ### Retrieve and Decode File Content Source: https://context7.com/harabat/pyforgejo/llms.txt Fetches a file from a repository and decodes its base64-encoded content. ```python file_content = client.repository.repo_get_contents( owner="harabat", repo="pyforgejo", filepath="README.md", ref="main" ) # For file type, content is base64 encoded import base64 if hasattr(file_content, 'content'): decoded = base64.b64decode(file_content.content).decode('utf-8') print(decoded) ``` -------------------------------- ### Search Issues Globally Source: https://context7.com/harabat/pyforgejo/llms.txt Searches for issues across repositories with advanced filtering and date-based queries. ```python from pyforgejo import PyforgejoApi from datetime import datetime, timedelta client = PyforgejoApi() # Search issues globally issues = client.issue.search_issues( q="bug fix", state="open", labels="bug", type="issues", # issues or pulls assigned=True, # Only assigned to current user page=1, limit=20 ) # Search with date filters since = datetime.now() - timedelta(days=30) issues = client.issue.search_issues( q="", state="all", since=since, # Issues updated since this date owner="harabat", sort="updated" ) ``` -------------------------------- ### List Repository Issues Source: https://context7.com/harabat/pyforgejo/llms.txt Retrieves issues from a repository with filtering options like state, labels, and milestones. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List all open issues issues = client.issue.list_issues( owner="harabat", repo="pyforgejo", state="open", # open, closed, or all page=1, limit=20 ) for issue in issues: print(f"#{issue.number}: {issue.title}") print(f" State: {issue.state}") print(f" Labels: {[l.name for l in issue.labels or []]}") # Filter by labels and assignee issues = client.issue.list_issues( owner="harabat", repo="pyforgejo", state="open", labels="bug,help wanted", # Comma-separated labels assigned_by="username", sort="created", # created, updated, comments milestones="v1.0" ) ``` -------------------------------- ### Configure Fern Generators Source: https://github.com/harabat/pyforgejo/blob/main/README.md Update the generators configuration to remove other SDKs and set the output path for the Python SDK to 'sdks/pyforgejo'. ```diff # yaml-language-server: $schema=https://schema.buildwithfern.dev/generators-yml.json api: specs: - openapi: openapi/openapi.json default-group: local groups: local: generators: - - name: fernapi/fern-typescript-sdk - # ... - name: fernapi/fern-python-sdk version: x.x.x output: location: local-file-system - path: ../sdks/python + path: ../sdks/pyforgejo ``` -------------------------------- ### Release Operations API Source: https://context7.com/harabat/pyforgejo/llms.txt APIs for retrieving and creating releases for a repository. ```APIDOC ## Release Operations ### List and Get Releases #### Description Retrieves releases from a repository with filtering options. #### List All Releases ##### Method GET ##### Endpoint `/repos/{owner}/{repo}/releases` ##### Query Parameters - **owner** (string) - Required - The owner of the repository. - **repo** (string) - Required - The name of the repository. - **draft** (boolean) - Optional - If true, show draft releases. - **pre_release** (boolean) - Optional - If true, show pre-releases. - **page** (integer) - Optional - Page number for pagination. - **limit** (integer) - Optional - Number of items per page. #### Get Latest Release ##### Method GET ##### Endpoint `/repos/{owner}/{repo}/releases/latest` ##### Parameters ###### Path Parameters - **owner** (string) - Required - The owner of the repository. - **repo** (string) - Required - The name of the repository. #### Get Release by Tag ##### Method GET ##### Endpoint `/repos/{owner}/{repo}/releases/tags/{tag}` ##### Parameters ###### Path Parameters - **owner** (string) - Required - The owner of the repository. - **repo** (string) - Required - The name of the repository. - **tag** (string) - Required - The tag of the release. ### Create Release #### Description Creates a new release with optional assets and release notes. #### Method POST #### Endpoint `/repos/{owner}/{repo}/releases` #### Parameters ##### Path Parameters - **owner** (string) - Required - The owner of the repository. - **repo** (string) - Required - The name of the repository. ##### Request Body - **tag_name** (string) - Required - The tag name for the release. - **name** (string) - Optional - The name of the release. - **body** (string) - Optional - The release notes in markdown format. - **target_commitish** (string) - Optional - The branch or commit to base this release on. - **draft** (boolean) - Optional - Whether to create a draft release. - **prerelease** (boolean) - Optional - Whether to create a pre-release. ``` -------------------------------- ### Edit Repository Settings Source: https://context7.com/harabat/pyforgejo/llms.txt Update repository configuration, including features and merge options. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Update repository settings updated_repo = client.repository.repo_edit( owner="myuser", repo="my-repo", description="Updated description", website="https://example.com", has_issues=True, has_wiki=True, has_pull_requests=True, allow_merge_commits=True, allow_squash_merge=True, allow_rebase=True, default_delete_branch_after_merge=True, archived=False ) ``` -------------------------------- ### Manage User Following Source: https://context7.com/harabat/pyforgejo/llms.txt Manages user following relationships, including listing followers, following, checking status, following, and unfollowing users. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List followers followers = client.user.current_list_followers(page=1, limit=50) for user in followers: print(f"Follower: {user.login}") # List following following = client.user.current_list_following(page=1, limit=50) # Check if following a user try: client.user.current_check_following(username="someuser") print("You are following this user") except Exception: print("You are not following this user") # Follow a user client.user.current_put_follow(username="someuser") # Unfollow a user client.user.current_delete_follow(username="someuser") ``` -------------------------------- ### Add Python SDK Generator Source: https://github.com/harabat/pyforgejo/blob/main/README.md Add the official Fern Python SDK generator to your Fern workspace configuration. ```shell fern add fernapi/fern-python-sdk ``` -------------------------------- ### Manage Organization Members and Teams Source: https://context7.com/harabat/pyforgejo/llms.txt Operations for listing organization members, managing teams, and adding members to specific teams. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # List organization members members = client.organization.org_list_members( org="my-organization", page=1, limit=50 ) for member in members: print(f"Member: {member.login}") # List teams teams = client.organization.org_list_teams( org="my-organization", page=1, limit=50 ) for team in teams: print(f"Team: {team.name} (Permission: {team.permission})") # Create a team team = client.organization.org_create_team( org="my-organization", name="developers", description="Development team", permission="write", # read, write, admin includes_all_repositories=False ) # Add member to team client.organization.org_add_team_member( id=team.id, username="newmember" ) ``` -------------------------------- ### Admin Operations API Source: https://context7.com/harabat/pyforgejo/llms.txt Administrative functions for managing users and system settings. ```APIDOC ## Admin Operations ### User Management (Admin) #### Description Administrative functions for managing users (requires admin privileges). #### Search Users ##### Method GET ##### Endpoint `/admin/users` ##### Query Parameters - **q** (string) - Required - The search query. - **page** (integer) - Optional - Page number for pagination. - **limit** (integer) - Optional - Number of items per page. #### Create User ##### Method POST ##### Endpoint `/admin/users` ##### Request Body - **username** (string) - Required - The username for the new user. - **email** (string) - Required - The email address for the new user. - **password** (string) - Required - The password for the new user. - **must_change_password** (boolean) - Optional - Whether the user must change their password on first login. - **visibility** (string) - Optional - The visibility of the user's profile (e.g., `public`). #### Edit User ##### Method PATCH ##### Endpoint `/admin/users/{username}` ##### Parameters ###### Path Parameters - **username** (string) - Required - The username of the user to edit. ##### Request Body - **active** (boolean) - Optional - Whether the user account is active. - **admin** (boolean) - Optional - Whether the user is an administrator. - **login_name** (string) - Optional - The login name for the user. #### Delete User ##### Method DELETE ##### Endpoint `/admin/users/{username}` ##### Parameters ###### Path Parameters - **username** (string) - Required - The username of the user to delete. ### System Administration #### Description Administrative functions for system management. #### List Cron Jobs ##### Method GET ##### Endpoint `/admin/cron` ##### Query Parameters - **page** (integer) - Optional - Page number for pagination. - **limit** (integer) - Optional - Number of items per page. #### Run Cron Job ##### Method POST ##### Endpoint `/admin/cron/{task}` ##### Parameters ###### Path Parameters - **task** (string) - Required - The name of the cron job task to run. #### Get All Emails ##### Method GET ##### Endpoint `/admin/emails` ##### Query Parameters - **page** (integer) - Optional - Page number for pagination. - **limit** (integer) - Optional - Number of items per page. ``` -------------------------------- ### Merge Pull Request with Pyforgejo Source: https://context7.com/harabat/pyforgejo/llms.txt Initiates a merge operation for a pull request. ```python from pyforgejo import PyforgejoApi client = PyforgejoApi() # Check if PR is merged ``` -------------------------------- ### Update API key header in client_wrapper.py Source: https://github.com/harabat/pyforgejo/blob/main/README.md Modifies the authorization header to ensure the token prefix is correctly applied. ```diff def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { "X-Fern-Language": "Python", } - headers["Authorization"] = self.api_key + headers["Authorization"] = f"token {self.api_key.replace('token ', '')}" return headers ``` -------------------------------- ### Mark Notifications as Read Source: https://context7.com/harabat/pyforgejo/llms.txt Update notification statuses individually, in bulk, or by repository. ```python from pyforgejo import PyforgejoApi from datetime import datetime client = PyforgejoApi() # Mark specific notification as read client.notification.notify_read_thread( id=12345, to_status="read" ) # Mark all notifications as read client.notification.notify_read_list( last_read_at=datetime.now(), all_=True, to_status="read" ) # Mark repo notifications as read client.notification.notify_read_repo_list( owner="harabat", repo="pyforgejo", all_=True ) ``` -------------------------------- ### PATCH /repos/{owner}/{repo} Source: https://context7.com/harabat/pyforgejo/llms.txt Updates repository settings including merge options, features, and metadata. ```APIDOC ## PATCH /repos/{owner}/{repo} ### Description Updates repository settings including merge options, features, and metadata. ### Method PATCH ### Endpoint /repos/{owner}/{repo} ### Parameters #### Path Parameters - **owner** (string) - Required - The owner of the repository - **repo** (string) - Required - The name of the repository #### Request Body - **description** (string) - Optional - Updated description - **website** (string) - Optional - Website URL - **has_issues** (boolean) - Optional - Enable issues - **has_wiki** (boolean) - Optional - Enable wiki - **has_pull_requests** (boolean) - Optional - Enable pull requests - **allow_merge_commits** (boolean) - Optional - Allow merge commits - **allow_squash_merge** (boolean) - Optional - Allow squash merge - **allow_rebase** (boolean) - Optional - Allow rebase - **default_delete_branch_after_merge** (boolean) - Optional - Delete branch after merge - **archived** (boolean) - Optional - Archive status ```