Skip to content

Commit

Permalink
feat: validate gitlabrc execution with small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpmatos committed Jul 27, 2020
1 parent 2cb3603 commit 4e07f70
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 44 deletions.
3 changes: 0 additions & 3 deletions gitlabcr/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions gitlabcr/constants.py

This file was deleted.

3 changes: 3 additions & 0 deletions gitlabrc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = ".".join(map(str, (0, 0, 6)))
File renamed without changes.
23 changes: 13 additions & 10 deletions gitlabcr/cli.py → gitlabrc/cli.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# -*- coding: utf-8 -*-

import os
from . import constants
from .constants import CLI
from .settings import Config
from typing import NoReturn, Text
from argparse import ArgumentParser, RawTextHelpFormatter

class Arguments:

def __init__(self, argv=None) -> NoReturn:
self._config = Config()
self._parser = self._create_parser_object()
self._adding_arguments()
self.args = self._parser.parse_args(argv)
args_print = vars(self.args ).copy()
args_print["token"] = "xxxxx"
print("running with args [%s]", args_print)

def _create_parser_object(self) -> ArgumentParser:
return ArgumentParser(
description="Gitlabrc - clones all projects inside namespaces",
prog="gitlabcr",
epilog=constants.CLI,
description="GitlabRC is a CLI that help you to clone all projects inside a specific namespace in Gitlab",
prog="gitlabrc",
epilog=CLI,
formatter_class=RawTextHelpFormatter)

def _adding_arguments(self) -> NoReturn:
Expand All @@ -32,7 +31,7 @@ def _adding_arguments(self) -> NoReturn:
self._parser.add_argument("-t", "--token",
type=str,
dest="token",
default=os.environ.get("GITLAB_TOKEN"),
default=self._config.get_env("GITLAB_TOKEN"),
metavar="<token>",
help="token GitLab API")
self._parser.add_argument("-n", "--namespace",
Expand All @@ -42,16 +41,20 @@ def _adding_arguments(self) -> NoReturn:
metavar="<namespace>",
help="namespace in GitLab to clone all projects")
self._parser.add_argument("-p", "--path",
type="string",
dest="path",
default=os.getenv("PWD"),
default=self._config.get_env("PWD"),
metavar="<path>",
help="destination path for cloned projects")
self._parser.add_argument("--disable-root",
action="store_true",
dest="noroot",
default=False,
help="do not create root namepace folder in path")
self._parser.add_argument("--dry-run",
action="store_true",
dest="dryrun",
default=False,
help="list the repositories without clone/fetch")
self._parser.add_argument("--version",
action="store_true",
help="show version")
28 changes: 14 additions & 14 deletions gitlabcr/clone.py → gitlabrc/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
import gitlab
import optparse
import subprocess
from . import settings
from . import cli
from .cli import Arguments
from . import __version__ as VERSION

from art import *

def pname():
return f"[gitlab-cloner - {str(os.getpid())}]"

def main():
args = cli.Arguments(argv=None if sys.argv[1:] else ["--help"]).args
Art=text2art("GitLabRC")
print(Art)

args = Arguments(argv=None if sys.argv[1:] else ["--help"]).args

if args.version:
print(VERSION)
print(f"Version: {VERSION}")
sys.exit(0)

clone(args)

def clone(options):
perform(args)

config = settings.Config()
def perform(options):

url = options.url if options.url else config.get_env("GITLAB_URL")
token = options.token if options.token else config.get_env("GITLAB_TOKEN")
namespace = options.namespace if options.namespace else None
url = options.url
token = options.token
namespace = options.namespace

# TODO catch errrors
if not url:
Expand Down Expand Up @@ -70,9 +72,7 @@ def clone(options):
print(pname() + " found " + project.path_with_namespace)

# Get all projects inside the subgroups
for group in gl.groups.list(
all=True, owned=True, query_parameters={"id": namespace}
):
for group in gl.groups.list(all=True, owned=True, query_parameters={"id": namespace}):

for project in group.projects.list(all=True):
projects.append(project)
Expand Down
13 changes: 13 additions & 0 deletions gitlabrc/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-

CLI = """
Examples:
Clone all projects inside specific namespace in current directory:
gitlabcr -u $GITLAB_URL -t $GITLAB_TOKEN -n msp/charts
Clone all projects inside specific namespace in specific directory:
gitlabcr -u $GITLAB_URL -t $GITLAB_TOKEN -n msp/charts -p /home/ubuntu
"""
File renamed without changes.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
art==4.7
python-gitlab==2.4.0
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import io
import os
from gitlabcr import __version__
from gitlabrc import __version__
from setuptools import setup, find_packages

# Package meta-data.
NAME = "gitlabcr"
DESCRIPTION = "CLI to help you clone projects inside groups in Gitlab"
URL = "https://github.com/lpmatos/gitlab-clone-recursive"
NAME = "gitlabrc"
DESCRIPTION = "GitlabRC is a CLI that help you to clone all projects inside a specific namespace in Gitlab"
URL = "https://github.com/lpmatos/gitlabrc"
EMAIL = "luccapsm@gmail.com"
AUTHOR = "Lucca Pessoa da Silva Matos"
REQUIRES_PYTHON = ">=3.6.0"
Expand All @@ -19,6 +19,7 @@
"python-gitlab"
]

# Getting current location of this file.
here = os.path.abspath(os.path.dirname(__file__))

# Import the README and use it as the long-description.
Expand All @@ -29,6 +30,7 @@
except FileNotFoundError:
LONG_DESCRIPTION = DESCRIPTION

# Build setup package.
setup(
name = NAME,
version = VERSION,
Expand All @@ -45,7 +47,7 @@
license = "MIT license",
keywords = [
"gitlab",
"gitlab-api",
"git",
"cli",
"python"
],
Expand Down

0 comments on commit 4e07f70

Please sign in to comment.