def perform_delete_issues(args): """ Delete all issues in the gitlab repo """ gitlab = GitlabClient(args.gitlab_key, args.no_verify) gitlab_project = GitlabProject(args.gitlab_project_url, gitlab) gitlab_issues = gitlab_project.get_issues() log.debug('Got {} issue(s) from gitlab.'.format(len(gitlab_issues))) for issue in gitlab_issues: log.debug('delete issue {}'.format(issue['id'])) gitlab_project.delete_issue(issue['iid'])
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']] 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
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