From 0df8ab7d7a73b40ca9d1795ce8a92f89030946b6 Mon Sep 17 00:00:00 2001 From: e Date: Mon, 11 Oct 2021 16:02:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E6=96=87=E4=BB=B6=E5=88=9B=E5=BB=BAis?= =?UTF-8?q?sue=E6=BA=90=E4=BA=8Ejenkins=E7=BC=96=E8=AF=91=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=9A=84=E8=AF=84=E8=AE=BA=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?verify=5Fstart=5Fupdate=E5=87=BD=E6=95=B0=E9=AA=8C=E8=AF=81issu?= =?UTF-8?q?e=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-assistant/javcra/api/gitee_comment.py | 81 +++++++++++++++++++ .../javcra/application/checkpart/checktest.py | 16 ++++ .../javcra/cli/commands/__init__.py | 11 ++- release-assistant/javcra/common/constant.py | 1 + 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 release-assistant/javcra/api/gitee_comment.py diff --git a/release-assistant/javcra/api/gitee_comment.py b/release-assistant/javcra/api/gitee_comment.py new file mode 100644 index 0000000..cd78631 --- /dev/null +++ b/release-assistant/javcra/api/gitee_comment.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3 +# ****************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# ******************************************************************************/ +""" +add a comment for the address of jenkins in the comment section of issue +""" +import sys +import os +import argparse +from datetime import datetime + +ABSPATH = os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(os.path.dirname(__file__))))) +sys.path.insert(0, ABSPATH) +from javcra.application.modifypart.modifyentrance import IssueOperation +from javcra.api.jenkins_api import JenkinsJob +from javcra.common.constant import GITEE_REPO, JENKINS_BASE_URL, LTS_BRANCH, MAX_PARAL_NUM +from javcra.libs.log import logger + + +class Comment(IssueOperation, JenkinsJob): + """ + add a comment for the address of jenkins in the comment section of issue + """ + + def __init__(self, repo, token, issue_num, base_url, jenkins_user, jenkins_password, now_time): + IssueOperation.__init__(self, repo, token, issue_num) + JenkinsJob.__init__(self, base_url, jenkins_user, jenkins_password, MAX_PARAL_NUM, LTS_BRANCH, now_time) + + def create_comment(self, jenkins_job_name, jenkins_build_id): + """ + add a comment for the address of jenkins in the comment section of issue + Args: + jenkins_job_name: jenkins job name + jenkins_build_id: jenkins build id + + Returns: + comment_res: comment response + """ + output_hyperlink = self.get_output_hyperlink(jenkins_job_name, jenkins_build_id) + if not output_hyperlink: + logger.error("Error in getting the output url of %s." % jenkins_job_name) + return False + table_top = ["job_name", "output"] + comment_body = [ + { + "job_name": jenkins_job_name, + "output": output_hyperlink + } + ] + comment_content = self.init_md_table(table_top, comment_body) + comment_res = self.create_issue_comment(comment_content) + if not comment_res: + logger.error("Failed to create Jenkins' comment message %s" % comment_res) + return False + return True + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="create gitee comments") + parser.add_argument("--token", required=True, type=str, help="gitee tonken") + parser.add_argument("--issue_num", required=True, type=str, help="gitee number") + parser.add_argument("--jenkins_user", required=True, type=str, help="jenkins user") + parser.add_argument("--jenkins_password", required=True, type=str, help="jenkins password") + parser.add_argument("--jenkins_job_name", required=True, type=str, help="jenkins job name") + parser.add_argument("--build_id", required=True, type=int, help="build id") + args = parser.parse_args() + create_time = datetime.now().strftime("%Y-%m-%d") + comment = Comment(GITEE_REPO, args.token, args.issue_num, JENKINS_BASE_URL, args.jenkins_user, + args.jenkins_password, create_time) + resp = comment.create_comment(args.jenkins_job_name, args.build_id) + if resp: + print("Successfully created an issue about jenkins information comment") diff --git a/release-assistant/javcra/application/checkpart/checktest.py b/release-assistant/javcra/application/checkpart/checktest.py index 82a68e0..7673222 100644 --- a/release-assistant/javcra/application/checkpart/checktest.py +++ b/release-assistant/javcra/application/checkpart/checktest.py @@ -57,6 +57,22 @@ class CheckTest(Issue): logger.error("Error parsing issue description information %s" % error) return {} + def verify_start_update(self): + """ + verify that the issue has been initialized + Returns: + True: has been successfully initialized + False: not initialized yet + """ + body = self.get_issue_body(self.issue_num) + if not body: + logger.error("The description information of issue is not obtained") + return False + + if "发布范围" in body: + return True + return False + def people_review(self): """ relevant people make an issue comment diff --git a/release-assistant/javcra/cli/commands/__init__.py b/release-assistant/javcra/cli/commands/__init__.py index 5773df8..7b5c6fa 100644 --- a/release-assistant/javcra/cli/commands/__init__.py +++ b/release-assistant/javcra/cli/commands/__init__.py @@ -15,12 +15,12 @@ from javcra.application.serialize.validate import validate, validate_giteeid from javcra.common.constant import GITEE_REPO -def personnel_authority(param_dict): +def personnel_authority(param_dict, comment): """ personnel name and responsibilities acquisition Args: param_dict: parameter dictionary - + comment: comment Returns: personnel_dict: personnel Information Dictionary """ @@ -29,6 +29,11 @@ def personnel_authority(param_dict): if not personnel_dict: print("[ERROR] Failed to get the list of personnel permissions") return {} + if "start" not in comment: + verify_res = check.verify_start_update() + if not verify_res: + print("[ERROR] not allowed operation, please start release issue first.") + return {} return personnel_dict @@ -46,7 +51,7 @@ def parameter_permission_validate(schema, param_dict, comment): if error: print("Parameter validation failed") return False - personnel_dict = personnel_authority(param_dict) + personnel_dict = personnel_authority(param_dict, comment) if not personnel_dict: return False permission = validate_giteeid(param_dict.get("giteeid"), comment, personnel_dict) diff --git a/release-assistant/javcra/common/constant.py b/release-assistant/javcra/common/constant.py index c0c7683..6446936 100644 --- a/release-assistant/javcra/common/constant.py +++ b/release-assistant/javcra/common/constant.py @@ -38,6 +38,7 @@ PERMISSION_INFO = { "/cve-ok", "/check-ok", "/cvrf-ok", + "/start-update" ], "developer": [ "/add-bugfix", -- Gitee