def perform_migrate_issues(args):

    closed_states = []
    if (args.closed_states):
        closed_states = args.closed_states.split(',')

    custom_fields = []
    if (args.custom_fields):
        custom_fields = args.custom_fields.split(',')

    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()

    gitlab_users_index = gitlab_instance.get_users_index()
    redmine_users_index = redmine_project.get_users_index()
    milestones_index = gitlab_project.get_milestones_index()

    log.debug('GitLab milestones are: {}'.format(', '.join(milestones_index) +
                                                 ' '))

    # get issues
    log.info('Getting redmine issues')
    issues = redmine_project.get_all_issues()

    # convert issues
    log.info('Converting issues')
    issues_data = (convert_issue(args.redmine_key, i, redmine_users_index,
                                 gitlab_users_index, milestones_index,
                                 closed_states, custom_fields) for i in issues)

    # create issues
    log.info('Creating gitlab issues')
    for data, meta in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'], len(meta['notes'])))

        else:

            try:
                created = gitlab_project.create_issue(data, meta)
                log.info('#{iid} {title}'.format(**created))
            except:
                log.info('create issue "{}" failed'.format(data['title']))
                raise
Exemple #2
0
def perform_migrate_issues(args):
    redmine = RedmineClient(args.redmine_key)
    gitlab = GitlabClient(args.gitlab_key)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()

    gitlab_users_index = gitlab_instance.get_users_index()
    redmine_users_index = redmine_project.get_users_index()

    checks = [
        (check_users, 'Required users presence'),
        (check_no_issue, 'Project has no pre-existing issue'),
    ]
    for i in checks:
        check(
            *i, redmine_project=redmine_project, gitlab_project=gitlab_project)

    # Get issues

    issues = redmine_project.get_all_issues()
    milestones_index = gitlab_project.get_milestones_index()
    issues_data = (
        convert_issue(
            i, redmine_users_index, gitlab_users_index, milestones_index)
        for i in issues)

    for data, meta in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'],
                len(meta['notes'])))
        else:
            created = gitlab_project.create_issue(data, meta)
            log.info('#{iid} {title}'.format(**created))
def perform_migrate_issues(args):
    closed_states = []
    if (args.closed_states):
        closed_states = args.closed_states.split(',')

    custom_fields = []
    if (args.custom_fields):
        custom_fields = args.custom_fields.split(',')

    if (args.user_dict is not None):
        load_user_dict(args.user_dict)

    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()
    if (args.project_members_only):
        gitlab_users_index = gitlab_project.get_members_index()
    else:
        gitlab_users_index = gitlab_instance.get_users_index()
    redmine_users_index = redmine_project.get_users_index()
    milestones_index = gitlab_project.get_milestones_index()
    textile_converter = TextileConverter()

    log.debug('GitLab milestones are: {}'.format(', '.join(milestones_index) + ' '))
    # get issues
    log.info('Getting redmine issues')
    issues = redmine_project.get_all_issues()
    if args.initial_id:
        issues = [issue for issue in issues if int(args.initial_id) <= issue['id']]

    if args.filter:
        filters = args.filter.split(",")
        filters = [filter.split("=") for filter in filters]
        filters = [[field.split("."), re.compile(value)] for field, value in filters]
        issues = [issue for issue in issues
            if all(
                value.match(reduce(
                    lambda object, key: object.get(key) if object is not None else None,
                    field,
                    issue
                )) for field, value in filters)]

    # convert issues
    log.info('Converting issues')
    issues_data = (
        convert_issue(args.redmine_key,
            i, redmine_users_index, gitlab_users_index, milestones_index, closed_states, custom_fields, textile_converter,
            args.keep_id or args.keep_title, args.sudo, args.archive_acc, args.migrate_version_as_label)
        for i in issues)

    # create issues
    log.info('Creating gitlab issues')
    last_iid = int(args.initial_id or 1) - 1
    for data, meta, redmine_id in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'],
                len(meta['notes'])))

        else:
            if args.keep_id:
                try:
                    fake_meta = {'uploads': [], 'notes': [], 'must_close': False}
                    if args.sudo:
                        fake_meta['sudo_user'] = args.archive_acc
                    while redmine_id > last_iid + 1:
                        created = gitlab_project.create_issue({'title': 'fake'}, fake_meta, gitlab.get_auth_headers())
                        last_iid = created['iid']
                        gitlab_project.delete_issue(created['iid'])
                        log.info('#{iid} {title}'.format(**created))
                except:
                    log.info('create issue "{}" failed'.format('fake'))
                    raise
            try:
                created = gitlab_project.create_issue(data, meta, gitlab.get_auth_headers())
                last_iid = created['iid']
                log.info('#{iid} {title}'.format(**created))
            except:
                log.info('create issue "{}" failed'.format(data['title']))
                raise
Exemple #4
0
def perform_migrate_issues(args):
    closed_states = []
    if (args.closed_states):
        closed_states = args.closed_states.split(',')

    custom_fields = []
    if (args.custom_fields):
        custom_fields = args.custom_fields.split(',')

    if (args.user_dict is not None):
        load_user_dict(args.user_dict)

    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()

    if (args.project_members_only):
        gitlab_users_index = gitlab_project.get_members_index()
    else:
        gitlab_users_index = gitlab_instance.get_users_index()

    redmine_users_index = redmine_project.get_users_index(args.issue_ids)
    milestones_index = gitlab_project.get_milestones_index()
    if args.no_textile:
        textile_converter = NopConverter()
    else:
        textile_converter = TextileConverter()

    log.debug('GitLab milestones are: {}'.format(', '.join(milestones_index) +
                                                 ' '))

    # get issues
    log.info('Getting redmine issues')
    issues = redmine_project.get_issues(args.issue_ids)
    if args.initial_id:
        issues = [
            issue for issue in issues if int(args.initial_id) <= issue['id']
        ]

    # convert issues
    log.info('Converting issues')
    issues_data = (convert_issue(args.redmine_key, i, redmine_users_index,
                                 gitlab_users_index, milestones_index,
                                 closed_states, custom_fields,
                                 textile_converter, args.keep_id
                                 or args.keep_title, args.sudo)
                   for i in issues)

    # create issues
    log.info('Creating gitlab issues')
    last_iid = int(args.initial_id or 1) - 1
    for data, meta, redmine_id in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'], len(meta['notes'])))

        else:
            if args.keep_id:
                data['iid'] = redmine_id

            try:
                created = gitlab_project.create_issue(data, meta)
                last_iid = created['iid']
                log.info('#{iid} {title}'.format(**created))
            except:
                log.info('create issue "{}" failed'.format(data['title']))
                raise
Exemple #5
0
def perform_migrate_issues(args):
    init_db()

    closed_states = []
    if (args.closed_states):
        closed_states = args.closed_states.split(',')

    custom_fields = []
    if (args.custom_fields):
        custom_fields = args.custom_fields.split(',')

    if (args.user_dict is not None):
        load_user_dict(args.user_dict)

    if (args.user_keys is not None):
        load_user_keys(args.user_keys)

    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()

    if (args.project_members_only):
        gitlab_users_index = gitlab_project.get_members_index()
    else:
        gitlab_users_index = gitlab_instance.get_users_index()

    redmine_users_index = redmine_project.get_users_index()
    milestones_index = gitlab_project.get_milestones_index()
    textile_converter = TextileConverter()

    log.debug('GitLab milestones are: {}'.format(', '.join(milestones_index) +
                                                 ' '))

    # get issues
    log.info('Getting redmine issues')
    issues = redmine_project.get_all_issues()
    if args.initial_id:
        issues = [
            issue for issue in issues if int(args.initial_id) <= issue['id']
        ]
    if args.max_id:
        issues = [issue for issue in issues if int(args.max_id) >= issue['id']]

    # convert issues
    log.info('Converting issues')
    issues_data = (convert_issue(args.redmine_key, i, redmine_users_index,
                                 gitlab_users_index, milestones_index,
                                 closed_states, custom_fields,
                                 textile_converter, args.keep_id
                                 or args.keep_title, args.sudo)
                   for i in issues)

    # create issues
    log.info('Creating gitlab issues')
    last_iid = int(args.initial_id or 1) - 1
    for data, meta, redmine_id in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'], len(meta['notes'])))

            log.info('Labels %s' % meta.get('labels', []))
            log.info('Tags %s' % meta.get('tags', []))
            log.info('Watchers %s' % meta.get('watchers', []))

        else:
            if args.keep_id:
                try:
                    fake_meta = {
                        'uploads': [],
                        'notes': [],
                        'must_close': False
                    }
                    if args.sudo:
                        fake_meta['sudo_user'] = meta['sudo_user']
                    while redmine_id > last_iid + 1:
                        created = gitlab_project.create_issue(
                            {'title': 'fake'}, fake_meta)
                        last_iid = created['iid']
                        gitlab_project.delete_issue(created['id'])
                        log.info('#{iid} {title}'.format(**created))
                except:
                    log.info('create issue "{}" failed'.format('fake'))
                    raise

            try:
                # labels
                for label in meta.get('labels', []):
                    gitlab_project.create_label(label)

                # tags
                for tag in meta.get('tags', []):
                    gitlab_project.create_label(tag)

                # issue
                created = gitlab_project.create_issue(data, meta)
                last_iid = created['iid']

                # watchers
                for watcher in meta.get('watchers', []):
                    created_watcher = gitlab_project.create_watcher(
                        watcher.get('data', {}), watcher, created['iid'])

                log.info('#{iid} {title}'.format(**created))
            except:
                log.info('create issue "{}" failed'.format(data['title']))
                raise
def perform_migrate_issues(args):
    closed_states = []
    if (args.closed_states):
        closed_states = args.closed_states.split(',')

    custom_fields = []
    if (args.custom_fields):
        custom_fields = args.custom_fields.split(',')

    if (args.user_dict is not None):
        load_user_dict(args.user_dict)

    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    gitlab_instance = gitlab_project.get_instance()

    if (args.project_members_only):
        gitlab_users_index = gitlab_project.get_members_index()
    else:
        gitlab_users_index = gitlab_instance.get_users_index()

    redmine_users_index = redmine_project.get_users_index()
    milestones_index = gitlab_project.get_milestones_index()
    textile_converter = TextileConverter()

    log.debug('GitLab milestones are: {}'.format(', '.join(milestones_index) + ' '))

    # get issues
    log.info('Getting redmine issues')
    issues = redmine_project.get_all_issues()
    if args.initial_id:
        issues = [issue for issue in issues if int(args.initial_id) <= issue['id']]

    # convert issues
    log.info('Converting issues')
    issues_data = (
        convert_issue(args.redmine_key,
            i, redmine_users_index, gitlab_users_index, milestones_index, closed_states, custom_fields, textile_converter,
            args.keep_id or args.keep_title, args.sudo)
        for i in issues)

    # create issues
    log.info('Creating gitlab issues')
    last_iid = int(args.initial_id or 1) - 1
    for data, meta, redmine_id in issues_data:
        if args.check:
            milestone_id = data.get('milestone_id', None)
            if milestone_id:
                try:
                    gitlab_project.get_milestone_by_id(milestone_id)
                except ValueError:
                    raise CommandError(
                        "issue \"{}\" points to unknown milestone_id \"{}\". "
                        "Check that you already migrated roadmaps".format(
                            data['title'], milestone_id))

            log.info('Would create issue "{}" and {} notes.'.format(
                data['title'],
                len(meta['notes'])))

        else:
            if args.keep_id:
                try:
                    fake_meta = {'uploads': [], 'notes': [], 'must_close': False}
                    if args.sudo:
                        fake_meta['sudo_user'] = meta['sudo_user']
                    while redmine_id > last_iid + 1:
                        created = gitlab_project.create_issue({'title': 'fake'}, fake_meta)
                        last_iid = created['iid']
                        gitlab_project.delete_issue(created['iid'])
                        log.info('#{iid} {title}'.format(**created))
                except:
                    log.info('create issue "{}" failed'.format('fake'))
                    raise

            try:
                created = gitlab_project.create_issue(data, meta)
                last_iid = created['iid']
                log.info('#{iid} {title}'.format(**created))
            except:
                log.info('create issue "{}" failed'.format(data['title']))
                raise