Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update gitlab host in config_util.py #113

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions merico/pr/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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:",
Expand Down
38 changes: 38 additions & 0 deletions merico/pr/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ 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")

Expand All @@ -59,6 +69,19 @@ 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")

Expand Down Expand Up @@ -104,3 +127,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