def test_closed_issue(self): redmine_issue = REDMINE_ISSUE_1732 gitlab_issue, meta = convert_issue(redmine_issue, self.redmine_user_index, self.gitlab_users_idx, {}) self.assertEqual( gitlab_issue, { 'title': '-RM-1732-MR-Update doc for v1', 'description': 'The doc is a bit old\n\n*(from redmine: created on 2015-08-21, closed on 2015-09-09)*', 'labels': ['Evolution'], 'assignee_id': JOHN['id'], }) self.assertEqual( meta, { 'sudo_user': JACK['username'], 'notes': [({ 'body': 'Appliqué par commit ' 'commit:66cbf9571ed501c6d38a5978f8a27e7b1aa35268.' '\n\n*(from redmine: written on 2015-09-09)*' }, { 'sudo_user': '******' }) # empty notes should not be kept ], 'must_close': True })
def test_open_issue(self): redmine_api_key = '<redmine_api_key>' redmine_issue = REDMINE_ISSUE_1439 milestone_index = {'v0.11': {'id': 3, 'title': 'v0.11'}} gitlab_issue, meta = convert_issue(redmine_api_key, redmine_issue, self.redmine_user_index, self.gitlab_users_idx, milestone_index, ['closed', 'rejected'], ['customer']) self.assertEqual( gitlab_issue, { 'title': '-RM-1439-MR-Support SSL', 'description': '\n\n*(from redmine: created on 2015-04-03)*\n\n* Relations:\n * relates #1430', 'labels': ['Evolution'], 'milestone_id': 3, }) self.assertEqual( meta, { 'sudo_user': JOHN['username'], 'notes': [], 'must_close': False, 'uploads': [] })
def test_closed_issue(self): redmine_api_key = '<redmine_api_key>' redmine_issue = REDMINE_ISSUE_1732 textile_converter = TextileConverter() gitlab_issue, meta, redmine_id = convert_issue( redmine_api_key, redmine_issue, self.redmine_user_index, self.gitlab_users_idx, {}, ['closed', 'rejected'], ['customer'], textile_converter, False, True, None) self.assertEqual(gitlab_issue, { 'title': '-RM-1732-MR-Update doc for v1', 'created_at': '2015-08-21T13:29:41Z', 'description': 'The doc is a bit old\n\n\n*(from redmine: issue id 1732, created on 2015-08-21, closed on 2015-09-09)*\n', 'labels': 'Evolution,Fixed,Urgent', 'due_date': None, 'assignee_id': JOHN['id'], }) self.assertEqual(meta, { 'notes': [ ({'body': 'Appliqué par commit ' 'commit:66cbf9571ed501c6d38a5978f8a27e7b1aa35268.' '\n\n\n*(from redmine: written on 2015-09-09)*', 'created_at': '2015-09-09T13:31:16Z'}, {'sudo_user': '******'}) # empty notes should not be kept ], 'must_close': True, 'sudo_user': '******', 'uploads': [] })
def test_open_issue(self): redmine_api_key = '<redmine_api_key>' redmine_issue = REDMINE_ISSUE_1439 milestone_index = {'v0.11': {'id': 3, 'title': 'v0.11'}} textile_converter = TextileConverter() gitlab_issue, meta, redmine_id = convert_issue( redmine_api_key, redmine_issue, self.redmine_user_index, self.gitlab_users_idx, milestone_index, ['closed', 'rejected'], ['customer'], textile_converter, False, True) self.assertEqual( gitlab_issue, { 'title': '-RM-1439-MR-Support SSL', 'description': '\n\n\n*(from redmine: issue id 1439, created on 2015-04-03)*\n\n* Relations:\n * relates #1430', 'due_date': None, 'created_at': '2015-04-03T14:56:08Z', 'labels': 'Evolution,Nouveau,Normal', 'milestone_id': 3, }) self.assertEqual( meta, { 'sudo_user': JOHN['username'], 'notes': [], 'must_close': False, 'uploads': [] })
def test_closed_issue(self): redmine_api_key = '<redmine_api_key>' redmine_issue = REDMINE_ISSUE_1732 textile_converter = TextileConverter() gitlab_issue, meta, redmine_id = convert_issue( redmine_api_key, redmine_issue, self.redmine_user_index, self.gitlab_users_idx, {}, ['closed', 'rejected'], ['customer'], textile_converter, False, True) self.assertEqual(gitlab_issue, { 'title': '-RM-1732-MR-Update doc for v1', 'created_at': '2015-08-21T13:29:41Z', 'description': 'The doc is a bit old\n\n\n*(from redmine: issue id 1732, created on 2015-08-21, closed on 2015-09-09)*\n', 'labels': 'Evolution,Fixed,Urgent', 'due_date': None, 'assignee_id': JOHN['id'], }) self.assertEqual(meta, { 'notes': [ ({'body': 'Appliqué par commit ' 'commit:66cbf9571ed501c6d38a5978f8a27e7b1aa35268.' '\n\n\n*(from redmine: written on 2015-09-09)*', 'created_at': '2015-09-09T13:31:16Z'}, {'sudo_user': '******'}) # empty notes should not be kept ], 'must_close': True, 'sudo_user': '******', 'uploads': [] })
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
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 test_open_issue(self): redmine_issue = REDMINE_ISSUE_1439 milestone_index = {'v0.11': {'id': 3, 'title': 'v0.11'}} gitlab_issue, meta = convert_issue( redmine_issue, self.redmine_user_index, self.gitlab_users_idx, milestone_index) self.assertEqual(gitlab_issue, { 'title': '-RM-1439-MR-Support SSL', 'description': '\n\n*(from redmine: created on 2015-04-03, relates #1430)*', 'labels': ['Evolution'], 'milestone_id': 3, }) self.assertEqual(meta, { 'sudo_user': JOHN['username'], 'notes': [], 'must_close': False })
def test_open_issue(self): redmine_issue = REDMINE_ISSUE_1439 milestone_index = {'v0.11': {'id': 3, 'title': 'v0.11'}} gitlab_issue, meta = convert_issue(redmine_issue, self.redmine_user_index, self.gitlab_users_idx, milestone_index) self.assertEqual( gitlab_issue, { 'title': '-RM-1439-MR-Support SSL', 'description': '\n\n*(from redmine: created on 2015-04-03, relates #1430)*', 'labels': ['Evolution'], 'milestone_id': 3, }) self.assertEqual(meta, { 'sudo_user': JOHN['username'], 'notes': [], 'must_close': False })
def test_closed_issue(self): redmine_issue = REDMINE_ISSUE_1732 gitlab_issue, meta = convert_issue( redmine_issue, self.redmine_user_index, self.gitlab_users_idx, {}) self.assertEqual(gitlab_issue, { 'title': '-RM-1732-MR-Update doc for v1', 'description': 'The doc is a bit old\n\n*(from redmine: created on 2015-08-21, closed on 2015-09-09)*', 'labels': ['Evolution'], 'assignee_id': JOHN['id'], }) self.assertEqual(meta, { 'sudo_user': JACK['username'], 'notes': [ ({'body': 'Appliqué par commit ' 'commit:66cbf9571ed501c6d38a5978f8a27e7b1aa35268.' '\n\n*(from redmine: written on 2015-09-09)*'}, {'sudo_user': '******'}) # empty notes should not be kept ], 'must_close': True })
def test_open_issue(self): redmine_api_key = '<redmine_api_key>' redmine_issue = REDMINE_ISSUE_1439 milestone_index = {'v0.11': {'id': 3, 'title': 'v0.11'}} textile_converter = TextileConverter() gitlab_issue, meta, redmine_id = convert_issue( redmine_api_key, redmine_issue, self.redmine_user_index, self.gitlab_users_idx, milestone_index, ['closed', 'rejected'], ['customer'], textile_converter, False, True) self.assertEqual(gitlab_issue, { 'title': '-RM-1439-MR-Support SSL', 'description': '\n\n\n*(from redmine: issue id 1439, created on 2015-04-03)*\n\n* Relations:\n * relates #1430', 'due_date': None, 'created_at': '2015-04-03T14:56:08Z', 'labels': 'Evolution,Nouveau,Normal', 'milestone_id': 3, }) self.assertEqual(meta, { 'sudo_user': JOHN['username'], 'notes': [], 'must_close': False, 'uploads': [] })
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(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
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