From 6091f1c1494c7c455b3c74c2bcc792cb890da117 Mon Sep 17 00:00:00 2001 From: bobo Date: Mon, 20 May 2024 20:17:18 +0800 Subject: [PATCH 1/2] chore: Update gitlab host in config_util.py --- merico/pr/command.py | 9 ++++++--- merico/pr/config_util.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/merico/pr/command.py b/merico/pr/command.py index 416383a..5b911a8 100644 --- a/merico/pr/command.py +++ b/merico/pr/command.py @@ -75,8 +75,6 @@ def get_git_provider(): # mock logging method, to redirect log to IDE from pr_agent.log import inv_analytics_filter, setup_logger -from lib.ide_service import IDEService - class CustomOutput: def __init__(self): @@ -105,7 +103,7 @@ def close(self): ) -from config_util import get_repo_type, read_server_access_token_with_input +from config_util import get_repo_type, gitlab_host, read_server_access_token_with_input from custom_suggestions_config import get_custom_suggestions_system_prompt # set openai key and api base @@ -121,10 +119,15 @@ def close(self): sys.exit(0) repo_type = get_repo_type(sys.argv[1]) +IDEService().ide_logging("debug", f"repo type: {repo_type}") if repo_type == "github": get_settings().set("GITHUB.USER_TOKEN", access_token) elif repo_type == "gitlab": get_settings().set("GITLAB.PERSONAL_ACCESS_TOKEN", access_token) + host = gitlab_host() + if host: + IDEService().ide_logging("debug", f"gitlab host: {host}") + get_settings().set("GITLAB.URL", host) else: print( "Unsupported git hosting service, input pr url is:", diff --git a/merico/pr/config_util.py b/merico/pr/config_util.py index f45228f..eb64a13 100644 --- a/merico/pr/config_util.py +++ b/merico/pr/config_util.py @@ -46,6 +46,15 @@ def read_server_access_token(repo_type): return "" +def read_gitlab_host(): + config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") + if os.path.exists(config_path): + with open(config_path, "r", encoding="utf-8") as f: + config_data = json.load(f) + if "gitlab_host" in config_data: + return config_data["gitlab_host"] + return "" + def save_github_token(github_token): config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") @@ -59,6 +68,18 @@ def save_github_token(github_token): json.dump(config_data, f, indent=4) +def save_gitlab_host(github_token): + config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") + + config_data = {} + if os.path.exists(config_path): + with open(config_path, "r", encoding="utf-8") as f: + config_data = json.load(f) + + config_data["gitlab_host"] = github_token + with open(config_path, "w+", encoding="utf-8") as f: + json.dump(config_data, f, indent=4) + def save_server_access_token(repo_type, access_token): config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") @@ -104,3 +125,18 @@ def read_server_access_token_with_input(pr_url): return server_access_token save_server_access_token(repo_type, server_access_token) return server_access_token + +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):" + ) + gitlab_host_editor.render() + host = gitlab_host_editor.new_text + if host: + save_gitlab_host(host) + return host From e883bf6f4f6e3285d33006589c7bc56da525e08a Mon Sep 17 00:00:00 2001 From: bobo Date: Mon, 20 May 2024 20:20:18 +0800 Subject: [PATCH 2/2] chore: Update gitlab host in config_util.py --- merico/pr/config_util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/merico/pr/config_util.py b/merico/pr/config_util.py index eb64a13..6b6b20b 100644 --- a/merico/pr/config_util.py +++ b/merico/pr/config_util.py @@ -55,6 +55,7 @@ def read_gitlab_host(): return config_data["gitlab_host"] return "" + def save_github_token(github_token): config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") @@ -80,6 +81,7 @@ def save_gitlab_host(github_token): with open(config_path, "w+", encoding="utf-8") as f: json.dump(config_data, f, indent=4) + def save_server_access_token(repo_type, access_token): config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json") @@ -126,14 +128,14 @@ def read_server_access_token_with_input(pr_url): save_server_access_token(repo_type, server_access_token) return server_access_token + 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):" + "", "Please input your gitlab host(for example: https://www.gitlab.com):" ) gitlab_host_editor.render() host = gitlab_host_editor.new_text