python-gerrit-api


Namepython-gerrit-api JSON
Version 2.0.8 PyPI version JSON
download
home_pagehttps://github.com/shijl0925/python-gerrit-api
SummaryPython wrapper for the Gerrit REST API.
upload_time2022-08-17 13:57:03
maintainer
docs_urlNone
authorJialiang Shi
requires_python
licenseMIT
keywords api gerrit client wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Project description
===================

.. image:: https://img.shields.io/pypi/pyversions/python-gerrit-api.svg
    :target: https://pypi.python.org/pypi/python-gerrit-api
.. image:: https://img.shields.io/pypi/v/python-gerrit-api.svg
    :target: https://pypi.python.org/pypi/python-gerrit-api
.. image:: https://pepy.tech/badge/python-gerrit-api
    :target: https://pepy.tech/project/python-gerrit-api
.. image:: https://sonarcloud.io/api/project_badges/measure?project=shijl0925_python-gerrit-api&metric=alert_status
    :target: https://sonarcloud.io/dashboard?id=shijl0925_python-gerrit-api
.. image:: https://img.shields.io/github/license/shijl0925/python-gerrit-api.svg
    :target: LICENSE
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

What is it?
-----------
python-gerrit-api provides a simple interface for clients to interact with Gerrit Code Review via the REST API.

Installation
------------

The easiest way to install the latest version is by using pip to pull it from PyPI.

Using Pip or Setuptools

.. code-block:: bash

	pip install python-gerrit-api

Or:

.. code-block:: bash

	easy_install python-gerrit-api


You may also use Git to clone the repository from Github and install it manually.

.. code-block:: bash

    git clone https://github.com/shijl0925/python-gerrit-api.git
    cd python-gerrit-api
    python setup.py install

Usage
-----

Example 1: setup gerrit client::

    from gerrit import GerritClient
    client = GerritClient(base_url="https://yourgerrit", username='******', password='xxxxx')

Example 2: operate gerrit project::

    # Retrieves a project.
    project = client.projects.get('MyProject')

    # or
    project = client.get(endpoint="/projects/MyProject")

    # Creates a new project.
    input_ = {
        "description": "This is a demo project.",
        "submit_type": "INHERIT",
        "owners": [
          "MyProject-Owners"
        ]
    }
    client.projects.create('MyProject', input_)

    # or
    client.post(endpoint="/projects/MyProject", json=input_)

    # Sets the description of a project.
    project = client.projects.get('MyProject')
    input_ = {
        "description": "Plugin for Gerrit that handles the replication.",,
        "commit_message": "Update the project description"
    }
    result = project.set_description(input_)

    # or
    result = client.put(endpoint="/projects/MyProject/description", json=input_)

    # Deletes the description of a project.
    project = client.projects.get('MyProject')
    project.delete_description()

    # or
    client.put(endpoint="/projects/MyProject/description")

    # get a branch of th project by ref
    branch = project.branches.get('refs/heads/stable')

    # get these branches of th project
    branches = client.get(endpoint = "/projects/MyProject"/branches/)

    # Creates a new branch.
    input_ = {
        'revision': '76016386a0d8ecc7b6be212424978bb45959d668'
    }
    new_branch = project.branches.create('stable', input_)

    # or
    result = client.put(endpoint="/projects/MyProject/branches/stable", json=input_)


Example 3: operate gerrit change::

    # Retrieves a change.
    change = client.changes.get('python-sonarqube-api~stable3~I60c3bf10a5b0daf62a0f7c38bdf90b15026bbc2e')

    # or
    change = client.get(endpoint='/changes/python-sonarqube-api~stable3~I60c3bf10a5b0daf62a0f7c38bdf90b15026bbc2e')

    # Marks a change as reviewed.
    change.mark_as_reviewed()

    # Adds and removes hashtags from a change.
    input_ = {
        "add" : [
            "hashtag3"
        ],
        "remove" : [
            "hashtag2"
        ]
    }
    result = change.set_hashtags(input_)

    # get one revision by revision id
    revision = change.get_revision('534b3ce21655a092eccf72680f2ad16b8fecf119')

    # get a file by path
    file = revision.files.get('sonarqube/community/favorites.py')

    # Gets the diff of a file from a certain revision.
    file_diff = file.get_diff()

Example 4: operate gerrit account::

    # Retrieves an account
    account = client.accounts.get('kevin.shi')

    # Sets the full name of an account.
    input_ = {
        "name": "Keven Shi"
    }
    result = account.set_name(input_)

    # Adds an SSH key for a user.
    ssh_key = 'ssh-rsa xxx'
    result = account.ssh_keys.add(ssh_key)

Example 5: operate gerrit group::

    # Retrieves a group.
    group = client.groups.get('af01a8cb8cbd8ee7be072b98b1ee882867c0cf06')

    # Adds a user as member to a Gerrit internal group.
    result = group.add_member("ci_jenkins")

    # Sets the owner group of a Gerrit internal group.
    input_ = {
        "owner": "6a1e70e1a88782771a91808c8af9bbb7a9871389"
    }
    result = group.set_owner(input_)

About this library
-------------------
Gerrit is a code review and project management tool for Git based projects.

Gerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.

Gerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer.

This library allows you to automate most common Gerrit operations using Python, such as:

* Ability to create/delete/query Gerrit projects, and ability to execute project:
    * Retrieves/Set/Delete the description of a project.
    * Retrieves the name of a project's parent project, and set the parent project for a project.
    * Retrieves for a project the name of the branch to which HEAD points, and sets HEAD for a project.
    * Gets some configuration information about a project, and sets the configuration of a project.
    * Lists the access rights for a single project, and sets access rights for a project.
    * Retrieves a commit of a project.
    * Ability to execute project's branches, tags, labels, dashboards and so on:
        * Retrieves/Create/Delete
    * ...

* Ability to create/query Gerrit accounts, and ability to execute account:
    * Sets/Deletes the full name of an account.
    * Retrieves/Sets the status of an account.
    * Sets the username of an account.
    * Sets the display name of an account.
    * Checks if an account is active, and sets the account state to active/inactive.
    * Sets/Generates/Deletes the HTTP password of an account.
    * Retrieves a previously obtained OAuth access token.
    * Retrieves/Sets the user's (diff/edit) preferences.
    * Retrieves/Add/Deletes the watched projects of an account.
    * Retrieves/Delete the external ids of a user account.
    * Ability to execute account's emails, ssh keys, gpg keys.
        * Retrieves/Create/Delete
    * ...

* Ability to create/query Gerrit groups, and ability to execute group:
    * Renames a Gerrit internal group.
    * Sets/Deletes the description of a Gerrit internal group.
    * Sets the options of a Gerrit internal group.
    * Sets the owner group of a Gerrit internal group.
    * Gets the audit log of a Gerrit internal group.
    * Lists the direct members of a Gerrit internal group.
    * Retrieves/Adds/Removes a group member to a Gerrit internal group..
    * Lists/Retrieves/Adds/Removes the direct subgroups of a group.

* Ability to create/delete/query Gerrit changes, and ability to execute change:
    * Update/Abandon/Restore/Rebase/Move/Revert/Submit an existing change.
    * Creates a new patch set with a new commit message.
    * Retrieves/Sets/Deletes the topic of a change.
    * Retrieves/Sets/Deletes the assignee of a change.
    * Retrieves the branches and tags in which a change is included.
    * Lists the published comments, the robot comments of all revisions of the change.
    * Lists the draft comments of all revisions of the change that belong to the calling user.
    * Marks the change as (not) ready for review.
    * Marks the change to be private/non-private.
    * Marks/Un-marks a change as ignored.
    * Marks a change as reviewed/unreviewed.
    * Gets/Adds/Removes the hashtags associated with a change.
    * Ability to execute change's messages, change edit, reviewers, revision
    * Retrieves all users that are currently in the attention set, Adds a single user to the attention set of a change, Deletes a single user from the attention set of a change.
    * ...

* Ability to execute Gerrit config:
    * Retrieves/Sets the default user/diff/edit preferences for the server.
    * ...

* Ability to install/enable/disable/reload/query Gerrit plugins

For a full documentation spec of what this library supports see `readthedocs
<https://python-gerrit-api.readthedocs.io/en/latest/>`_

Python versions
---------------

The project has been tested against Python versions:

* 3.6
* 3.7
* 3.8
* 3.9
* 3.10

Gerrit versions
---------------

Project tested on Version 3.5.0 Gerrit.

Important Links
---------------

Support and bug-reports: https://github.com/shijl0925/python-gerrit-api/issues?direction=desc&sort=comments&state=open

Project source code: github: https://github.com/shijl0925/python-gerrit-api

Project documentation: https://python-gerrit-api.readthedocs.org/en/latest/

Releases: http://pypi.python.org/pypi/python-gerrit-api



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shijl0925/python-gerrit-api",
    "name": "python-gerrit-api",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "api gerrit client wrapper",
    "author": "Jialiang Shi",
    "author_email": "kevin09254930sjl@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f9/c0/b3484915bb329562e70872ad33a978c1f1034cab4a64bc670283d0a60571/python-gerrit-api-2.0.8.tar.gz",
    "platform": null,
    "description": "Project description\n===================\n\n.. image:: https://img.shields.io/pypi/pyversions/python-gerrit-api.svg\n    :target: https://pypi.python.org/pypi/python-gerrit-api\n.. image:: https://img.shields.io/pypi/v/python-gerrit-api.svg\n    :target: https://pypi.python.org/pypi/python-gerrit-api\n.. image:: https://pepy.tech/badge/python-gerrit-api\n    :target: https://pepy.tech/project/python-gerrit-api\n.. image:: https://sonarcloud.io/api/project_badges/measure?project=shijl0925_python-gerrit-api&metric=alert_status\n    :target: https://sonarcloud.io/dashboard?id=shijl0925_python-gerrit-api\n.. image:: https://img.shields.io/github/license/shijl0925/python-gerrit-api.svg\n    :target: LICENSE\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\nWhat is it?\n-----------\npython-gerrit-api provides a simple interface for clients to interact with Gerrit Code Review via the REST API.\n\nInstallation\n------------\n\nThe easiest way to install the latest version is by using pip to pull it from PyPI.\n\nUsing Pip or Setuptools\n\n.. code-block:: bash\n\n\tpip install python-gerrit-api\n\nOr:\n\n.. code-block:: bash\n\n\teasy_install python-gerrit-api\n\n\nYou may also use Git to clone the repository from Github and install it manually.\n\n.. code-block:: bash\n\n    git clone https://github.com/shijl0925/python-gerrit-api.git\n    cd python-gerrit-api\n    python setup.py install\n\nUsage\n-----\n\nExample 1: setup gerrit client::\n\n    from gerrit import GerritClient\n    client = GerritClient(base_url=\"https://yourgerrit\", username='******', password='xxxxx')\n\nExample 2: operate gerrit project::\n\n    # Retrieves a project.\n    project = client.projects.get('MyProject')\n\n    # or\n    project = client.get(endpoint=\"/projects/MyProject\")\n\n    # Creates a new project.\n    input_ = {\n        \"description\": \"This is a demo project.\",\n        \"submit_type\": \"INHERIT\",\n        \"owners\": [\n          \"MyProject-Owners\"\n        ]\n    }\n    client.projects.create('MyProject', input_)\n\n    # or\n    client.post(endpoint=\"/projects/MyProject\", json=input_)\n\n    # Sets the description of a project.\n    project = client.projects.get('MyProject')\n    input_ = {\n        \"description\": \"Plugin for Gerrit that handles the replication.\",,\n        \"commit_message\": \"Update the project description\"\n    }\n    result = project.set_description(input_)\n\n    # or\n    result = client.put(endpoint=\"/projects/MyProject/description\", json=input_)\n\n    # Deletes the description of a project.\n    project = client.projects.get('MyProject')\n    project.delete_description()\n\n    # or\n    client.put(endpoint=\"/projects/MyProject/description\")\n\n    # get a branch of th project by ref\n    branch = project.branches.get('refs/heads/stable')\n\n    # get these branches of th project\n    branches = client.get(endpoint = \"/projects/MyProject\"/branches/)\n\n    # Creates a new branch.\n    input_ = {\n        'revision': '76016386a0d8ecc7b6be212424978bb45959d668'\n    }\n    new_branch = project.branches.create('stable', input_)\n\n    # or\n    result = client.put(endpoint=\"/projects/MyProject/branches/stable\", json=input_)\n\n\nExample 3: operate gerrit change::\n\n    # Retrieves a change.\n    change = client.changes.get('python-sonarqube-api~stable3~I60c3bf10a5b0daf62a0f7c38bdf90b15026bbc2e')\n\n    # or\n    change = client.get(endpoint='/changes/python-sonarqube-api~stable3~I60c3bf10a5b0daf62a0f7c38bdf90b15026bbc2e')\n\n    # Marks a change as reviewed.\n    change.mark_as_reviewed()\n\n    # Adds and removes hashtags from a change.\n    input_ = {\n        \"add\" : [\n            \"hashtag3\"\n        ],\n        \"remove\" : [\n            \"hashtag2\"\n        ]\n    }\n    result = change.set_hashtags(input_)\n\n    # get one revision by revision id\n    revision = change.get_revision('534b3ce21655a092eccf72680f2ad16b8fecf119')\n\n    # get a file by path\n    file = revision.files.get('sonarqube/community/favorites.py')\n\n    # Gets the diff of a file from a certain revision.\n    file_diff = file.get_diff()\n\nExample 4: operate gerrit account::\n\n    # Retrieves an account\n    account = client.accounts.get('kevin.shi')\n\n    # Sets the full name of an account.\n    input_ = {\n        \"name\": \"Keven Shi\"\n    }\n    result = account.set_name(input_)\n\n    # Adds an SSH key for a user.\n    ssh_key = 'ssh-rsa xxx'\n    result = account.ssh_keys.add(ssh_key)\n\nExample 5: operate gerrit group::\n\n    # Retrieves a group.\n    group = client.groups.get('af01a8cb8cbd8ee7be072b98b1ee882867c0cf06')\n\n    # Adds a user as member to a Gerrit internal group.\n    result = group.add_member(\"ci_jenkins\")\n\n    # Sets the owner group of a Gerrit internal group.\n    input_ = {\n        \"owner\": \"6a1e70e1a88782771a91808c8af9bbb7a9871389\"\n    }\n    result = group.set_owner(input_)\n\nAbout this library\n-------------------\nGerrit is a code review and project management tool for Git based projects.\n\nGerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.\n\nGerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer.\n\nThis library allows you to automate most common Gerrit operations using Python, such as:\n\n* Ability to create/delete/query Gerrit projects, and ability to execute project:\n    * Retrieves/Set/Delete the description of a project.\n    * Retrieves the name of a project's parent project, and set the parent project for a project.\n    * Retrieves for a project the name of the branch to which HEAD points, and sets HEAD for a project.\n    * Gets some configuration information about a project, and sets the configuration of a project.\n    * Lists the access rights for a single project, and sets access rights for a project.\n    * Retrieves a commit of a project.\n    * Ability to execute project's branches, tags, labels, dashboards and so on:\n        * Retrieves/Create/Delete\n    * ...\n\n* Ability to create/query Gerrit accounts, and ability to execute account:\n    * Sets/Deletes the full name of an account.\n    * Retrieves/Sets the status of an account.\n    * Sets the username of an account.\n    * Sets the display name of an account.\n    * Checks if an account is active, and sets the account state to active/inactive.\n    * Sets/Generates/Deletes the HTTP password of an account.\n    * Retrieves a previously obtained OAuth access token.\n    * Retrieves/Sets the user's (diff/edit) preferences.\n    * Retrieves/Add/Deletes the watched projects of an account.\n    * Retrieves/Delete the external ids of a user account.\n    * Ability to execute account's emails, ssh keys, gpg keys.\n        * Retrieves/Create/Delete\n    * ...\n\n* Ability to create/query Gerrit groups, and ability to execute group:\n    * Renames a Gerrit internal group.\n    * Sets/Deletes the description of a Gerrit internal group.\n    * Sets the options of a Gerrit internal group.\n    * Sets the owner group of a Gerrit internal group.\n    * Gets the audit log of a Gerrit internal group.\n    * Lists the direct members of a Gerrit internal group.\n    * Retrieves/Adds/Removes a group member to a Gerrit internal group..\n    * Lists/Retrieves/Adds/Removes the direct subgroups of a group.\n\n* Ability to create/delete/query Gerrit changes, and ability to execute change:\n    * Update/Abandon/Restore/Rebase/Move/Revert/Submit an existing change.\n    * Creates a new patch set with a new commit message.\n    * Retrieves/Sets/Deletes the topic of a change.\n    * Retrieves/Sets/Deletes the assignee of a change.\n    * Retrieves the branches and tags in which a change is included.\n    * Lists the published comments, the robot comments of all revisions of the change.\n    * Lists the draft comments of all revisions of the change that belong to the calling user.\n    * Marks the change as (not) ready for review.\n    * Marks the change to be private/non-private.\n    * Marks/Un-marks a change as ignored.\n    * Marks a change as reviewed/unreviewed.\n    * Gets/Adds/Removes the hashtags associated with a change.\n    * Ability to execute change's messages, change edit, reviewers, revision\n    * Retrieves all users that are currently in the attention set, Adds a single user to the attention set of a change, Deletes a single user from the attention set of a change.\n    * ...\n\n* Ability to execute Gerrit config:\n    * Retrieves/Sets the default user/diff/edit preferences for the server.\n    * ...\n\n* Ability to install/enable/disable/reload/query Gerrit plugins\n\nFor a full documentation spec of what this library supports see `readthedocs\n<https://python-gerrit-api.readthedocs.io/en/latest/>`_\n\nPython versions\n---------------\n\nThe project has been tested against Python versions:\n\n* 3.6\n* 3.7\n* 3.8\n* 3.9\n* 3.10\n\nGerrit versions\n---------------\n\nProject tested on Version 3.5.0 Gerrit.\n\nImportant Links\n---------------\n\nSupport and bug-reports: https://github.com/shijl0925/python-gerrit-api/issues?direction=desc&sort=comments&state=open\n\nProject source code: github: https://github.com/shijl0925/python-gerrit-api\n\nProject documentation: https://python-gerrit-api.readthedocs.org/en/latest/\n\nReleases: http://pypi.python.org/pypi/python-gerrit-api\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python wrapper for the Gerrit REST API.",
    "version": "2.0.8",
    "split_keywords": [
        "api",
        "gerrit",
        "client",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "7abed5b3c62687ae8be68db87103e5b6",
                "sha256": "2b94dec5b4258bd934a24bd59da7c08cbea64f8b20522aab69a41ac1b53cedca"
            },
            "downloads": -1,
            "filename": "python_gerrit_api-2.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7abed5b3c62687ae8be68db87103e5b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 58121,
            "upload_time": "2022-08-17T13:57:00",
            "upload_time_iso_8601": "2022-08-17T13:57:00.308754Z",
            "url": "https://files.pythonhosted.org/packages/6d/1f/48c994268b2eb0f99e7834f4af70688a30e01618056ecbdd01bcef612ba5/python_gerrit_api-2.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d6599bc63f62d0fc2cff2b9fa77180f8",
                "sha256": "fd0d73dbb66a2818c152cd852b5aa9248bbe7d168cdbe82b7501901475a9fb74"
            },
            "downloads": -1,
            "filename": "python-gerrit-api-2.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "d6599bc63f62d0fc2cff2b9fa77180f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 40192,
            "upload_time": "2022-08-17T13:57:03",
            "upload_time_iso_8601": "2022-08-17T13:57:03.380513Z",
            "url": "https://files.pythonhosted.org/packages/f9/c0/b3484915bb329562e70872ad33a978c1f1034cab4a64bc670283d0a60571/python-gerrit-api-2.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-17 13:57:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "shijl0925",
    "github_project": "python-gerrit-api",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "python-gerrit-api"
}
        
Elapsed time: 0.41189s