diff --git a/ci/tools/translation/create_translation_issue.py b/ci/tools/translation/create_translation_issue.py index 7f8ede5ca85d6090d1cfbd96b89fff83bbb9ca32..d1d5fb00bc337a5e0b41783fcb84934fc144bf2c 100644 --- a/ci/tools/translation/create_translation_issue.py +++ b/ci/tools/translation/create_translation_issue.py @@ -1,10 +1,11 @@ -import requests -import yaml -import sys import json import re +import sys from difflib import SequenceMatcher +import requests +import yaml + def load_yaml(file_path): """ @@ -107,7 +108,7 @@ def create_issue(acc_token, owner, repo, p_number, issue_title, assignee, body): "title": issue_title + "[{}]".format(p_number), "assignee": assignee, "issue_type": "翻译", - "body": "Related PR link: +{}".format(body) + "body": "### Related PR link \n - {}".format(body) } r = requests.post(issue_url, params=param) if r.status_code != 201: @@ -123,7 +124,7 @@ def create_issue(acc_token, owner, repo, p_number, issue_title, assignee, body): "repo": repo, "title": issue_title + "[{}]".format(p_number), "issue_type": "翻译", - "body": "Related PR link: +{}".format(body) + "body": "### Related PR link \n- {}".format(body) } res = requests.post(issue_url, params=param2) if res.status_code != 201: @@ -132,6 +133,24 @@ def create_issue(acc_token, owner, repo, p_number, issue_title, assignee, body): print("issue has been made successfully, issue number is #{}".format(json.loads(res.text).get("number"))) +def add_pr_comment(acc_token, owner, repo, p_number, body): + """ + create issues + :param acc_token: access_token + :param owner: owner ep:openeuler + :param repo: repo ep: docs + :param p_number: pull request number + :param body: pull request url + :return: + """ + issue_url = 'https://gitee.com/api/v5/repos/{}/{}/pulls/{}/comments'.format(owner, repo, p_number) + param = { + "access_token": acc_token, + "body": "### Translation Feedback \n - {} ".format(body) + } + requests.post(issue_url, params=param) + + def get_pr_information(owner, repo, number, token): url = "https://gitee.com/api/v5/repos/{}/{}/pulls/{}".format(owner, repo, number) param = {"access_token": token} @@ -220,6 +239,7 @@ def main(owner, repo, token, number): """ content = load_yaml("translation2.yaml") issue_related_pr_number = {} + existed_issue = {} current_assignee = {} current_file_extension = {} current_issue_title = {} @@ -238,6 +258,16 @@ def main(owner, repo, token, number): print(e) sys.exit(1) for repository in repositories: + if "issue_of_owner" in repository: + issue_of_owner = repository["issue_of_owner"] + else: + issue_of_owner = repository["owner"] + if "issue_of_repo" in repository: + issue_of_repo = repository["issue_of_repo"] + else: + issue_of_repo = repository["repo"] + issue_title_pr_mark = "{}/{}/pulls/{}".format(owner, repo, number) + if owner == repository["owner"] and repo == repository["repo"] and repository["auto_create_issue"]: exclude = repository.get('exclude') if not exclude: @@ -253,7 +283,8 @@ def main(owner, repo, token, number): trigger_path.append(issue_trigger["trigger_pr_path"]) for diff_file in diff_files: if diff_file.startswith(issue_trigger["trigger_pr_path"]) \ - and diff_file.split('.')[-1] in issue_trigger["file_extension"] and "/zh" in issue_trigger["trigger_pr_path"]: + and diff_file.split('.')[-1] in issue_trigger["file_extension"] and "/zh" in issue_trigger[ + "trigger_pr_path"]: print("file {} has been changed".format(diff_file)) file_count += 1 current_assignee["zh"] = issue_trigger["assign_issue"][1]["sign_to"] @@ -261,7 +292,8 @@ def main(owner, repo, token, number): current_issue_title["zh"] = issue_trigger["assign_issue"][0]["title"] zh_file.append(diff_file.replace("zh/", "")) elif diff_file.startswith(issue_trigger["trigger_pr_path"]) \ - and diff_file.split('.')[-1] in issue_trigger["file_extension"] and "/en" in issue_trigger["trigger_pr_path"]: + and diff_file.split('.')[-1] in issue_trigger["file_extension"] and "/en" in issue_trigger[ + "trigger_pr_path"]: print("file {} has been changed".format(diff_file)) file_count += 1 current_assignee["en"] = issue_trigger["assign_issue"][1]["sign_to"] @@ -270,7 +302,8 @@ def main(owner, repo, token, number): en_file.append(diff_file.replace("en/", "")) elif diff_file.startswith(issue_trigger["trigger_pr_path"]) \ and diff_file.split('.')[-1] in issue_trigger["file_extension"]: - if owner in ["opengauss"] and repo in ["docs"] and issue_trigger["trigger_pr_path"] in ["contribute/"]: + if owner in ["opengauss"] and repo in ["docs"] and issue_trigger["trigger_pr_path"] in [ + "contribute/"]: print("file {} has been changed".format(diff_file)) file_count += 1 current_assignee["zh"] = issue_trigger["assign_issue"][1]["sign_to"] @@ -286,26 +319,33 @@ def main(owner, repo, token, number): else: changed_same_files = False if file_count > 0 and not changed_same_files: - results = check_issue_exits(token, owner, repo) + results = check_issue_exits(token, issue_of_owner, issue_of_repo) if results: + existed_issue = {} for result in results: - issue_number = result.get("title").split('.')[-1].replace('[', '').replace(']', '') - issue_related_pr_number[issue_number] = result.get("number") - if number in issue_related_pr_number.keys(): - print("Error: issue has already created, please go to check issue: #{}" - .format(issue_related_pr_number[number])) + pr_mark = result.get("title").split('.')[-1].replace('[', '').replace(']', '') + issue_related_pr_number[pr_mark] = result.get("number") + if issue_title_pr_mark == pr_mark: + existed_issue = result + if existed_issue: + feedback_comment = "issue has already created, please go to check issue: {}".format( + existed_issue["html_url"]) + print("Warning: " + feedback_comment) + add_pr_comment(token, owner, repo, number, feedback_comment) sys.exit(1) else: for k in current_file_extension.keys(): if pr_issue_title.startswith("[Auto]"): continue - create_issue(token, owner, repo, number, current_issue_title[k], + create_issue(token, issue_of_owner, issue_of_repo, issue_title_pr_mark, + current_issue_title[k], current_assignee[k], pr_url) else: for k in current_file_extension.keys(): if pr_issue_title.startswith("[Auto]"): continue - create_issue(token, owner, repo, number, current_issue_title[k], + create_issue(token, issue_of_owner, issue_of_repo, issue_title_pr_mark, + current_issue_title[k], current_assignee[k], pr_url) elif file_count > 0 and changed_same_files: print("changed the same files in en and zh path, no need to create issue") @@ -352,21 +392,28 @@ def main(owner, repo, token, number): diff_files, pr_url = get_diff_files(owner, repo, number, token) if do_translate and pr_state == "merged": + results = check_issue_exits(token, issue_of_owner, issue_of_repo) if results: + existed_issue = {} for result in results: - issue_number = result.get("title").split('.')[-1].replace('[', '').replace(']', '') - issue_related_pr_number[issue_number] = result.get("number") - if number in issue_related_pr_number.keys(): - print("Error: issue has already created, please go to check issue: #{}" - .format(issue_related_pr_number[number])) + pr_mark = result.get("title").split('.')[-1].replace('[', '').replace(']', '') + issue_related_pr_number[pr_mark] = result.get("number") + if issue_title_pr_mark == pr_mark: + existed_issue = result + if existed_issue: + feedback_comment = "issue has already created, please go to check issue: {}".format( + existed_issue["html_url"]) + print("Warning: " + feedback_comment) + add_pr_comment(token, owner, repo, number, feedback_comment) sys.exit(1) else: - create_issue(token, owner, repo, number, - repository["issue_triggers"]["assign_issue"][0]["title"], - repository["issue_triggers"]["assign_issue"][1]["sign_to"], pr_url) + create_issue(token, issue_of_owner, issue_of_repo, issue_title_pr_mark, + repository["issue_triggers"][0]["assign_issue"][0]["title"], + repository["issue_triggers"][0]["assign_issue"][1]["sign_to"], pr_url) else: - create_issue(token, owner, repo, number, repository["issue_triggers"]["assign_issue"][0]["title"], - repository["issue_triggers"]["assign_issue"][1]["sign_to"], pr_url) + create_issue(token, issue_of_owner, issue_of_repo, issue_title_pr_mark, + repository["issue_triggers"][0]["assign_issue"][0]["title"], + repository["issue_triggers"][0]["assign_issue"][1]["sign_to"], pr_url) elif cancel_translate: print("not need to create issue for pull request") @@ -386,4 +433,3 @@ if __name__ == '__main__': access_token = sys.argv[3] pr_number = sys.argv[4] main(pr_owner, pr_repo, access_token, pr_number) - diff --git a/ci/tools/translation/translation.yaml b/ci/tools/translation/translation.yaml index 2dfccd2353e31c07e610a2bc33c083a1d0aaeb2a..5a200202316a3bee9c477d5646aed51a93237188 100644 --- a/ci/tools/translation/translation.yaml +++ b/ci/tools/translation/translation.yaml @@ -1,70 +1,103 @@ repositories: -- owner: openeuler - repo: docs - auto_create_issue: true - issue_triggers: - - trigger_pr_path: 'docs/zh' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: judithsq -# - trigger_pr_path: 'docs/en' -# file_extension: [doc, md, json] -# assign_issue: -# - title: "[Auto] This is a Russian translation issue." -# - sign_to: judithsq - exclude: - - condition: only_marks_change - check_list: [',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、'] -- owner: openeuler - repo: website-v2 - auto_create_issue: false - # if you want to trigger to create an issue when pull request has been merged, use this command. - trigger_command: "/translate" - # if you don't want to trigger to create an issue when pull request has been merged, use this command. - cancel_command: "/translate cancel" - issue_triggers: - - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: georgecao -- owner: opengauss - repo: docs - auto_create_issue: true - issue_triggers: - - trigger_pr_path: 'content/zh' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: freyaqqianjin - - trigger_pr_path: 'content/en' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] 这是一个中文翻译需求." - - sign_to: freyaqqianjin - - trigger_pr_path: 'content/docs-lite/zh' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: freyaqqianjin - - trigger_pr_path: 'content/docs-lite/en' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] 这是一个中文翻译需求." - - sign_to: freyaqqianjin - - trigger_pr_path: 'contribute/' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: freyaqqianjin -- owner: Ascend - repo: canndev - auto_create_issue: true - issue_triggers: - - trigger_pr_path: 'ops/built-in/op_api/doc/zh' - file_extension: [doc, md, json] - assign_issue: - - title: "[Auto] This is an English translation issue." - - sign_to: lux1 - exclude: - - condition: only_marks_change - check_list: [',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、'] \ No newline at end of file + - owner: ibforuorg + repo: cloudnative-docs + issue_of_owner: ibforuorg + issue_of_repo: test-free + auto_create_issue: true + trigger_command: "/1111" + cancel_command: "/2222" + issue_triggers: + - trigger_pr_path: 'docs/zh' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is an English translation issue." + - sign_to: ibforu + - trigger_pr_path: 'docs/en' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is a Chinese translation issue." + - sign_to: ibforu + exclude: + - condition: only_marks_change + check_list: [ ',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、' ] + + - owner: ibforuorg + repo: openstack-docs + issue_of_owner: ibforuorg + issue_of_repo: test-free + auto_create_issue: true + trigger_command: "/1111" + cancel_command: "/2222" + issue_triggers: + - trigger_pr_path: 'docs/zh' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is an English translation issue." + - sign_to: ibforu + - trigger_pr_path: 'docs/en' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is a Chinese translation issue." + - sign_to: ibforu + exclude: + - condition: only_marks_change + check_list: [ ',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、' ] + + - owner: ibforuorg + repo: openstack-docs + auto_create_issue: true + trigger_command: "/1111" + cancel_command: "/2222" + issue_triggers: + - trigger_pr_path: 'docs/zh' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is an English translation issue." + - sign_to: ibforu + - trigger_pr_path: 'docs/en' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is a Chinese translation issue." + - sign_to: ibforu + exclude: + - condition: only_marks_change + + - owner: ibforuorg + repo: compiler-docs + auto_create_issue: true + issue_triggers: + - trigger_pr_path: 'docs/zh' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is an English translation issue." + - sign_to: ibforu + - trigger_pr_path: 'docs/en' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is a Russian translation issue." + - sign_to: ibforu + exclude: + - condition: only_marks_change + check_list: [ ',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、' ] + + - owner: ibforuorg + repo: Virt-docs + issue_of_owner: ibforuorg + issue_of_repo: test-free + auto_create_issue: false + trigger_command: "/1111" + cancel_command: "/2222" + issue_triggers: + - trigger_pr_path: 'docs/zh' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is an English translation issue." + - sign_to: ibforu + - trigger_pr_path: 'docs/en' + file_extension: [ doc, md, json ] + assign_issue: + - title: "[Auto] This is a Chinese translation issue." + - sign_to: ibforu + exclude: + - condition: only_marks_change + check_list: [ ',', ',', '.', '。', ';', ';', ':', ':', '"', '“', '”', '、' ] \ No newline at end of file