From effb7b5446057923dcf0ced6aaf7b0321ba47622 Mon Sep 17 00:00:00 2001
From: Lukas Bednar <lbednar@redhat.com>
Date: Tue, 30 Apr 2024 12:43:42 +0200
Subject: [PATCH] Passing URL as environment variable (#141)

Signed-off-by: Lukas Bednar <lbednar@redhat.com>
---
 README.rst     | 4 ++--
 pytest_jira.py | 7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/README.rst b/README.rst
index 2ffec9e..f6a0794 100644
--- a/README.rst
+++ b/README.rst
@@ -198,11 +198,11 @@ Usage
      # connection_error_strategy [strict|skip|ignore] Choose how to handle connection errors
      # return_jira_metadata = False (return Jira issue with metadata instead of boolean result)
 
-   You can set the password and username fields by setting the PYTEST_JIRA_PASSWORD, PYTEST_JIRA_USERNAME and
-   PYTEST_JIRA_TOKEN environment variables:
+   Alternatively, you can set the url, password, username and token fields using relevant environment variables:
 
     .. code:: sh
 
+      export PYTEST_JIRA_URL="https://..."
       export PYTEST_JIRA_PASSWORD="FOO"
       export PYTEST_JIRA_USERNAME="BAR"
       export PYTEST_JIRA_TOKEN="TOKEN"
diff --git a/pytest_jira.py b/pytest_jira.py
index 86926fe..4d458af 100644
--- a/pytest_jira.py
+++ b/pytest_jira.py
@@ -29,6 +29,7 @@
 SKIP = 'skip'
 IGNORE = 'ignore'
 PLUGIN_NAME = "jira_plugin"
+URL_ENV_VAR = 'PYTEST_JIRA_URL'
 PASSWORD_ENV_VAR = 'PYTEST_JIRA_PASSWORD'
 USERNAME_ENV_VAR = 'PYTEST_JIRA_USERNAME'
 TOKEN_ENV_VAR = 'PYTEST_JIRA_TOKEN'
@@ -544,9 +545,11 @@ def pytest_configure(config):
     if not resolved_resolutions:
         resolved_resolutions = []
 
-    if config.getvalue('jira') and config.getvalue('jira_url'):
+    if config.getvalue('jira') and (
+        os.getenv(URL_ENV_VAR) or config.getvalue('jira_url')
+    ):
         jira_connection = JiraSiteConnection(
-            config.getvalue('jira_url'),
+            os.getenv(URL_ENV_VAR) or config.getvalue('jira_url'),
             os.getenv(USERNAME_ENV_VAR) or config.getvalue('jira_username'),
             os.getenv(PASSWORD_ENV_VAR) or config.getvalue('jira_password'),
             config.getvalue('jira_verify'),