From b06ff8c0ade3cf71aa31d11b52d5e25763128fa5 Mon Sep 17 00:00:00 2001 From: licihua Date: Thu, 5 Nov 2020 11:44:20 +0800 Subject: [PATCH] support batch check yaml and spec file --- ...missing_specs.py => check_missing_file.py} | 141 ++++++++++++++---- advisors/check_version.py | 49 +++--- advisors/oa_upgradable.py | 9 +- ...check_missing_specs => check_missing_file} | 2 +- 4 files changed, 145 insertions(+), 56 deletions(-) rename advisors/{check_missing_specs.py => check_missing_file.py} (37%) rename command/{check_missing_specs => check_missing_file} (90%) diff --git a/advisors/check_missing_specs.py b/advisors/check_missing_file.py similarity index 37% rename from advisors/check_missing_specs.py rename to advisors/check_missing_file.py index b26baff4..50e1e174 100755 --- a/advisors/check_missing_specs.py +++ b/advisors/check_missing_file.py @@ -12,7 +12,7 @@ # # ******************************************************************************/ """ -This is a simple script to check if SPEC already been submit into repository. +This is a simple script to check if files already been submit into repository. If not, it can be used to push an issue to remind the developer. """ @@ -22,7 +22,7 @@ from datetime import datetime from advisors import gitee -NEW_ISSUE_BODY = """Dear {repo} maintainer: +NEW_SPEC_ISSUE_BODY = """Dear {repo} maintainer: 亲爱的 {repo} 维护者: We found there is no spec file in this repository's master branch yet. @@ -40,6 +40,24 @@ This is a automatic advise from openEuler-Advisor. If you think the advise is no Yours openEuler Advisor. """ +NEW_YMAL_ISSUE_BODY = """Dear {repo} maintainer: +亲爱的 {repo} 维护者: + +We found there is no yaml file in this repository's master branch yet. +我们发现这个代码仓 master branch 中没有 yaml 文件。 + +Missing yaml file implies that this components will not upgrade automatic. +缺少 yaml 文件意味着这个项目还不能自动升级。 + +We courage you submit your yaml file into this repository as soon as possible. +我们鼓励您尽快提交 yaml 文件到这个代码仓中. + +This is a automatic advise from openEuler-Advisor. If you think the advise is not correct, please fill an issue at https://gitee.com/openeuler/openEuler-Advisor to help us improve. +这是一条由 openEuler-Advisor 自动生成的建议。如果您认为这个建议不对,请访问 https://gitee.com/openeuler/openEuler-Advisor 来帮助我们改进。 + +Yours openEuler Advisor. +""" + NEW_COMMENT = """Dear {repo} maintainer: We found this issue has been open for {days} days. @@ -53,44 +71,113 @@ This is a automatic advise from openEuler-Advisor. If you think the advise is no Yours openEuler Advisor. """ - -def main(): +def get_repos_by_sig(sig): """ - Main entrance for command line + Get repos by sig + """ + user_gitee = gitee.Gitee() + yaml_data = user_gitee.get_sigs() + + repo_list = [] + for sigs in yaml_data['sigs']: + if sig not in (sigs['name'], 'all'): + continue + repo_name = sigs['repositories'] + repo_list.append(repo_name) + repo_list = [i for item in repo_list for i in item] + return repo_list + +def main_process(repo, push, check_file): + """ + Main process for command line """ - pars = argparse.ArgumentParser() - pars.add_argument("repo", type=str, help="Repo to be checked") - pars.add_argument("-p", "--push", help="Push the advise to gitee.com/src-openeuler", - action="store_true") - - args = pars.parse_args() - my_gitee = gitee.Gitee() - spec_string = my_gitee.get_spec(args.repo) + if check_file == 'yaml': + file = my_gitee.get_yaml(repo) + elif check_file == 'spec': + file = my_gitee.get_spec(repo) + else: + print("ERROR: Not support {file} check".format(file=check_file)) + return 'NOK' - if not spec_string: - print("no spec file found for {repo} project".format(repo=args.repo)) - if args.push: - issues = my_gitee.get_issues(args.repo) + if not file: + print("no {file} file found for {repo} project".format(file=check_file, repo=repo)) + if push: + issues = my_gitee.get_issues(repo) for issue in issues: - if issue["title"] == "Submit spec file into this repository": + if issue["title"] == "Submit {file} file into this repository".format( + file=check_file): ages = datetime.now() - my_gitee.get_gitee_datetime(issue["created_at"]) if ages.days <= 10: print("Advise has been issues only %d days ago" % ages.days) print("Give developers more time to handle it.") break - my_gitee.post_issue_comment(args.repo, issue["number"], NEW_COMMENT.format( - repo=args.repo, days=ages.days)) + my_gitee.post_issue_comment(repo, issue["number"], NEW_COMMENT.format( + repo=repo, + days=ages.days)) break else: - my_gitee.post_issue(args.repo, - "Submit spec file into this repository", - NEW_ISSUE_BODY.format(repo=args.repo)) - else: - print("Keep this between us.") - else: - print("Everything's fine") + if check_file == 'spec': + my_gitee.post_issue(repo, + "Submit {file} file into this repository".format( + file=check_file), + NEW_SPEC_ISSUE_BODY.format(repo=repo, + file=check_file)) + else: + my_gitee.post_issue(repo, + "Submit {file} file into this repository".format( + file=check_file), + NEW_YMAL_ISSUE_BODY.format(repo=repo, + file=check_file)) + return 'NOK' + return 'OK' + + +def main(): + """ + Main process for command line + """ + pars = argparse.ArgumentParser() + pars.add_argument("-s", "--sig", type=str, default='all', help="Sig name") + pars.add_argument("-p", "--push", + help="Push the advise to gitee.com/src-openeuler", + action="store_true") + pars.add_argument("-f", "--file", type=str, default='spec', + help="File name want to check, spec or yaml?") + args = pars.parse_args() + if args.file not in ('spec', 'yaml'): + print("ERROR: Not support {file} check".format(file=args.file)) + return + + repos = get_repos_by_sig(args.sig) + if not repos: + print("ERROR: no repos find is {sig} sig, please check the sig name.".format( + sig=args.sig)) + return + fail_list = [] + + total = len(repos) + index = 0 + for repo in repos: + index = index + 1 + url = repo.split('/')[0] + if url == 'openeuler': + continue + check_repo = repo.split('/')[1] + result = main_process(check_repo, args.push, args.file) + if result != 'OK': + fail_list.append(check_repo) + + print("INFO: {index} in {total} check {repo} {file} {result}".format(index=index, + total=total, + repo=check_repo, + file=args.file, + result=result)) + if fail_list: + print('The repos listed below check {file} failed:'.format(file=args.file)) + for repo in fail_list: + print(repo) if __name__ == "__main__": main() diff --git a/advisors/check_version.py b/advisors/check_version.py index 45b9d202..65541335 100755 --- a/advisors/check_version.py +++ b/advisors/check_version.py @@ -16,25 +16,8 @@ This is an automatic script for checking source url of package """ import os import argparse -from advisors import gitee from advisors.oa_upgradable import main_process - - -def get_repos_by_sig(sig): - """ - Get repos by sig - """ - user_gitee = gitee.Gitee() - yaml_data = user_gitee.get_sigs() - - repo_list = [] - for sigs in yaml_data['sigs']: - if sig not in (sigs['name'], 'all'): - continue - repo_name = sigs['repositories'] - repo_list.append(repo_name) - repo_list = [i for item in repo_list for i in item] - return repo_list +from advisors.check_missing_file import get_repos_by_sig def main(): @@ -58,16 +41,36 @@ def main(): sig = 'all' repos = get_repos_by_sig(sig) - + total = len(repos) + index = 0 + upgrade_list = [] for repo in repos: + index = index + 1 url = repo.split('/')[0] if url == 'openeuler': continue - try: - main_process(args.push, args.default, repo.split('/')[1]) - except Exception as error: - print("ERROR: Command execution error", error) + check_repo = repo.split('/')[1] + result = main_process(args.push, args.default, check_repo) + if result: + print('''INFO: {index} in {total} check {repo} need upgrade \ +from {current} to {latest}'''.format(index=index, + total=total, + repo=result[0], + current=result[1], + latest=result[2])) + upgrade_list.append(result) + else: + print('''INFO: {index} in {total} check {repo} not need \ +upgrade'''.format(index=index, + total=total, + repo=check_repo)) + if upgrade_list: + print("The repos listed below need upgrade:") + for upgrade_repo in upgrade_list: + print("{repo} {current} {latest}".format(repo=upgrade_repo[0], + current=upgrade_repo[1], + latest=upgrade_repo[2])) if __name__ == "__main__": main() diff --git a/advisors/oa_upgradable.py b/advisors/oa_upgradable.py index 9e584825..2d337f54 100755 --- a/advisors/oa_upgradable.py +++ b/advisors/oa_upgradable.py @@ -111,12 +111,11 @@ def main_process(push, default, repo): Main process of the functionality """ print("Checking", repo) - user_gitee = gitee.Gitee() spec_string = user_gitee.get_spec(repo) if not spec_string: print("WARNING: {pkg}.spec can't be found on master".format(pkg=repo)) - return + return None spec_file = Spec.from_string(spec_string) cur_version = replace_macros(spec_file.version, spec_file) @@ -128,7 +127,7 @@ def main_process(push, default, repo): print("known release tags:", pkg_tags) if pkg_tags is None: - return + return None if cur_version not in pkg_tags: print("WARNING: Current {ver} doesn't exist in upstream." \ @@ -153,7 +152,7 @@ If you think this is not proper issue, Please visit https://gitee.com/openeuler/ Issues and feedbacks are welcome.""".format(repo=repo, ver=ver_rec.latest_version, cur_ver=cur_version)) - - + return repo, cur_version, ver_rec.latest_version + return None if __name__ == "__main__": main() diff --git a/command/check_missing_specs b/command/check_missing_file similarity index 90% rename from command/check_missing_specs rename to command/check_missing_file index cdffa17f..521556dd 100644 --- a/command/check_missing_specs +++ b/command/check_missing_file @@ -14,7 +14,7 @@ try: except: pass -from advisors.check_missing_specs import main +from advisors.check_missing_file import main if __name__ == '__main__': -- Gitee