From 64d5108f99f0d3630cbeb04792e3fd92004278af Mon Sep 17 00:00:00 2001 From: balaba-max Date: Wed, 6 Dec 2023 06:41:36 +0300 Subject: [PATCH] Feature: GitLab url from ENV (#14221) --------- Co-authored-by: Erick Friis --- docs/docs/integrations/toolkits/gitlab.ipynb | 2 ++ libs/langchain/langchain/utilities/gitlab.py | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/docs/integrations/toolkits/gitlab.ipynb b/docs/docs/integrations/toolkits/gitlab.ipynb index 3edb840ef2a..83b40ffdd6a 100644 --- a/docs/docs/integrations/toolkits/gitlab.ipynb +++ b/docs/docs/integrations/toolkits/gitlab.ipynb @@ -77,6 +77,7 @@ "\n", "Before initializing your agent, the following environmental variables need to be set:\n", "\n", + "* **GITLAB_URL** - The URL hosted Gitlab. Defaults to \"https://gitlab.com\". \n", "* **GITLAB_PERSONAL_ACCESS_TOKEN**- The personal access token you created in the last step\n", "* **GITLAB_REPOSITORY**- The name of the Gitlab repository you want your bot to act upon. Must follow the format {username}/{repo-name}.\n", "* **GITLAB_BRANCH**- The branch where the bot will make its commits. Defaults to 'main.'\n", @@ -111,6 +112,7 @@ "outputs": [], "source": [ "# Set your environment variables using os.environ\n", + "os.environ[\"GITLAB_URL\"] = \"https://gitlab.example.org\"\n", "os.environ[\"GITLAB_PERSONAL_ACCESS_TOKEN\"] = \"\"\n", "os.environ[\"GITLAB_REPOSITORY\"] = \"username/repo-name\"\n", "os.environ[\"GITLAB_BRANCH\"] = \"bot-branch-name\"\n", diff --git a/libs/langchain/langchain/utilities/gitlab.py b/libs/langchain/langchain/utilities/gitlab.py index 78765637c71..c36f8479e95 100644 --- a/libs/langchain/langchain/utilities/gitlab.py +++ b/libs/langchain/langchain/utilities/gitlab.py @@ -38,6 +38,10 @@ class GitLabAPIWrapper(BaseModel): @root_validator() def validate_environment(cls, values: Dict) -> Dict: """Validate that api key and python package exists in environment.""" + + gitlab_url = get_from_dict_or_env( + values, "gitlab_url", "GITLAB_URL", default=None + ) gitlab_repository = get_from_dict_or_env( values, "gitlab_repository", "GITLAB_REPOSITORY" ) @@ -62,7 +66,11 @@ class GitLabAPIWrapper(BaseModel): "Please install it with `pip install python-gitlab`" ) - g = gitlab.Gitlab(private_token=gitlab_personal_access_token) + g = gitlab.Gitlab( + url=gitlab_url, + private_token=gitlab_personal_access_token, + keep_base_url=True, + ) g.auth()