diff --git a/release-assistant/javcra/application/modifypart/modifyentrance.py b/release-assistant/javcra/application/modifypart/modifyentrance.py index 7d4321a7f718f66067cd8f3de34885611ae80558..c4d62ff2718e7260cc0f4917f300dc8822fc9273 100644 --- a/release-assistant/javcra/application/modifypart/modifyentrance.py +++ b/release-assistant/javcra/application/modifypart/modifyentrance.py @@ -11,56 +11,100 @@ # See the Mulan PSL v2 for more details. # ******************************************************************************/ """ -Description: modify commands entrance -Class: ModifyEntrance +Description: modify entrance """ +import copy +import re -class ModifyEntrance(): - """ - Description: distributing different modify commands to correct methods - Attributes: - """ - def __init__(self, issue_id, issue_list): - """ - Description: Instance initialization - """ - pass - def modify_cve_list(self, action): +class Operation: + + def init_md_table(self, t_head=None, t_body=None, block_title="", prefix="", suffix=""): """ - Description: add or delete cve issue list - Args: + initialize the md table of specific part like "CVE part" for release issue - Returns: + Args: + t_head: table head. e.g.["CVE", "仓库", "status"] + t_body: table body + block_title: title of block. e.g.: "## 1.CVE" + prefix: table prefix. e.g.: "修复cve xx 个" + suffix: characters between the end of the table and the next block. Raises: + ValueError: The thead must be a list or tuple + Returns: + str: markdown table str """ - print("add/delete cve checklist!") - pass + if not t_head: + t_head = [] + + if not isinstance(t_head, (list, tuple)): + raise ValueError("The thead must be a list or tuple.") + + thead_str = "|" + "|".join(t_head) + "|\n" + "|-" * len(t_head) + "|\n" + tbody_str = self.convert_md_table_format(t_head, t_body) + table_str = thead_str + tbody_str - def modify_bugfix_list(self, action): + if prefix: + table_str = prefix + "\n" + table_str + return "\n".join([block_title, table_str, suffix]) + + @staticmethod + def convert_md_table_format(table_head, issue_info): """ - Description: add or delete bugfix issue list + get markdown table body according to table_head and issue_info + Args: + table_head: table head like ["issue","status",...] + issue_info: issue info like [{"issue":...,"status":...},....] Returns: + markdown table str + """ + table_body_str = "" + for info in issue_info: + table_body_str += "|" + for word in table_head: + table_body_str += str(info.get(word)) + "|" - Raises: + table_body_str += "\n" + return table_body_str + @staticmethod + def __get_block_lines(issue_body_lines, start_flag, end_flag): """ - print("add/delete bugix checklist!") - pass + get block lines of specific part from issue body lines - def modify_release_result(self, action): - """ - Description: add or delete final release issue list Args: + issue_body_lines: the lines of issue body + start_flag: start flag of specific part, like ""## 1、CVE"" + end_flag: end flag of specific part, like "\n" - Returns: - - Raises: + Returns: block_lines: lines in specific part like "cve part" + block_start_idx: start index of specific part + block_end_idx: end index of specific part """ - print("modify final release list!") - pass \ No newline at end of file + block_lines = [] + block_start_idx = 0 + block_end_idx = 0 + flag = 0 + + # get block lines + for idx, line in enumerate(issue_body_lines): + if line.startswith(start_flag): + # represents the start of block + flag = 1 + block_start_idx = idx + block_lines.append(line) + continue + + if flag and line == end_flag: + block_end_idx = idx + break + + if flag: + block_lines.append(line) + + return block_lines, block_start_idx, block_end_idx