逐个解析.code.yml文件,获取代码目录/文件对应的负责人信息 :param file_dir_map: :param source_dir :return:
(self, yaml_files, source_dir)
| 35 | |
| 36 | class FileOwner(object): |
| 37 | def __get_file_owners(self, yaml_files, source_dir): |
| 38 | """ |
| 39 | 逐个解析.code.yml文件,获取代码目录/文件对应的负责人信息 |
| 40 | :param file_dir_map: |
| 41 | :param source_dir |
| 42 | :return: |
| 43 | """ |
| 44 | relpos = len(source_dir) + 1 |
| 45 | file_owners = [] |
| 46 | for item in yaml_files: |
| 47 | yaml_path, dir_path = item["yaml_path"], item["dir_path"] |
| 48 | try: |
| 49 | file_info_list = YamlReader().read_section(yaml_path, "file") |
| 50 | |
| 51 | logger.info("file_owners(%s): %s" % (yaml_path, json.dumps(file_info_list, indent=2))) |
| 52 | if file_info_list: |
| 53 | for info in file_info_list: |
| 54 | path = info["path"] |
| 55 | |
| 56 | if path.startswith("/"): # 基于项目根目录的相对路径 |
| 57 | rel_path = path[1:] |
| 58 | else: # 基于.code.yml文件所在目录的相对路径 |
| 59 | if path.startswith("./"): |
| 60 | path = path[2:] |
| 61 | full_path = "%s/%s" % (dir_path, path) |
| 62 | rel_path = full_path[relpos:] |
| 63 | |
| 64 | # 如果路径包含.*字符,说明是正则表达式,先实例化正则,提高匹配效率 |
| 65 | if ".*" in rel_path: |
| 66 | try: |
| 67 | regex_object = re.compile(rel_path) |
| 68 | except Exception as err: |
| 69 | err_msg = "yaml file owner path(%s) format is wrong, skip: %s" % (rel_path, str(err)) |
| 70 | logger.error(err_msg) |
| 71 | regex_object = None |
| 72 | else: |
| 73 | regex_object = None |
| 74 | file_owners.append( |
| 75 | {"rel_path": rel_path, "regex_object": regex_object, "owners": info["owners"]} |
| 76 | ) |
| 77 | except: |
| 78 | logger.exception("encounter Error when analyze %s" % yaml_path) |
| 79 | return file_owners |
| 80 | |
| 81 | def __find_owners(self, format_path, file_owners_list): |
| 82 | """ |
no test coverage detected