From 24bd31288a2d39c51e5685b5feb27f434a0b1ddb Mon Sep 17 00:00:00 2001 From: bobo Date: Wed, 22 May 2024 16:46:27 +0800 Subject: [PATCH 1/3] chore: Update logging level to DEBUG in command.py --- merico/pr/command.py | 2 +- merico/pr/config_util.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/merico/pr/command.py b/merico/pr/command.py index 5b911a8..a58394f 100644 --- a/merico/pr/command.py +++ b/merico/pr/command.py @@ -96,7 +96,7 @@ def close(self): logger.remove(None) logger.add( CustomOutput(), - level=logging.INFO, + level=logging.DEBUG, format="{message}", colorize=False, filter=inv_analytics_filter, diff --git a/merico/pr/config_util.py b/merico/pr/config_util.py index 21dc28e..cd6d12e 100644 --- a/merico/pr/config_util.py +++ b/merico/pr/config_util.py @@ -1,9 +1,10 @@ import json import os -from lib.chatmark import TextEditor +from lib.chatmark import TextEditor, Radio +cache_repo_types = {} # 根据PR URL获取不同的仓库管理类型 # 支持的类型有:github gitlab bitbucket bitbucket_server azure codecommit gerrit def get_repo_type(url): @@ -22,8 +23,35 @@ def get_repo_type(url): return "codecommit" elif "gerrit" in url: return "gerrit" + elif url in cache_repo_types: + return cache_repo_types[url] else: - return "" + radio = Radio( + [ + "github", + "gitlab", + "bitbucket", + "bitbucket_server", + "azure", + "codecommit", + "gerrit" + ], + ) + radio.render() + if radio.selection is not None: + return "" + + rtype = [ + "github", + "gitlab", + "bitbucket", + "bitbucket_server", + "azure", + "codecommit", + "gerrit" + ][radio.selection] + cache_repo_types[url] = rtype + return rtype def read_github_token(): From 14b3197543c90cb7d12ffdb5e56c696e3794323c Mon Sep 17 00:00:00 2001 From: bobo Date: Wed, 22 May 2024 16:56:13 +0800 Subject: [PATCH 2/3] chore: Refactor config_util.py to handle gitlab host input --- merico/pr/config_util.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/merico/pr/config_util.py b/merico/pr/config_util.py index cd6d12e..c1c5b49 100644 --- a/merico/pr/config_util.py +++ b/merico/pr/config_util.py @@ -38,7 +38,7 @@ def get_repo_type(url): ], ) radio.render() - if radio.selection is not None: + if radio.selection is None: return "" rtype = [ @@ -159,11 +159,9 @@ def read_server_access_token_with_input(pr_url): def gitlab_host(): host = read_gitlab_host() - if host: - return host gitlab_host_editor = TextEditor( - "", "Please input your gitlab host(for example: https://www.gitlab.com):" + host, "Please input your gitlab host(for example: https://www.gitlab.com):" ) gitlab_host_editor.render() host = gitlab_host_editor.new_text From 62b450d677c4eff8319544afdd63f46c2eae01c8 Mon Sep 17 00:00:00 2001 From: bobo Date: Wed, 22 May 2024 16:57:16 +0800 Subject: [PATCH 3/3] Refactor config_util.py to handle gitlab host input --- merico/pr/config_util.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/merico/pr/config_util.py b/merico/pr/config_util.py index c1c5b49..ca2c9d2 100644 --- a/merico/pr/config_util.py +++ b/merico/pr/config_util.py @@ -1,10 +1,11 @@ import json import os -from lib.chatmark import TextEditor, Radio - +from lib.chatmark import Radio, TextEditor cache_repo_types = {} + + # 根据PR URL获取不同的仓库管理类型 # 支持的类型有:github gitlab bitbucket bitbucket_server azure codecommit gerrit def get_repo_type(url): @@ -27,29 +28,21 @@ def get_repo_type(url): return cache_repo_types[url] else: radio = Radio( - [ - "github", - "gitlab", - "bitbucket", - "bitbucket_server", - "azure", - "codecommit", - "gerrit" - ], + ["github", "gitlab", "bitbucket", "bitbucket_server", "azure", "codecommit", "gerrit"], ) radio.render() if radio.selection is None: return "" rtype = [ - "github", - "gitlab", - "bitbucket", - "bitbucket_server", - "azure", - "codecommit", - "gerrit" - ][radio.selection] + "github", + "gitlab", + "bitbucket", + "bitbucket_server", + "azure", + "codecommit", + "gerrit", + ][radio.selection] cache_repo_types[url] = rtype return rtype