gitlabber


Namegitlabber JSON
Version 1.2.6 PyPI version JSON
download
home_pagehttps://github.com/ezbz/gitlabber
SummaryA Gitlab clone/pull utility for backing up or cloning Gitlab groups
upload_time2024-07-03 02:07:35
maintainerNone
docs_urlNone
authorErez Mazor
requires_python>=3
licenseMIT
keywords gitlab python cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://github.com/ezbz/gitlabber/actions/workflows/python-app.yml/badge.svg?branch=master
    :target: https://github.com/ezbz/gitlabber/actions/workflows/python-app.yml

.. image:: https://codecov.io/gh/ezbz/gitlabber/branch/main/graph/badge.svg
  :target: https://codecov.io/gh/ezbz/gitlabber
  
.. image:: https://badge.fury.io/py/gitlabber.svg
    :target: https://badge.fury.io/py/gitlabber
  
.. image:: https://img.shields.io/pypi/l/gitlabber.svg
    :target: https://pypi.python.org/pypi/gitlabber/

.. image:: https://img.shields.io/pypi/pyversions/gitlabber
    :target: https://pypi.python.org/pypi/gitlabber/

.. image:: https://readthedocs.org/projects/gitlabber/badge/?version=latest&style=plastic
    :target: https://gitlabber.readthedocs.io/en/latest/README.html


Gitlabber
=========

* A utility to clone and pull GitLab groups, subgroups, group projects or personal user projects based on path selection


Purpose
-------

Gitlabber clones or pulls all projects under a subset of groups / subgroups by building a tree from the GitLab API and allowing you to specify which subset of the tree you want to clone using glob patterns and/or regex expressions.


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

* You can install Gitlabber from `PyPi <https://pypi.org/project/gitlabber>`_:

.. code-block:: bash

    pip install gitlabber

* You'll need to create an `access token <https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html>`_ from GitLab with API scopes `read_repository`
  and ``read_api`` (or ``api``, for GitLab versions <12.0)

Usage
-----

* Arguments can be provided via the CLI arguments directly or via environment variables:

    +---------------+---------------+---------------------------+
    | Argument      | Flag          | Environment Variable      |
    +===============+===============+===========================+
    | token         | -t            | `GITLAB_TOKEN`            |
    +---------------+---------------+---------------------------+
    | url           | -u            | `GITLAB_URL`              |
    +---------------+---------------+---------------------------+
    | method        | -m            | `GITLABBER_CLONE_METHOD`  |
    +---------------+---------------+---------------------------+
    | naming        | -n            | `GITLABBER_FOLDER_NAMING` |
    +---------------+---------------+---------------------------+
    | include       | -i            | `GITLABBER_INCLUDE`       |
    +---------------+---------------+---------------------------+
    | exclude       | -x            | `GITLABBER_EXCLUDE`       |
    +---------------+---------------+---------------------------+

* To view the tree run the command with your includes/excludes and the ``-p`` flag. It will print your tree like so:

.. code-block:: bash

    root [http://gitlab.my.com]
    ├── group1 [/group1]
    │   └── subgroup1 [/group1/subgroup1]
    │       └── project1 [/group1/subgroup1/project1]
    └── group2 [/group2]
        ├── subgroup1 [/group2/subgroup1]
        │   └── project2 [/group2/subgroup1/project2]
        ├── subgroup2 [/group2/subgroup2]
        └── subgroup3 [/group2/subgroup3]

* To see how to use glob patterns and regex to filter tree nodes, see the `globre project page <https://pypi.org/project/globre/#details>`_.

* Include/Exclude patterns do not work at the API level but work on the results returned from the API, for large Gitlab installations this can take a lot of time, if you need to reduce the amound of API calls for such projects use the ``--group-search`` parameter to search only for the top level groups the interest you using the `Gitlab Group Search API <https://docs.gitlab.com/ee/api/groups.html#search-for-group>` which allows you to do a partial like query for a Group's path or name

* Cloning vs Pulling: when running Gitlabber consecutively with the same parameters, it will scan the local tree structure; if the project directory exists and is a valid git repository (has .git folder in it) Gitlabber will perform a git pull in the directory, otherwise the project directory will be created and the GitLab project will be cloned into it.

* Cloning submodules: use the ``-r`` flag to recurse git submodules, uses the ``--recursive`` for cloning and utilizes `GitPython's smart update method <https://github.com/gitpython-developers/GitPython/blob/20f4a9d49b466a18f1af1fdfb480bc4520a4cdc2/git/objects/submodule/root.py#L67>`_ for updating cloned repositories

* Printed Usage:

.. code-block:: bash

    usage: gitlabber [-h] [-t token] [-T] [-u url] [--verbose] [-p] [--print-format {json,yaml,tree}] [-n {name,path}] [-m {ssh,http}]
                    [-a {include,exclude,only}] [-i csv] [-x csv] [-r] [-F] [-d] [-s] [-g term] [-U] [-o options] [--version]
                    [dest]

    Gitlabber - clones or pulls entire groups/projects tree from gitlab

    positional arguments:
    dest                  destination path for the cloned tree (created if doesn't exist)

    options:
    -h, --help            show this help message and exit
    -t token, --token token
                            gitlab personal access token https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
    -T, --hide-token      use an inline URL token (avoids storing the gitlab personal access token in the .git/config)
    -u url, --url url     base gitlab url (e.g.: 'http://gitlab.mycompany.com')
    --verbose             print more verbose output
    -p, --print           print the tree without cloning
    --print-format {json,yaml,tree}
                            print format (default: 'tree')
    -n {name,path}, --naming {name,path}
                            the folder naming strategy for projects from the gitlab API attributes (default: "name")
    -m {ssh,http}, --method {ssh,http}
                            the git transport method to use for cloning (default: "ssh")
    -a {include,exclude,only}, --archived {include,exclude,only}
                            include archived projects and groups in the results (default: "include")
    -i csv, --include csv
                            comma delimited list of glob patterns of paths to projects or groups to clone/pull
    -x csv, --exclude csv
                            comma delimited list of glob patterns of paths to projects or groups to exclude from clone/pull
    -r, --recursive       clone/pull git submodules recursively
    -F, --use-fetch       clone/fetch git repository (mirrored repositories)
    -d, --dont-checkout   don't checkout pulled git repository
    -s, --include-shared  include shared projects in the results
    -g term, --group-search term
                            only include groups matching the search term, filtering done at the API level (useful for large projects, see: https://docs.gitlab.com/ee/api/groups.html#search-for-group works with partial names of path or name)
    -U, --user-projects   fetch only user personal projects (skips the group tree altogether, group related parameters are ignored). Clones personal projects to '{gitlab-username}-personal-projects'
    -o options, --git-options options
                            provide additional options as csv for the git command (e.g., --depth=1). See: clone/multi_options https://gitpython.readthedocs.io/en/stable/reference.html#
    --version             print the version

    examples:

        clone an entire gitlab tree using a url and a token:
        gitlabber -t <personal access token> -u <gitlab url>

        only print the gitlab tree:
        gitlabber -p .

        clone only projects under subgroup 'MySubGroup' to location '~/GitlabRoot':
        gitlabber -i '/MyGroup/MySubGroup**' ~/GitlabRoot

        clone only projects under group 'MyGroup' excluding any projects under subgroup 'MySubGroup':
        gitlabber -i '/MyGroup**' -x '/MyGroup/MySubGroup**' .

        clone an entire gitlab tree except projects under groups named 'ArchiveGroup':
        gitlabber -x '/ArchiveGroup**' .

        clone projects that start with a case insensitive 'w' using a regular expression:
        gitlabber -i '/{[w].*}' .

        clone a user's personal projects to username-personal-projects
        gitlabber -U .

        perform a shallow clone of the git repositories
        gitlabber -o "\-\-depth=1," .



Debugging
---------
* You can use the ``--verbose`` flag to print Gitlabber debug messages
* For more verbose GitLab messages, you can get the `GitPython <https://gitpython.readthedocs.io/en/stable>`_ module to print more debug messages by setting the environment variable:

.. code-block:: bash

    export GIT_PYTHON_TRACE='full'

Troubleshooting
---------------
* ``GitlabHttpError: 503``: make sure you provide the base URL to your GitLab installation (e.g., `https://gitlab.my.com` and not `https://gitlab.my.com/some/nested/path`)
* ``git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)`` OR ``ERROR: The project you were looking for could not be found or you don't have permission to view it.``: if you are using Git's SSH method, follow the `SSH Guide <https://docs.gitlab.com/ee/user/ssh.html>`_ from Gitlab and ensure you have your SSH key in Gitlab for clone or use the HTTP method (``-m http`` flag)
  
Known Limitations
-----------------
* Renaming, moving and deleting projects: Gitlabber doesn't maintain local tree state (projects and groups). For that reason is does not rename move or delete local projects when they are modified on the server. When projects are moved or renamed, Gitlabber will clone them again under their new name or location. When deleted, Gitlabber will not delete the local project.
* Folder naming strategy: Consecutively running Gitlabber with different values for the ``-n`` parameter will produce undesirable results. Use the same value as previous runs, or simply don't change it from the default (project name).
* If you're going to clone a large number of projects, observe rate limits `for gitlab.com <https://docs.gitlab.com/ee/user/gitlab_com/index.html#gitlabcom-specific-rate-limits/>`_, and `for on-premise installations <https://docs.gitlab.com/ee/security/rate_limits.html>`_.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ezbz/gitlabber",
    "name": "gitlabber",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": null,
    "keywords": "gitlab, python, cli",
    "author": "Erez Mazor",
    "author_email": "erezmazor@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/92/91/ae0dd730a07f32c53841ecfa34373cb9e713184f0c6fa4b480c81a77fefe/gitlabber-1.2.6.tar.gz",
    "platform": null,
    "description": ".. image:: https://github.com/ezbz/gitlabber/actions/workflows/python-app.yml/badge.svg?branch=master\n    :target: https://github.com/ezbz/gitlabber/actions/workflows/python-app.yml\n\n.. image:: https://codecov.io/gh/ezbz/gitlabber/branch/main/graph/badge.svg\n  :target: https://codecov.io/gh/ezbz/gitlabber\n  \n.. image:: https://badge.fury.io/py/gitlabber.svg\n    :target: https://badge.fury.io/py/gitlabber\n  \n.. image:: https://img.shields.io/pypi/l/gitlabber.svg\n    :target: https://pypi.python.org/pypi/gitlabber/\n\n.. image:: https://img.shields.io/pypi/pyversions/gitlabber\n    :target: https://pypi.python.org/pypi/gitlabber/\n\n.. image:: https://readthedocs.org/projects/gitlabber/badge/?version=latest&style=plastic\n    :target: https://gitlabber.readthedocs.io/en/latest/README.html\n\n\nGitlabber\n=========\n\n* A utility to clone and pull GitLab groups, subgroups, group projects or personal user projects based on path selection\n\n\nPurpose\n-------\n\nGitlabber clones or pulls all projects under a subset of groups / subgroups by building a tree from the GitLab API and allowing you to specify which subset of the tree you want to clone using glob patterns and/or regex expressions.\n\n\nInstallation\n------------\n\n* You can install Gitlabber from `PyPi <https://pypi.org/project/gitlabber>`_:\n\n.. code-block:: bash\n\n    pip install gitlabber\n\n* You'll need to create an `access token <https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html>`_ from GitLab with API scopes `read_repository`\n  and ``read_api`` (or ``api``, for GitLab versions <12.0)\n\nUsage\n-----\n\n* Arguments can be provided via the CLI arguments directly or via environment variables:\n\n    +---------------+---------------+---------------------------+\n    | Argument      | Flag          | Environment Variable      |\n    +===============+===============+===========================+\n    | token         | -t            | `GITLAB_TOKEN`            |\n    +---------------+---------------+---------------------------+\n    | url           | -u            | `GITLAB_URL`              |\n    +---------------+---------------+---------------------------+\n    | method        | -m            | `GITLABBER_CLONE_METHOD`  |\n    +---------------+---------------+---------------------------+\n    | naming        | -n            | `GITLABBER_FOLDER_NAMING` |\n    +---------------+---------------+---------------------------+\n    | include       | -i            | `GITLABBER_INCLUDE`       |\n    +---------------+---------------+---------------------------+\n    | exclude       | -x            | `GITLABBER_EXCLUDE`       |\n    +---------------+---------------+---------------------------+\n\n* To view the tree run the command with your includes/excludes and the ``-p`` flag. It will print your tree like so:\n\n.. code-block:: bash\n\n    root [http://gitlab.my.com]\n    \u251c\u2500\u2500 group1 [/group1]\n    \u2502   \u2514\u2500\u2500 subgroup1 [/group1/subgroup1]\n    \u2502       \u2514\u2500\u2500 project1 [/group1/subgroup1/project1]\n    \u2514\u2500\u2500 group2 [/group2]\n        \u251c\u2500\u2500 subgroup1 [/group2/subgroup1]\n        \u2502   \u2514\u2500\u2500 project2 [/group2/subgroup1/project2]\n        \u251c\u2500\u2500 subgroup2 [/group2/subgroup2]\n        \u2514\u2500\u2500 subgroup3 [/group2/subgroup3]\n\n* To see how to use glob patterns and regex to filter tree nodes, see the `globre project page <https://pypi.org/project/globre/#details>`_.\n\n* Include/Exclude patterns do not work at the API level but work on the results returned from the API, for large Gitlab installations this can take a lot of time, if you need to reduce the amound of API calls for such projects use the ``--group-search`` parameter to search only for the top level groups the interest you using the `Gitlab Group Search API <https://docs.gitlab.com/ee/api/groups.html#search-for-group>` which allows you to do a partial like query for a Group's path or name\n\n* Cloning vs Pulling: when running Gitlabber consecutively with the same parameters, it will scan the local tree structure; if the project directory exists and is a valid git repository (has .git folder in it) Gitlabber will perform a git pull in the directory, otherwise the project directory will be created and the GitLab project will be cloned into it.\n\n* Cloning submodules: use the ``-r`` flag to recurse git submodules, uses the ``--recursive`` for cloning and utilizes `GitPython's smart update method <https://github.com/gitpython-developers/GitPython/blob/20f4a9d49b466a18f1af1fdfb480bc4520a4cdc2/git/objects/submodule/root.py#L67>`_ for updating cloned repositories\n\n* Printed Usage:\n\n.. code-block:: bash\n\n    usage: gitlabber [-h] [-t token] [-T] [-u url] [--verbose] [-p] [--print-format {json,yaml,tree}] [-n {name,path}] [-m {ssh,http}]\n                    [-a {include,exclude,only}] [-i csv] [-x csv] [-r] [-F] [-d] [-s] [-g term] [-U] [-o options] [--version]\n                    [dest]\n\n    Gitlabber - clones or pulls entire groups/projects tree from gitlab\n\n    positional arguments:\n    dest                  destination path for the cloned tree (created if doesn't exist)\n\n    options:\n    -h, --help            show this help message and exit\n    -t token, --token token\n                            gitlab personal access token https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html\n    -T, --hide-token      use an inline URL token (avoids storing the gitlab personal access token in the .git/config)\n    -u url, --url url     base gitlab url (e.g.: 'http://gitlab.mycompany.com')\n    --verbose             print more verbose output\n    -p, --print           print the tree without cloning\n    --print-format {json,yaml,tree}\n                            print format (default: 'tree')\n    -n {name,path}, --naming {name,path}\n                            the folder naming strategy for projects from the gitlab API attributes (default: \"name\")\n    -m {ssh,http}, --method {ssh,http}\n                            the git transport method to use for cloning (default: \"ssh\")\n    -a {include,exclude,only}, --archived {include,exclude,only}\n                            include archived projects and groups in the results (default: \"include\")\n    -i csv, --include csv\n                            comma delimited list of glob patterns of paths to projects or groups to clone/pull\n    -x csv, --exclude csv\n                            comma delimited list of glob patterns of paths to projects or groups to exclude from clone/pull\n    -r, --recursive       clone/pull git submodules recursively\n    -F, --use-fetch       clone/fetch git repository (mirrored repositories)\n    -d, --dont-checkout   don't checkout pulled git repository\n    -s, --include-shared  include shared projects in the results\n    -g term, --group-search term\n                            only include groups matching the search term, filtering done at the API level (useful for large projects, see: https://docs.gitlab.com/ee/api/groups.html#search-for-group works with partial names of path or name)\n    -U, --user-projects   fetch only user personal projects (skips the group tree altogether, group related parameters are ignored). Clones personal projects to '{gitlab-username}-personal-projects'\n    -o options, --git-options options\n                            provide additional options as csv for the git command (e.g., --depth=1). See: clone/multi_options https://gitpython.readthedocs.io/en/stable/reference.html#\n    --version             print the version\n\n    examples:\n\n        clone an entire gitlab tree using a url and a token:\n        gitlabber -t <personal access token> -u <gitlab url>\n\n        only print the gitlab tree:\n        gitlabber -p .\n\n        clone only projects under subgroup 'MySubGroup' to location '~/GitlabRoot':\n        gitlabber -i '/MyGroup/MySubGroup**' ~/GitlabRoot\n\n        clone only projects under group 'MyGroup' excluding any projects under subgroup 'MySubGroup':\n        gitlabber -i '/MyGroup**' -x '/MyGroup/MySubGroup**' .\n\n        clone an entire gitlab tree except projects under groups named 'ArchiveGroup':\n        gitlabber -x '/ArchiveGroup**' .\n\n        clone projects that start with a case insensitive 'w' using a regular expression:\n        gitlabber -i '/{[w].*}' .\n\n        clone a user's personal projects to username-personal-projects\n        gitlabber -U .\n\n        perform a shallow clone of the git repositories\n        gitlabber -o \"\\-\\-depth=1,\" .\n\n\n\nDebugging\n---------\n* You can use the ``--verbose`` flag to print Gitlabber debug messages\n* For more verbose GitLab messages, you can get the `GitPython <https://gitpython.readthedocs.io/en/stable>`_ module to print more debug messages by setting the environment variable:\n\n.. code-block:: bash\n\n    export GIT_PYTHON_TRACE='full'\n\nTroubleshooting\n---------------\n* ``GitlabHttpError: 503``: make sure you provide the base URL to your GitLab installation (e.g., `https://gitlab.my.com` and not `https://gitlab.my.com/some/nested/path`)\n* ``git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)`` OR ``ERROR: The project you were looking for could not be found or you don't have permission to view it.``: if you are using Git's SSH method, follow the `SSH Guide <https://docs.gitlab.com/ee/user/ssh.html>`_ from Gitlab and ensure you have your SSH key in Gitlab for clone or use the HTTP method (``-m http`` flag)\n  \nKnown Limitations\n-----------------\n* Renaming, moving and deleting projects: Gitlabber doesn't maintain local tree state (projects and groups). For that reason is does not rename move or delete local projects when they are modified on the server. When projects are moved or renamed, Gitlabber will clone them again under their new name or location. When deleted, Gitlabber will not delete the local project.\n* Folder naming strategy: Consecutively running Gitlabber with different values for the ``-n`` parameter will produce undesirable results. Use the same value as previous runs, or simply don't change it from the default (project name).\n* If you're going to clone a large number of projects, observe rate limits `for gitlab.com <https://docs.gitlab.com/ee/user/gitlab_com/index.html#gitlabcom-specific-rate-limits/>`_, and `for on-premise installations <https://docs.gitlab.com/ee/security/rate_limits.html>`_.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Gitlab clone/pull utility for backing up or cloning Gitlab groups",
    "version": "1.2.6",
    "project_urls": {
        "Download": "https://github.com/ezbz/gitlabber/archive/main.zip",
        "Homepage": "https://github.com/ezbz/gitlabber"
    },
    "split_keywords": [
        "gitlab",
        " python",
        " cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf794fc99d331ce98c06bb39c45ed25d41a38ca214736249cc742ab81a512f29",
                "md5": "abc3d25375fdea1d3dbc6b67cd69bdcb",
                "sha256": "7539dccb7f8664a1ff2d388d17dbb0d4b6a9762196a1bd75acae48d3d3935db4"
            },
            "downloads": -1,
            "filename": "gitlabber-1.2.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "abc3d25375fdea1d3dbc6b67cd69bdcb",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3",
            "size": 15108,
            "upload_time": "2024-07-03T02:07:32",
            "upload_time_iso_8601": "2024-07-03T02:07:32.424029Z",
            "url": "https://files.pythonhosted.org/packages/bf/79/4fc99d331ce98c06bb39c45ed25d41a38ca214736249cc742ab81a512f29/gitlabber-1.2.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9291ae0dd730a07f32c53841ecfa34373cb9e713184f0c6fa4b480c81a77fefe",
                "md5": "3d8efd7b99dfecfb53443b3c90db563b",
                "sha256": "f83658956758e4f03992e2454463fb48dbe16bf7e55d9af26d1a791bec638c43"
            },
            "downloads": -1,
            "filename": "gitlabber-1.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "3d8efd7b99dfecfb53443b3c90db563b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 52375,
            "upload_time": "2024-07-03T02:07:35",
            "upload_time_iso_8601": "2024-07-03T02:07:35.421113Z",
            "url": "https://files.pythonhosted.org/packages/92/91/ae0dd730a07f32c53841ecfa34373cb9e713184f0c6fa4b480c81a77fefe/gitlabber-1.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-03 02:07:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ezbz",
    "github_project": "gitlabber",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "gitlabber"
}
        
Elapsed time: 3.67418s