### Install OGR using Pip Source: https://github.com/packit/ogr/blob/main/README.md Instructions for installing the OGR library using pip, the Python package installer. This method is suitable for most Python environments. ```bash $ pip3 install --user ogr ``` ```bash $ pip3 install --user git+https://github.com/packit/ogr.git ``` -------------------------------- ### Install OGR on Fedora Source: https://github.com/packit/ogr/blob/main/README.md Instructions for installing the OGR library on Fedora systems using the DNF package manager. It covers installation from the default Fedora repositories and from a Copr repository. ```bash $ dnf install python3-ogr ``` ```bash $ dnf copr enable packit/packit-releases $ dnf install python3-ogr ``` -------------------------------- ### Install OGR from Development Branch on Fedora Source: https://github.com/packit/ogr/blob/main/README.md Instructions for installing the latest development version of OGR on Fedora from a Copr repository. This is for users who want to test the most recent features or contribute to development. ```bash $ dnf copr enable packit/packit-dev $ dnf install python3-ogr ``` -------------------------------- ### Initialize PagureService and Get Project Source: https://github.com/packit/ogr/blob/main/examples/list_pr_patches.ipynb Initializes the PagureService with a token and instance URL, then retrieves a specific project. Requires the 'ogr' library and a valid Pagure token. ```python from ogr import PagureService TOKEN = "" service = PagureService(token=TOKEN, instance_url="https://pagure.io") project = service.get_project(repo="toddlers", namespace="fedora-infra") ``` -------------------------------- ### Initialize GitlabService and Get Project Source: https://github.com/packit/ogr/blob/main/examples/releases.ipynb This snippet shows how to initialize the GitlabService with a token and instance URL, and then retrieve a specific project from Gitlab. It requires the 'ogr' library and a valid Gitlab token. ```python from ogr import GitlabService TOKEN = "" service = GitlabService(token=TOKEN, instance_url="https://gitlab.com") project = service.get_project(repo="isleward", namespace="Isleward") ``` -------------------------------- ### Initialize Ogr Service and Get Project Source: https://github.com/packit/ogr/blob/main/examples/list_prs_since_release.ipynb Initializes the GithubService with a token and retrieves a specific project from the repository. This is the first step in interacting with the Ogr library for Git operations. ```python from ogr import GithubService TOKEN = "" service = GithubService(token=TOKEN) project = service.get_project(namespace="packit-service", repo="ogr") ``` -------------------------------- ### Getting Ogr Version Source: https://github.com/packit/ogr/blob/main/CONTRIBUTING.md Commands to retrieve the installed version of the 'ogr' Python package. ```shell rpm -q python3-ogr pip3 freeze | grep ogr ``` -------------------------------- ### Get a Project Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Retrieves a specific project (repository) from GitHub using its name and namespace. ```python # let's get the project project = service.get_project(repo="issues-with-ogr", namespace=service.user.get_username()) ``` -------------------------------- ### Get All Releases for a Project Source: https://github.com/packit/ogr/blob/main/examples/releases.ipynb This snippet demonstrates how to fetch all releases associated with a given project object obtained from the GitlabService. This is a prerequisite for further processing or filtering of releases. ```python all_releases = project.get_releases() ``` -------------------------------- ### Run Tests in Container (Podman) Source: https://github.com/packit/ogr/blob/main/plans/README.md Runs tests within a containerized environment using Podman. This requires installing the `tmt-provision-container` package and ensures tests are executed in an isolated and reproducible environment. ```bash $ sudo dnf install tmt-provision-container $ tmt -v run -a provision -h container ``` -------------------------------- ### Get All Pull Requests Source: https://github.com/packit/ogr/blob/main/examples/list_prs_since_release.ipynb Fetches a list of all pull requests for a given project, regardless of their status. This provides the dataset to be filtered. ```python from ogr.abstract import PRStatus prs = project.get_pr_list(status=PRStatus.all) ``` -------------------------------- ### Get GitHub Releases using OGR Source: https://github.com/packit/ogr/blob/main/README.md This snippet demonstrates how to fetch all releases for a specific GitHub repository using the Ogr library. It requires a GitHub token for authentication and utilizes the GithubService to interact with the GitHub API. ```python from ogr.services.github import GithubService service = GithubService(token="your_token") ogr_project = service.get_project( repo="ogr", namespace="packit-service" ) ogr_releases = ogr_project.get_releases() for release in ogr_releases: print(release.tag_name) ``` -------------------------------- ### Release Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Release methods and properties across GitHub, GitLab, Pagure, and Forgejo. Includes support for 'edit_release' and 'body' (get only). ```APIDOC Release: edit_release: [GitHub, Forgejo] body: get: [GitHub, GitLab, Forgejo] notes: Pagure (returns empty string) ``` -------------------------------- ### Get a Specific Release Source: https://github.com/packit/ogr/blob/main/examples/list_prs_since_release.ipynb Retrieves a specific release object from a project using its tag name. This is used to establish a reference point for filtering pull requests. ```python big_release = project.get_release(tag_name="0.12.0") print(f"Bigger release from {big_release.created_at}.") ``` -------------------------------- ### Get Comments for an Issue Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Retrieves all comments associated with an issue and prints them. ```python for comment in new_issue.get_comments(): print(comment) ``` -------------------------------- ### Filter Pull Requests Since Release Source: https://github.com/packit/ogr/blob/main/examples/list_prs_since_release.ipynb Filters the list of all pull requests to include only those created after a specified release's creation date. It then iterates through the filtered list and prints the ID and title of each pull request, indicating if it was not merged. ```python prs_since_release = filter(lambda pr: pr.created > big_release.created_at, prs) for pr in prs_since_release: print(f"#{pr.id}: {pr.title}{' (not merged)' if pr.status == PRStatus.closed else ''}") ``` -------------------------------- ### Initialize GithubService Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Demonstrates how to initialize the GithubService with a personal access token. ```python from ogr import GithubService TOKEN = "" service = GithubService(token=TOKEN) ``` -------------------------------- ### Create a New Project Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Shows how to create a new repository on GitHub using the GithubService. ```python service.project_create(repo="issues-with-ogr") ``` -------------------------------- ### Initialize GithubService Source: https://github.com/packit/ogr/blob/main/examples/syncing_labels.ipynb Initializes the GithubService with a GitHub token. This is the first step to interact with GitHub repositories using OGR. ```python import os from ogr import GithubService service = GithubService(token=os.getenv("GITHUB_TOKEN")) ``` -------------------------------- ### Building and Running Tests in Container Source: https://github.com/packit/ogr/blob/main/CONTRIBUTING.md Makefile commands to build a test image and run tests within a containerized environment. ```shell make build-test-image make check-in-container ``` -------------------------------- ### Initialize Ogr GithubService Source: https://github.com/packit/ogr/blob/main/examples/user_owned_repositories.ipynb This snippet shows how to import and initialize the GithubService class from the Ogr library, using a previously acquired API token. The service object is essential for interacting with GitHub. ```python from ogr import GithubService service = GithubService(token=TOKEN) ``` -------------------------------- ### API Documentation Links Source: https://github.com/packit/ogr/blob/main/CONTRIBUTING.md Links to the official API documentation for GitHub, GitLab, and Pagure services, which are integrated with the Ogr project. ```APIDOC GitHub (PyGithub): - PyGithub documentation: https://pygithub.readthedocs.io/ - Official GitHub API docs: https://developer.github.com/v3/ GitLab (Python-Gitlab): - Python-Gitlab documentation: https://python-gitlab.readthedocs.io/ - Official GitLab API docs: https://docs.gitlab.com/ee/api/ Pagure (requests): - src.fedoraproject.org API: https://src.fedoraproject.org/api/0/ - pagure.io API: https://pagure.io/api/0/ - git.stg.centos.org API: https://git.stg.centos.org/api/0/ ``` -------------------------------- ### Makefile Targets for Testing and Packaging Source: https://github.com/packit/ogr/blob/main/CONTRIBUTING.md Common Makefile targets for running tests locally, checking packaging, and managing containerized tests. ```shell make build-test-image make shell make check-in-container make check-pypi-packaging make check ``` -------------------------------- ### Project Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Project methods and properties across GitHub, GitLab, Pagure, and Forgejo. Covers a wide range of operations including token changes, release retrieval, commit retrieval, privacy checks, user/group management, and file diffs. ```APIDOC Project: change_token: [GitLab, Pagure] get_release: [GitHub, GitLab] get_commits: [GitHub, GitLab, Forgejo] get_latest_release: [GitHub, GitLab] is_private: supported: [GitHub, GitLab, Forgejo] notes: Pagure (may not be accurate) remove_user: [Pagure, Forgejo] add_group: [Pagure] remove_group: [Pagure] which_groups_can_merge_pr: [Pagure] get_pr_files_diff: [Pagure] get_users_with_given_access: [Pagure, Forgejo] ``` -------------------------------- ### PRComment Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of PRComment methods and properties across GitHub, GitLab, Pagure, and Forgejo. Includes support for 'body' (get/set), 'add_reaction', 'get_reactions', and 'closed_by'. ```APIDOC PRComment: body: get: [GitHub, GitLab, Pagure] set: [GitHub, GitLab] add_reaction: [GitHub, GitLab] get_reactions: [GitHub, GitLab] closed_by: [Pagure] ``` -------------------------------- ### Fetch Labels from Source Project Source: https://github.com/packit/ogr/blob/main/examples/syncing_labels.ipynb Fetches all labels from a specified source GitHub project. It requires the service object and the namespace and repository name of the source project. ```python project = service.get_project(namespace="packit", repo="packit") labels = project.get_labels() labels ``` -------------------------------- ### Run Tests Locally Source: https://github.com/packit/ogr/blob/main/plans/README.md Executes tests using the tmt framework on the local machine. This is a straightforward way to run tests without any external dependencies beyond the tmt tool itself. ```bash $ tmt -v run -a provision -h local ``` -------------------------------- ### User Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of User methods and properties across GitHub, GitLab, Pagure, and Forgejo. Includes support for retrieving projects, forks, and user emails. ```APIDOC User: get_projects: [GitHub, Pagure, Forgejo] get_forks: [GitHub, Pagure, Forgejo] get_email: [GitHub, GitLab, Forgejo] ``` -------------------------------- ### Reaction Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Reaction methods across GitHub, GitLab, Pagure, and Forgejo. Specifically covers the 'delete' method. ```APIDOC Reaction: delete: [GitHub, GitLab] ``` -------------------------------- ### Service Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Service methods across GitHub, GitLab, Pagure, and Forgejo. Specifically covers the 'get_group' method. ```APIDOC Service: get_group: [Pagure] ``` -------------------------------- ### Issue Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Issue methods and properties across GitHub, GitLab, Pagure, and Forgejo. Specifically covers the 'add_label' method. ```APIDOC Issue: add_label: [GitHub, GitLab] ``` -------------------------------- ### Acquire GitHub Token by Copy-Pasting Source: https://github.com/packit/ogr/blob/main/examples/user_owned_repositories.ipynb This snippet shows how to directly embed a GitHub API token as a string. While simple, it's less secure than using environment variables for production. ```python TOKEN = "" ``` -------------------------------- ### Print Release Information Source: https://github.com/packit/ogr/blob/main/examples/releases.ipynb This snippet shows how to iterate through a filtered list of releases and print specific details for each release, including its title, commit SHA, and tarball URL. This is typically the final step in processing release data. ```python for release in releases_in_20: print(f"{release.title}: {release.git_tag.commit_sha}\n({release.tarball_url})") ``` -------------------------------- ### Acquire GitHub Token from Environment Variable Source: https://github.com/packit/ogr/blob/main/examples/user_owned_repositories.ipynb This snippet demonstrates how to retrieve a GitHub API token from the GITHUB_TOKEN environment variable using Python's os module. It's a common method for securely managing credentials. ```python import os TOKEN = os.environ.get("GITHUB_TOKEN") # if variable is not set, you get `None` ``` -------------------------------- ### Retrieve User Object and List Projects Source: https://github.com/packit/ogr/blob/main/examples/user_owned_repositories.ipynb This snippet demonstrates how to access the user object associated with the provided token and then retrieve a list of the user's projects. It also shows how to iterate through the first three projects and print their names and the count of open pull requests. ```python user = service.user # Now we can get list of projects from a user projects = user.get_projects() # And we print first 3 out: for project in projects[:3]: print(f"{project.namespace}/{project.repo} has {len(project.get_pr_list())} pull requests open") ``` -------------------------------- ### IssueComment Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of IssueComment methods and properties across GitHub, GitLab, Pagure, and Forgejo. Includes support for 'body' (get/set), 'add_reaction', and 'get_reactions'. ```APIDOC IssueComment: body: get: [GitHub, GitLab, Pagure] set: [GitHub, GitLab] add_reaction: [GitHub, GitLab] get_reactions: [GitHub, GitLab] ``` -------------------------------- ### List Open Pull Requests Source: https://github.com/packit/ogr/blob/main/examples/list_pr_patches.ipynb Retrieves a list of all open pull requests for a given project and prints the total count. This snippet assumes a 'project' object has already been obtained. ```python open_prs = project.get_pr_list() print(f"Open pull requests: {len(open_prs)}") ``` -------------------------------- ### Pull Request Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Pull Request methods and properties across GitHub, GitLab, Pagure, and Forgejo. Includes support for 'add_label' and 'get_all_commits'. ```APIDOC PullRequest: add_label: [GitHub, GitLab, Forgejo] get_all_commits: [GitHub, GitLab, Forgejo] ``` -------------------------------- ### Iterate and Display Pull Request Patches Source: https://github.com/packit/ogr/blob/main/examples/list_pr_patches.ipynb Iterates through a list of open pull requests, printing the PR ID, title, the first four lines of its patch, and the full diff URL. This requires the 'open_prs' list to be populated. ```python for pr in open_prs: print(f"# {pr.id}: {pr.title}") for line in pr.patch.splitlines()[:4]: print(line) print(f"Full diff: {pr.diff_url}") print() ``` -------------------------------- ### Sync Labels to Target Project Source: https://github.com/packit/ogr/blob/main/examples/syncing_labels.ipynb Updates the labels in a target GitHub project with the filtered list of labels. This operation synchronizes the labels from the source to the target repository. ```python target_project = service.get_project(namespace="packit", repo="validation") target_project.update_labels(wanted_labels) ``` -------------------------------- ### Create a New Issue Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Creates a new issue within a given project with a specified title and body. ```python new_issue = project.create_issue(title="Something TBD", body="new issue related to xyz") ``` -------------------------------- ### Commit Flag Compatibility Source: https://github.com/packit/ogr/blob/main/COMPATIBILITY.md Details the compatibility of Commit flag properties across GitHub, GitLab, Pagure, and Forgejo. Specifically covers the 'edited' flag. ```APIDOC CommitFlag: edited: [GitHub, Pagure] ``` -------------------------------- ### Close an Issue Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Closes an existing issue. ```python new_issue.close() ``` -------------------------------- ### Filter Releases by Creation Date Source: https://github.com/packit/ogr/blob/main/examples/releases.ipynb This snippet illustrates how to filter a list of releases to include only those created on or after a specified date. It uses Python's datetime module and a lambda function for filtering. ```python import datetime since = datetime.datetime(year=2020, month=1, day=1) releases_in_20 = filter( lambda release: datetime.datetime.fromisoformat(release.created_at.split('.')[0]) >= since, all_releases, ) ``` -------------------------------- ### Makefile Targets for Removing Response Files Source: https://github.com/packit/ogr/blob/main/CONTRIBUTING.md Makefile targets to remove generated response files for testing, categorized by service. ```shell make remove-response-files make remove-response-files-github make remove-response-files-gitlab make remove-response-files-pagure ``` -------------------------------- ### Filter Labels Source: https://github.com/packit/ogr/blob/main/examples/syncing_labels.ipynb Filters the fetched labels to include only those that contain a '/' in their name. This is useful for selecting specific labels for synchronization. ```python wanted_labels = list(filter(lambda label: "/" in label.name, labels)) wanted_labels ``` -------------------------------- ### Add a Comment to an Issue Source: https://github.com/packit/ogr/blob/main/examples/working_with_issues.ipynb Adds a comment to an existing issue. ```python new_issue.comment("first comment") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.