示例#1
0
def perform_redirect(args):
    redmine = RedmineClient(args.redmine_key, args.no_verify)
    redmine_project = RedmineProject(args.redmine_project_url, redmine)

    # get issues
    redmine_issues = redmine_project.get_issues(args.issue_ids)

    print('# uncomment next line to enable RewriteEngine')
    print('# RewriteEngine On')
    print('# Redirects from {} to {}'.format(args.redmine_project_url, args.gitlab_project_url))

    for issue in redmine_issues:
        print('RedirectMatch 301 ^/issues/{}$ {}/issues/{}'.format(issue['id'], args.gitlab_project_url, issue['id']))
示例#2
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