def _create_field(self, field_name, field_type, attach_bundle_policy, auto_attached=True): if field_name in youtrack.EXISTING_FIELDS: return create_custom_field(self._target, field_type, field_name, auto_attached, bundle_policy=attach_bundle_policy)
def bugzilla2youtrack(target_url, target_login, target_pass, bz_db, bz_host, bz_port, bz_login, bz_pass, bz_product_names, issues_filter): # connecting to bz client = Client(bz_host, int(bz_port), bz_login, bz_pass, db_name=bz_db) if not len(bz_product_names): answer = raw_input("All projects will be imported. Are you sure? [y/n]") if answer.capitalize() != "Y": sys.exit() bz_product_names = client.get_product_names() print("bz_product_names : " + repr(bz_product_names)) # connecting to yt target = Connection(target_url, target_login, target_pass) print("Creating issue link types") link_types = client.get_issue_link_types() for link in link_types: print("Processing link type [ %s ]" % link.name) try: target.createIssueLinkType(to_yt_issue_link_type(link)) except YouTrackException: print("Can't create link type [ %s ] (maybe because it already exists)" % link.name) print("Creating issue link types finished") print("Creating custom fields") custom_fields = client.get_custom_fields() for cf in custom_fields: create_yt_custom_field(cf, target) print("Creating custom fields finished") for key in youtrackutils.bugzilla.FIELD_TYPES: if key not in youtrack.EXISTING_FIELDS: create_custom_field(target, youtrackutils.bugzilla.FIELD_TYPES[key], key, True, bundle_policy="1") bz_product_ids = [] for name in bz_product_names: product_id = str(client.get_product_id_by_name(name)) bz_product_ids.append(product_id) print("Creating project [ %s ] with name [ %s ]" % (product_id, name)) try: target.getProject(str(product_id)) except YouTrackException: target.createProjectDetailed(str(product_id), name, client.get_project_description(product_id), target_login) print("Importing components for project [ %s ]" % product_id) process_components(client.get_components(product_id), product_id, target) print("Importing components finished for project [ %s ]" % product_id) print("Importing versions for project [ %s ]" % product_id) process_versions(client.get_versions(product_id), product_id, target) print("Importing versions finished for project [ %s ] finished" % product_id) print("Importing issues to project [ %s ]" % product_id) max_count = 100 count = 0 from_id = 0 bz_issues_count = client.get_issues_count(product_id) while count < bz_issues_count: batch = client.get_issues(product_id, from_id, from_id + max_count) batch = [bz_issue for bz_issue in batch if (issues_filter(bz_issue))] count += len(batch) from_id += max_count target.importIssues(product_id, product_id + " assignees", [to_yt_issue(bz_issue, product_id, target) for bz_issue in batch]) # todo convert to good tags import for issue in batch: tags = issue["keywords"] | issue["flags"] for t in tags: print("Processing tag [ %s ]" % t.encode('utf8')) target.executeCommand(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]), "tag " + t.encode('utf8')) for issue in batch: for attach in issue["attachments"]: print("Processing attachment [ %s ]" % (attach.name.encode('utf8'))) content = StringIO(attach.content) target.createAttachment(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]), attach.name, content, attach.reporter.login , created=str(int(attach.created) * 1000)) print("Importing issues to project [ %s ] finished" % product_id) # todo add pagination to links print("Importing issue links") cf_links = client.get_issue_links() duplicate_links = client.get_duplicate_links() if len(duplicate_links): try: target.createIssueLinkTypeDetailed("Duplicate", "duplicates", "is duplicated by", True) except YouTrackException: print("Can't create link type [ Duplicate ] (maybe because it already exists)") depend_links = client.get_dependencies_link() if len(depend_links): try: target.createIssueLinkTypeDetailed("Depend", "depends on", "is required for", True) except YouTrackException: print("Can't create link type [ Depend ] (maybe because it already exists)") links = cf_links | duplicate_links | depend_links links_to_import = list([]) for link in links: print("Processing link %s for issue%s" % (link.name, link.source)) if (str(link.target_product_id) in bz_product_ids) and (str(link.source_product_id) in bz_product_ids): links_to_import.append(to_yt_issue_link(link)) print(target.importLinks(links_to_import)) print("Importing issue links finished")
def create_yt_custom_field(cf, target): cf_name = get_name_for_new_cf(cf.name) cf_type = youtrackutils.bugzilla.CF_TYPES[cf.type] if cf_name in youtrackutils.bugzilla.FIELD_TYPES: cf_type = youtrackutils.bugzilla.FIELD_TYPES[cf_name] create_custom_field(target, cf_type, cf_name, True)
def bugzilla2youtrack(target_url, target_login, target_pass, bz_db, bz_host, bz_port, bz_login, bz_pass, bz_product_names, issues_filter): # connecting to bz client = Client(bz_host, int(bz_port), bz_login, bz_pass, db_name=bz_db) if not len(bz_product_names): answer = raw_input("All projects will be imported. Are you sure? [y/n]") if answer.capitalize() != "Y": sys.exit() bz_product_names = client.get_product_names() print "bz_product_names : " + repr(bz_product_names) # connecting to yt target = Connection(target_url, target_login, target_pass) print "Creating issue link types" link_types = client.get_issue_link_types() for link in link_types: print "Processing link type [ %s ]" % link.name try: target.createIssueLinkType(to_yt_issue_link_type(link)) except YouTrackException: print "Can't create link type [ %s ] (maybe because it already exists)" % link.name print "Creating issue link types finished" print "Creating custom fields" custom_fields = client.get_custom_fields() for cf in custom_fields: create_yt_custom_field(cf, target) print "Creating custom fields finished" for key in bugzilla.FIELD_TYPES: if key not in youtrack.EXISTING_FIELDS: create_custom_field(target, bugzilla.FIELD_TYPES[key], key, True, bundle_policy="1") bz_product_ids = [] for name in bz_product_names: product_id = str(client.get_product_id_by_name(name)) bz_product_ids.append(product_id) print "Creating project [ %s ] with name [ %s ]" % (product_id, name) try: target.getProject(str(product_id)) except YouTrackException: target.createProjectDetailed(str(product_id), name, client.get_project_description(product_id), target_login) print "Importing components for project [ %s ]" % product_id process_components(client.get_components(product_id), product_id, target) print "Importing components finished for project [ %s ]" % product_id print "Importing versions for project [ %s ]" % product_id process_versions(client.get_versions(product_id), product_id, target) print "Importing versions finished for project [ %s ] finished" % product_id print "Importing issues to project [ %s ]" % product_id max_count = 100 count = 0 from_id = 0 bz_issues_count = client.get_issues_count(product_id) while count < bz_issues_count: batch = client.get_issues(product_id, from_id, from_id + max_count) batch = [bz_issue for bz_issue in batch if (issues_filter(bz_issue))] count += len(batch) from_id += max_count target.importIssues(product_id, product_id + " assignees", [to_yt_issue(bz_issue, product_id, target) for bz_issue in batch]) # todo convert to good tags import for issue in batch: tags = issue["keywords"] | issue["flags"] for t in tags: print "Processing tag [ %s ]" % t.encode('utf8') target.executeCommand(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]), "tag " + t.encode('utf8')) for issue in batch: for attach in issue["attachments"]: print "Processing attachment [ %s ]" % (attach.name.encode('utf8')) content = StringIO(attach.content) target.createAttachment(str(product_id) + "-" + str(issue[get_number_in_project_field_name()]), attach.name, content, attach.reporter , created=str(int(attach.created) * 1000)) print "Importing issues to project [ %s ] finished" % product_id # todo add pagination to links print "Importing issue links" cf_links = client.get_issue_links() duplicate_links = client.get_duplicate_links() if len(duplicate_links): try: target.createIssueLinkTypeDetailed("Duplicate", "duplicates", "is duplicated by", True) except YouTrackException: print "Can't create link type [ Duplicate ] (maybe because it already exists)" depend_links = client.get_dependencies_link() if len(depend_links): try: target.createIssueLinkTypeDetailed("Depend", "depends on", "is required for", True) except YouTrackException: print "Can't create link type [ Depend ] (maybe because it already exists)" links = cf_links | duplicate_links | depend_links links_to_import = list([]) for link in links: print "Processing link %s for issue%s" % (link.name, link.source) if (str(link.target_product_id) in bz_product_ids) and (str(link.source_product_id) in bz_product_ids): links_to_import.append(to_yt_issue_link(link)) print target.importLinks(links_to_import) print "Importing issue links finished"
def create_yt_custom_field(cf, target): cf_name = get_name_for_new_cf(cf.name) cf_type = bugzilla.CF_TYPES[cf.type] if cf_name in bugzilla.FIELD_TYPES: cf_type = bugzilla.FIELD_TYPES[cf_name] create_custom_field(target, cf_type, cf_name, True)
def bugzilla2youtrack(params): # Connecting to Bugzilla client = Client(host=params['bz_host'], port=int(params['bz_port']), login=params['bz_login'], password=params['bz_password'], db_name=params['bz_db']) bz_product_names = params.get('bz_product_names') if not bz_product_names: answer = raw_input( "All projects will be imported. Are you sure? [Y/n] ") if answer.strip().lower() not in ("y", "yes", ""): sys.exit() bz_product_names = client.get_product_names() print("bz_product_names: " + repr(bz_product_names)) # Connecting to YouTrack token = params.get('token') if not token and 'token_file' in params: try: with open(params['token_file'], 'r') as f: token = f.read().strip() except (OSError, IOError) as e: print("Cannot load token from file: " + str(e)) sys.exit(1) if token: target = Connection(params['yt_url'], token=token) elif 'yt_login' in params: target = Connection(params['yt_url'], params.get('yt_login'), params.get('yt_password')) else: print("You have to provide token or login/password to import data") sys.exit(1) print("Creating issue link types") link_types = client.get_issue_link_types() for link in link_types: print("Processing link type [ %s ]" % link.name) try: target.createIssueLinkType(to_yt_issue_link_type(link)) except YouTrackException: print( "Can't create link type [ %s ] (maybe because it already exists)" % link.name) print("Creating issue link types finished") print("Creating custom fields") custom_fields = client.get_custom_fields() for cf in custom_fields: create_yt_custom_field(cf, target) print("Creating custom fields finished") for key in youtrackutils.bugzilla.FIELD_TYPES: if key not in youtrack.EXISTING_FIELDS: create_custom_field(target, youtrackutils.bugzilla.FIELD_TYPES[key], key, True, bundle_policy="1") bz_product_ids = [] for name in bz_product_names: product_id = str(client.get_product_id_by_name(name)) bz_product_ids.append(product_id) print("Creating project [ %s ] with name [ %s ]" % (product_id, name)) try: target.getProject(product_id) except YouTrackException: target.createProjectDetailed( product_id, name, client.get_project_description(product_id), 'root') print("Importing components for project [ %s ]" % product_id) process_components(client.get_components(product_id), product_id, target) print("Importing components finished for project [ %s ]" % product_id) print("Importing versions for project [ %s ]" % product_id) process_versions(client.get_versions(product_id), product_id, target) print("Importing versions finished for project [ %s ] finished" % product_id) print("Importing issues to project [ %s ]" % product_id) max_count = 100 count = 0 from_id = 0 bz_issues_count = client.get_issues_count(product_id) while count < bz_issues_count: batch = client.get_issues(product_id, from_id, from_id + max_count) batch = [bz_issue for bz_issue in batch] count += len(batch) from_id += max_count target.importIssues(product_id, product_id + " assignees", [ to_yt_issue(bz_issue, product_id, target) for bz_issue in batch ]) # todo convert to good tags import for issue in batch: tags = issue["keywords"] | issue["flags"] for t in tags: print("Processing tag [ %s ]" % t.encode('utf8')) target.executeCommand( str(product_id) + "-" + str(issue[get_number_in_project_field_name()]), "tag " + t.encode('utf8')) for issue in batch: issue_id = str(product_id) + '-' + \ str(issue[get_number_in_project_field_name()]) for attach in issue["attachments"]: print("Processing attachment [ %s ] for issue %s" % (utf8encode(attach.name), issue_id)) content = StringIO(attach.content) try: target.importAttachment( issue_id, attach.name, content, attach.reporter.login, None, None, str(int(attach.created) * 1000)) except urllib2.HTTPError as e: print("WARN: Cant import attachment [ %s ]" % utf8encode(attach.name)) print(e.code) print(e.read()) print("Please check Max Upload File Size in YouTrack") continue print("Importing issues to project [ %s ] finished" % product_id) # todo add pagination to links print("Importing issue links") cf_links = client.get_issue_links() duplicate_links = client.get_duplicate_links() if len(duplicate_links): try: target.createIssueLinkTypeDetailed("Duplicate", "duplicates", "is duplicated by", True) except YouTrackException: print( "Can't create link type [ Duplicate ] (maybe because it already exists)" ) depend_links = client.get_dependencies_link() if len(depend_links): try: target.createIssueLinkTypeDetailed("Depend", "depends on", "is required for", True) except YouTrackException: print( "Can't create link type [ Depend ] (maybe because it already exists)" ) links = cf_links | duplicate_links | depend_links links_to_import = list([]) for link in links: print("Processing link %s for issue%s" % (link.name, link.source)) if (str(link.target_product_id) in bz_product_ids) and (str( link.source_product_id) in bz_product_ids): links_to_import.append(to_yt_issue_link(link)) print(target.importLinks(links_to_import)) print("Importing issue links finished")
def import_custom_fields(field_names, target): for name in field_names: yt_name = get_yt_field_name(name) yt_type = get_yt_field_type(yt_name) if (yt_type is not None) and (yt_name not in youtrack.EXISTING_FIELDS): create_custom_field(target, yt_type, yt_name, True)