chore: Update gitlab host in config_util.py
This commit is contained in:
parent
da12ac1fb9
commit
6091f1c149
@ -75,8 +75,6 @@ from pr_agent.config_loader import get_settings
|
||||
# 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 @@ logger.add(
|
||||
)
|
||||
|
||||
|
||||
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 @@ if not access_token:
|
||||
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:",
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user