Merge pull request #113 from devchat-ai/fix_gitlab_host_in_pr
chore: Update gitlab host in config_util.py
This commit is contained in:
commit
ec187a0c1b
@ -75,8 +75,6 @@ from pr_agent.config_loader import get_settings
|
|||||||
# mock logging method, to redirect log to IDE
|
# mock logging method, to redirect log to IDE
|
||||||
from pr_agent.log import inv_analytics_filter, setup_logger
|
from pr_agent.log import inv_analytics_filter, setup_logger
|
||||||
|
|
||||||
from lib.ide_service import IDEService
|
|
||||||
|
|
||||||
|
|
||||||
class CustomOutput:
|
class CustomOutput:
|
||||||
def __init__(self):
|
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
|
from custom_suggestions_config import get_custom_suggestions_system_prompt
|
||||||
|
|
||||||
# set openai key and api base
|
# set openai key and api base
|
||||||
@ -121,10 +119,15 @@ if not access_token:
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
repo_type = get_repo_type(sys.argv[1])
|
repo_type = get_repo_type(sys.argv[1])
|
||||||
|
IDEService().ide_logging("debug", f"repo type: {repo_type}")
|
||||||
if repo_type == "github":
|
if repo_type == "github":
|
||||||
get_settings().set("GITHUB.USER_TOKEN", access_token)
|
get_settings().set("GITHUB.USER_TOKEN", access_token)
|
||||||
elif repo_type == "gitlab":
|
elif repo_type == "gitlab":
|
||||||
get_settings().set("GITLAB.PERSONAL_ACCESS_TOKEN", access_token)
|
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:
|
else:
|
||||||
print(
|
print(
|
||||||
"Unsupported git hosting service, input pr url is:",
|
"Unsupported git hosting service, input pr url is:",
|
||||||
|
@ -46,6 +46,16 @@ def read_server_access_token(repo_type):
|
|||||||
return ""
|
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):
|
def save_github_token(github_token):
|
||||||
config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json")
|
config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json")
|
||||||
|
|
||||||
@ -59,6 +69,19 @@ def save_github_token(github_token):
|
|||||||
json.dump(config_data, f, indent=4)
|
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):
|
def save_server_access_token(repo_type, access_token):
|
||||||
config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json")
|
config_path = os.path.join(os.path.expanduser("~/.chat"), ".workflow_config.json")
|
||||||
|
|
||||||
@ -104,3 +127,18 @@ def read_server_access_token_with_input(pr_url):
|
|||||||
return server_access_token
|
return server_access_token
|
||||||
save_server_access_token(repo_type, server_access_token)
|
save_server_access_token(repo_type, server_access_token)
|
||||||
return 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