From baafc4dba18724688af7d3096c1deda09097a6da Mon Sep 17 00:00:00 2001 From: tushenmei Date: Sun, 8 Aug 2021 23:22:39 +0800 Subject: [PATCH 1/2] issue operations --- .../application/modifypart/modifyentrance.py | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/release-assistant/javcra/application/modifypart/modifyentrance.py b/release-assistant/javcra/application/modifypart/modifyentrance.py index d5bbef3..06fb78f 100644 --- a/release-assistant/javcra/application/modifypart/modifyentrance.py +++ b/release-assistant/javcra/application/modifypart/modifyentrance.py @@ -591,3 +591,167 @@ class RemainIssue(Operation): body_str=body_str, issues=issues ) + + +class IssueOperation(Operation): + def __init__(self, repo, token, issue_num): + super().__init__(repo, token, issue_num) + args = (repo, token, issue_num) + self.bugfix_object = BugFixIssue(*args) + self.install_build_object = InstallBuildIssue(*args) + self.remain_object = RemainIssue(*args) + + def init_repo_table(self): + """ + init repo table + + return: + md table str + """ + block_name = "# 2、测试repo源" + table_head = ["repo_type", "architecture", "url"] + table_str = self.init_md_table(table_head) + return block_name + table_str + + def create_install_build_issue(self, failed_type, pkg_name): + """ + create issue when install failed or build failed + + Args: + failed_type: install failed or build failed + pkg_name: package name + + return: + issue_id + """ + branch = self.get_update_issue_branch() + if not branch: + logger.error("failed to create install build issue because the release issue branch not found.") + return None + + params = { + "repo": pkg_name, + "owner": self.owner, + "access_token": self.token, + "title": "[{brh}] {pkg} {verify_type} failed".format(pkg=pkg_name, verify_type=failed_type, brh=branch) + } + + command = "" + if failed_type == "build": + command = "rpmbuild --rebuild" + if failed_type == "install": + command = "yum install" + + params["body"] = """Branch: {brh} + Component: {pkg} + Instructions to reappear the problem : {command} + Expected results: successfully {_type} + Actual results: failed to {_type}""".format(brh=branch, pkg=pkg_name, command=command, + _type=failed_type) + issue_id = self.create_issue(params) + return issue_id + + def get_update_version_info(self): + """ + Get update target and personnel information + + Returns: + update version info + """ + issue_body = self.get_issue_body(self.issue_num) + if issue_body: + if re.compile("1、CVE.*?\\n\\n", re.S).search(issue_body): + logger.error("Issue has CVE content, maybe you already have operated start update command.") + return None + if not issue_body.endswith("\n"): + issue_body += "\n" + return issue_body + return None + + def init_issue_description(self): + """ + initialize the release issue body when commenting "start-update" command + + Returns: + True or False + """ + update_info = self.get_update_version_info() + if not update_info: + return + + release_range = "# 1、发布范围\n" + bugfix_block_str = self.bugfix_object.init() + repo_block_str = self.init_repo_table() + install_build_block_str = self.install_build_object.init() + remain_block_str = self.remain_object.init() + + body_str = ( + update_info + + release_range + + bugfix_block_str + + repo_block_str + + install_build_block_str + + remain_block_str + ) + + return True if self.update_issue(body=body_str) else False + + def update_issue_description(self, operate, update_block, issues=None): + """ + to update issue description + + Args: + operate: {init,add,delete}. + update_block: block name, like cve or bugfix, + issues: issue list. + + returns: + True or False + """ + if not issues: + issues = [] + + old_body_str = self.get_issue_body(self.issue_num) + if not old_body_str: + logger.error("The current issue has no content, please start first.") + return False + + # get the block object, like cve block object, and then call "get_new_issue_body" for this block + operate_object = getattr(self, update_block + "_object") + body_str = operate_object.get_new_issue_body( + operate=operate, body_str=old_body_str, issues=issues) + + if not body_str: + logger.error("after update issue description, got empty new release issue body.") + return False + + return True if self.update_issue(body=body_str) else False + + def operate_release_issue(self, operation="init", operate_block=None, issues=None): + """ + modify entrance of the release issue + + Args: + operation: {init,add,delete} + operate_block: block to operate + when the operation is "init", operate_block=None + issues: issue list + + Returns: + True or False + """ + valid_operations = ["init", "add", "delete"] + if not operation or operation not in valid_operations: + logger.error("must given operation in ['init','add','delete']") + return False + + try: + if operation == "init": + return self.init_issue_description() + else: + return self.update_issue_description( + operate=operation, update_block=operate_block, issues=issues + ) + except ValueError as e: + logger.error(e) + return False -- Gitee From 877e40a660178baf9d80f75dfc11151fa46f5b7f Mon Sep 17 00:00:00 2001 From: tushenmei Date: Mon, 9 Aug 2021 10:22:14 +0800 Subject: [PATCH 2/2] add docstring1 --- .../javcra/application/modifypart/modifyentrance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release-assistant/javcra/application/modifypart/modifyentrance.py b/release-assistant/javcra/application/modifypart/modifyentrance.py index 06fb78f..cf2248d 100644 --- a/release-assistant/javcra/application/modifypart/modifyentrance.py +++ b/release-assistant/javcra/application/modifypart/modifyentrance.py @@ -677,7 +677,7 @@ class IssueOperation(Operation): """ update_info = self.get_update_version_info() if not update_info: - return + return False release_range = "# 1、发布范围\n" bugfix_block_str = self.bugfix_object.init() @@ -701,7 +701,7 @@ class IssueOperation(Operation): to update issue description Args: - operate: {init,add,delete}. + operate: operate in {add,delete}. update_block: block name, like cve or bugfix, issues: issue list. -- Gitee