예제 #1
0
파일: gitlab.py 프로젝트: cronohub/plugins
    def fetch(self):
        paths = []
        gitlab_id = 'gitlab'
        if 'CRONOHUB_GITLAB_ID' in os.environ:
            gitlab_id = os.environ['CRONOHUB_GITLAB_ID']

        target = Path.cwd() / 'target'
        if not target.exists():
            os.makedirs(str(target))

        self.gl = Gitlab.from_config(gitlab_id=gitlab_id,
                                     config_files=[self.cfg_file])
        projects = self.get_repo_list()
        p: v4.objects.Project
        for p in projects:
            # Create the export
            export = p.exports.create({})

            # Wait for the 'finished' status
            export.refresh()
            while export.export_status != 'finished':
                time.sleep(1)
                export.refresh()

            timestr = time.strftime("%Y%m%d-%H%M%S")
            filename = "{}_{}.gz".format(p.name, timestr)
            t = Path.cwd() / 'target' / filename
            # (Location, Filename) tuple
            paths.append((str(t), filename))
            with open(str(t), 'wb') as f:
                export.download(streamed=True, action=f.write)
        return paths
예제 #2
0
def get_gitlab_project(group, subgroup):
    project = get_project_for_group(group, subgroup)
    if project is None:
        return None

    gl = Gitlab.from_config(_gitlab_conf_section, [_gitlab_conf_file])
    return gl.projects.get(project)
예제 #3
0
def main():
    with Gitlab.from_config(config_files=["/tmp/python-gitlab.cfg"]) as gl:
        for project in gl.projects.list():
            project.delete()
        for group in gl.groups.list():
            group.delete()
        for user in gl.users.list():
            if user.username != "root":
                user.delete()
예제 #4
0
파일: config.py 프로젝트: Ikke/mkmr
    def get_gitlab(self) -> Gitlab:
        """
            Get the Gitlab object that is generated from this configuration file
        """
        gl = Gitlab.from_config(self.section, [self.config])
        # If the user passed --token to us then override the token acquired
        # from private_token
        if self.options.token is not None:
            gl.private_token = self.options.token

        # If the user passed --timeout to us then override the token acquired
        # from timeout or the default value
        if hasattr(self.options,
                   "timeout") and self.options.timeout is not None:
            gl.timeout = self.options.timeout
        return gl
예제 #5
0
def main():
    args = parse_args()
    check_old_gitlab()

    try:
        gl = Gitlab.from_config(gitlab_id=args.gitlab)
    except gitlab.config.ConfigError as cfgerr:
        print("Error loading python-gitlab config:", cfgerr)
        print(
            "See http://python-gitlab.readthedocs.io/en/stable/cli.html#configuration"
        )
        sys.exit(1)

    print('Would delete' if args.dry_run else 'Deleting',
          'non-tagged artifacts',
          end='')
    if args.min_age:
        print(' older than', args.min_age, end='')
    print('\n')

    cleanup = GitlabArtifactCleanup(dry_run=args.dry_run,
                                    min_age=args.min_age,
                                    keep=args.keep)

    if args.all_projects:
        for proj in gl.projects.list(as_list=False):
            cleanup.cleanup_project(proj)
    else:
        for pname in args.projects:
            try:
                proj = gl.projects.get(pname)
            except GitlabGetError as e:
                print("Error getting project", pname, e)
                continue
            cleanup.cleanup_project(proj)

    print('\n{action} {size} in {count} artifacts total'.format(
        action='Would delete' if args.dry_run else 'Deleted',
        size=format_datasize(cleanup.total_size),
        count=cleanup.total_count))
예제 #6
0
    def _create_user(self, username, first_name, email, password,
                     **extra_fields):
        is_test = extra_fields.pop('is_test')
        username = normalize_username(username)

        with transaction.atomic():
            user = self.model(username=username,
                              first_name=first_name,
                              **extra_fields)
            user.save()

            if settings.GITLAB_ENABLED:
                # Create Gitlab user
                gl = Gitlab.from_config(
                    gitlab_id=settings.GITLAB_ID,
                    config_files=[settings.GITLAB_CONFIG_PATH])
                gl_user = gl.users.create({
                    'email': email,
                    'username': username,
                    'password': password,
                    'name': user.get_full_name(),
                    'reset_password': False,
                    'projects_limit': 0,
                    'admin': False,
                    'can_create_group': False,
                    'skip_confirmation': True
                })

                if not user.is_active:
                    gl_user.deactivate()

            device = user.passworddevice_set.create(email=email)
            device.set_password(password)
            device.save()

            if not is_test:
                device.generate_challenge()

        return user
예제 #7
0
    def save(self, **kwargs):
        # Check if activation status of the user has changed
        activation_changed = False
        old_obj = self.__class__.objects.only('is_active').filter(
            pk=getattr(self, 'pk', None)).values().first()
        if old_obj and old_obj['is_active'] != self.is_active:
            activation_changed = True

        # Validate and save
        self.full_clean()
        super().save(**kwargs)

        # Update Gitlab user's activation status if needed
        if settings.GITLAB_ENABLED and activation_changed:
            gl = Gitlab.from_config(gitlab_id=settings.GITLAB_ID,
                                    config_files=[settings.GITLAB_CONFIG_PATH])
            gl_user = gl.users.list(username=self.username)[0]

            if self.is_active is True:
                gl_user.activate()
            else:
                gl_user.deactivate()
예제 #8
0
    def __init__(self, uri, token, insecure):
        """
        Connects to a GitLab instance using connection details from one of the
        local configuration files (see https://python-gitlab.readthedocs.io >
        Configuration > Files). Connects to GitLab.com by default if no config
        file is found. Specify an URI to override the config file lookup, the
        token is optional (anonymous access if none is supplied).
        """
        if not uri:
            try:
                self.api = Gitlab.from_config()
            except GitlabConfigMissingError:
                uri = GITLAB_DEFAULT_URI

        if uri:
            self.api = Gitlab(uri, private_token=token, per_page=100)

        if insecure:
            # pylint: disable=import-outside-toplevel
            from warnings import filterwarnings
            from urllib3.exceptions import InsecureRequestWarning

            filterwarnings('ignore', category=InsecureRequestWarning)
            self.api.ssl_verify = False
예제 #9
0
def test_gitlab_from_config(default_config):
    config_path = default_config
    Gitlab.from_config("one", [config_path])
예제 #10
0
        'HOST': v.get('database.default.host'),
        'PORT': v.get('database.default.port'),
        'NAME': v.get('database.default.name'),
        'USER': v.get('database.default.user'),
        'PASSWORD': v.get('database.default.password')
    }
}

# Hub
HUB_NAMESPACE = v.get('hub.namespace')

# Gitlab
GITLAB_ENABLED = v.get('gitlab.enabled')
GITLAB_ID = v.get('gitlab.id')
GITLAB_CONFIG_PATH = v.get('gitlab.config_path')
GITLAB_CLIENT = Gitlab.from_config(gitlab_id=GITLAB_ID,
                                   config_files=[GITLAB_CONFIG_PATH])
GITLAB_URL = GITLAB_CLIENT._base_url

GIT_HOST = v.get('git.host')
GIT_ADMIN_NAME = v.get('git.admin_name')
GIT_ADMIN_EMAIL = v.get('git.admin_email')
GIT_ADMIN_TOKEN = v.get('git.admin_token')
GIT_URL = f"https://*****:*****@{GIT_HOST}"

# Message Queue
QUEUE_CLIENT = v.get('queue.client')
QUEUE_SERVER_HOST = v.get('queue.host')
QUEUE_SERVER_USERNAME = v.get('queue.username')
QUEUE_SERVER_PASSWORD = v.get('queue.password')
QUEUE_SERVER_API_URL = f"amqp://{'%s:%s@' % (QUEUE_SERVER_USERNAME, QUEUE_SERVER_PASSWORD) if QUEUE_SERVER_USERNAME else ''}{QUEUE_SERVER_HOST}"
DATASET_FILLER_QUEUE_NAME = v.get('queue.dataset_filler_queue_name')
예제 #11
0
import json
import re
import yaml
import logging
from flask import Flask, request, abort
from gitlab import Gitlab
from pandas import DataFrame

app = Flask(__name__)
gl = Gitlab.from_config('global', ['gitlab.cfg'])
secretkey = "hogehoge"

DESC_PATTERN = re.compile(r'```yaml\n*((.|\s)*)\n*```')
NOTE_PATTERN = re.compile(r'```yaml\n*((.|\s)*)\n*```')


@app.route("/", methods=["POST"])
def index():
    if (request.headers.get("X-Gitlab-Token", "") != secretkey) or (
            request.headers.get("X-Gitlab-Event", "") != "Note Hook"):
        abort(400)

    data = json.loads(request.get_data())
    if ('merge_request' in data):
        project_id = data["project"]["id"]
        mr_id = data["merge_request"]["iid"]

        try:
            mr = gl.projects.get(project_id,
                                 lazy=True).mergerequests.get(mr_id)
            review_list = get_review_list(mr)
예제 #12
0
파일: glsession.py 프로젝트: oux/scripts
class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    def pgreen(t):
        print(OKGREEN + t + ENDC)


if __name__ == '__main__':
    gl = Gitlab.from_config(None, [os.path.expanduser("~/.gitlab.cfg")])
    parser = argparse.ArgumentParser()
    parser.add_argument("action")
    args = parser.parse_args()

    if os.getenv('BLOCK_BUTTON'):
        if args.action == "todo":
            call('browse https://gitlabee.dt.renault.com/dashboard/todos'.split(' '))
        elif args.action == "issues":
            call('browse https://gitlabee.dt.renault.com/dashboard/issues?assignee_id=248'.split(' '))
        elif args.action == "mrs":
            call('browse https://gitlabee.dt.renault.com/dashboard/merge_requests?assignee_id=248'.split(' '))


    if args.action == "todo":
        nb = 0
예제 #13
0
 def __init__(self, project='ao-mvp-backlog', gitlab=None):
     if gitlab is None:
         self.gitlab = Gitlab.from_config('pannet', ['.gitlabconfig', os.path.join(IssueManager.dir_path, '..', '.gitlabconfig')])
     self.gitlab.auth()
     self.project = self.gitlab.projects.list(search=project)[0]
     self.issues = self.project.issues.list()