zanoon / health-app-demo

GNU General Public License v3.0
0 stars 0 forks source link

Sweep: add .env file in root of each project with all env variables . set default value for each env variable #1

Closed zanoon closed 11 months ago

zanoon commented 11 months ago
Checklist - [X] Create `api/django_project/django_project/.env` ✓ https://github.com/zanoon/health-app-demo/commit/72769f03ac2401bdab91d504030c68e94d0e5c9f [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/.env) - [X] Running GitHub Actions for `api/django_project/django_project/.env` ✓ [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/.env) - [X] Modify `api/django_project/django_project/settings.py` ✓ https://github.com/zanoon/health-app-demo/commit/93556d7c26945aee04b317eb383d784a7881721b [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/settings.py) - [X] Running GitHub Actions for `api/django_project/django_project/settings.py` ✓ [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/settings.py) - [X] Modify `api/django_project/django_project/logging_handler.py` ✓ https://github.com/zanoon/health-app-demo/commit/6a6dcf5a8bb023e96089ae36e4e69de67320c599 [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/logging_handler.py#L54-L71) - [X] Running GitHub Actions for `api/django_project/django_project/logging_handler.py` ✓ [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/api/django_project/django_project/logging_handler.py#L54-L71) - [X] Modify `base.yml` ✓ https://github.com/zanoon/health-app-demo/commit/2a720b6ab4b5c70ca3a20ef1f39eb36dcbd77e85 [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/base.yml) - [X] Running GitHub Actions for `base.yml` ✓ [Edit](https://github.com/zanoon/health-app-demo/edit/sweep/add_env_file_in_root_of_each_project_wit/base.yml)
sweep-ai[bot] commented 11 months ago

🚀 Here's the PR! #3

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 5fb26486a3)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).
Install Sweep Configs: Pull Request

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for a8f0a0d
Checking api/django_project/django_project/settings.py for syntax errors... ✅ api/django_project/django_project/settings.py has no syntax errors! 1/1 ✓
Checking api/django_project/django_project/settings.py for syntax errors...
✅ api/django_project/django_project/settings.py has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/zanoon/health-app-demo/blob/a8f0a0d3a4af2647a6ad9955dc253632be59bfc9/api/django_project/django_project/logging_handler.py#L54-L70 https://github.com/zanoon/health-app-demo/blob/a8f0a0d3a4af2647a6ad9955dc253632be59bfc9/base.yml#L1-L29 https://github.com/zanoon/health-app-demo/blob/a8f0a0d3a4af2647a6ad9955dc253632be59bfc9/api/django_project/django_project/settings.py#L1-L250

Step 2: ⌨️ Coding

Ran GitHub Actions for 72769f03ac2401bdab91d504030c68e94d0e5c9f:

--- 
+++ 
@@ -25,11 +25,11 @@
 SECRET_KEY = "django-insecure-p9s3h@$1k6gs4uj!qyp$^9f6nttydour71(cq5=83ti(j1r*s4"
 TESTING = "test" in sys.argv
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = literal_eval(os.environ.get("DEBUG_MODE", "True"))
-
-ALLOWED_HOSTS = literal_eval(os.environ.get("ALLOWED_HOST", "['*']"))
+DEBUG = literal_eval(os.getenv("DEBUG_MODE", "True"))
+
+ALLOWED_HOSTS = literal_eval(os.getenv("ALLOWED_HOST", "['*']"))
 CORS_ALLOWED_ORIGINS = literal_eval(
-    os.environ.get("CORS_ALLOWED_ORIGINS", "['http://localhost:3000']")
+    os.getenv("CORS_ALLOWED_ORIGINS", "['http://localhost:3000']")
 )

@@ -95,19 +95,19 @@
 DATABASES = {
     "default": {
         "ENGINE": "django.db.backends.postgresql",
-        "NAME": os.environ.get("DATABASE_NAME", "maindb"),
-        "USER": os.environ.get("DATABASE_USER", "admin_user"),
-        "PASSWORD": os.environ.get("DATABASE_PASSWORD", "password123*"),
-        "HOST": os.environ.get("DATABASE_HOST", "localhost"),
-        "PORT": os.environ.get("DATABASE_PORT", "5432"),
+        "NAME": os.getenv("DATABASE_NAME", "maindb"),
+        "USER": os.getenv("DATABASE_USER", "admin_user"),
+        "PASSWORD": os.getenv("DATABASE_PASSWORD", "password123*"),
+        "HOST": os.getenv("DATABASE_HOST", "localhost"),
+        "PORT": os.getenv("DATABASE_PORT", "5432"),
     }
 }

 ELASTIC_SEARCH = {
-    "host": os.environ.get("ELASTIC_SEARCH_HOST", "localhost"),
+    "host": os.getenv("ELASTIC_SEARCH_HOST", "localhost"),
     "port": 9200,
-    "user": os.environ.get("ELASTIC_SEARCH_USER", ""),
-    "password": os.environ.get("ELASTIC_SEARCH_PASSWORD", ""),
+    "user": os.getenv("ELASTIC_SEARCH_USER", ""),
+    "password": os.getenv("ELASTIC_SEARCH_PASSWORD", ""),
 }

 # Password validation
@@ -155,8 +155,8 @@

 DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

-CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379/0")
-CELERY_RESULT_BACKEND = os.environ.get(
+CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
+CELERY_RESULT_BACKEND = os.getenv(
     "CELERY_RESULT_URL",
     "redis://localhost:6379/0",
 )
@@ -170,7 +170,7 @@
     "default": {
         "BACKEND": "channels_redis.core.RedisChannelLayer",
         "CONFIG": {
-            "hosts": [(os.environ.get("CHANNELS_URLS", "redis://localhost:6379/0"))],
+            "hosts": [(os.getenv("CHANNELS_URLS", "redis://localhost:6379/0"))],
         },
     },
 }
@@ -178,7 +178,7 @@
 CACHES = {
     "default": {
         "BACKEND": "django.core.cache.backends.redis.RedisCache",
-        "LOCATION": os.environ.get("CHANNELS_URLS", "redis://localhost:6379/0"),
+        "LOCATION": os.getenv("CHANNELS_URLS", "redis://localhost:6379/0"),
     }
 }

@@ -193,27 +193,27 @@
     "PAGE_SIZE": 50,
 }

-GMAPS_API_KEY = os.environ.get("GMAPS_API_KEY", "")
-MAILGUN_API_KEY = os.environ.get("MAILGUN_API_KEY", "")
-MAILGUN_DOMAIN = os.environ.get("MAILGUN_DOMAIN", "")
-
-BUCKET_NAME = os.environ.get("BUCKET_NAME", "")
-BUCKET_USERNAME = os.environ.get("BUCKET_USERNAME", "")
-BUCKET_KEY = os.environ.get("BUCKET_KEY", "")
-BUCKET_SECRET = os.environ.get("BUCKET_SECRET", "")
-BUCKET_ENDPOINT = os.environ.get("BUCKET_ENDPOINT", "")
-BUCKET_REGION = os.environ.get("BUCKET_REGION", "uk")
+GMAPS_API_KEY = os.getenv("GMAPS_API_KEY", "")
+MAILGUN_API_KEY = os.getenv("MAILGUN_API_KEY", "")
+MAILGUN_DOMAIN = os.getenv("MAILGUN_DOMAIN", "")
+
+BUCKET_NAME = os.getenv("BUCKET_NAME", "")
+BUCKET_USERNAME = os.getenv("BUCKET_USERNAME", "")
+BUCKET_KEY = os.getenv("BUCKET_KEY", "")
+BUCKET_SECRET = os.getenv("BUCKET_SECRET", "")
+BUCKET_ENDPOINT = os.getenv("BUCKET_ENDPOINT", "")
+BUCKET_REGION = os.getenv("BUCKET_REGION", "uk")

 LOGIN_URL = "/admin/login/"
-AUTH0_DOMAIN = os.environ.get("AUTH_DOMAIN", "")
-AUTH0_IDENTIFIER = os.environ.get("AUTH_IDENTIFIER", "")
-AUTH0_STAFF_APP_CLIENT_ID = os.environ.get("AUTH0_STAFF_APP_CLIENT_ID", "")
-AUTH0_CUSTOMER_APP_CLIENT_ID = os.environ.get("AUTH0_CUSTOMER_APP_CLIENT_ID", "")
-AUTH0_STAFF_APP_CONNECTION_ID = os.environ.get("AUTH0_STAFF_APP_CONNECTION_ID", "")
-AUTH0_M2M_CLIENT_ID = os.environ.get("AUTH0_M2M_CLIENT_ID", "")
-AUTH0_M2M_CLIENT_SECRET = os.environ.get("AUTH0_M2M_CLIENT_SECRET", "")
-AUTH0_STAFF_ROLE_ID = os.environ.get("AUTH0_STAFF_ROLE_ID", "")
-AUTH0_PATIENT_ROLE_ID = os.environ.get("AUTH0_PATIENT_ROLE_ID", "")
+AUTH0_DOMAIN = os.getenv("AUTH_DOMAIN", "")
+AUTH0_IDENTIFIER = os.getenv("AUTH_IDENTIFIER", "")
+AUTH0_STAFF_APP_CLIENT_ID = os.getenv("AUTH0_STAFF_APP_CLIENT_ID", "")
+AUTH0_CUSTOMER_APP_CLIENT_ID = os.getenv("AUTH0_CUSTOMER_APP_CLIENT_ID", "")
+AUTH0_STAFF_APP_CONNECTION_ID = os.getenv("AUTH0_STAFF_APP_CONNECTION_ID", "")
+AUTH0_M2M_CLIENT_ID = os.getenv("AUTH0_M2M_CLIENT_ID", "")
+AUTH0_M2M_CLIENT_SECRET = os.getenv("AUTH0_M2M_CLIENT_SECRET", "")
+AUTH0_STAFF_ROLE_ID = os.getenv("AUTH0_STAFF_ROLE_ID", "")
+AUTH0_PATIENT_ROLE_ID = os.getenv("AUTH0_PATIENT_ROLE_ID", "")

 JWT_AUTH = {
     "JWT_PAYLOAD_GET_USERNAME_HANDLER": "django_project.auth_utils.jwt_get_username_from_payload_handler",
@@ -224,11 +224,11 @@
     "JWT_AUTH_HEADER_PREFIX": "Bearer",
 }

-OTLP_ENDPOINT = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT", "")
-OTLP_IS_SECURE = os.environ.get("OTLP_IS_SECURE", False)
-OTEL_SERVICE_NAME = os.environ.get("OTEL_SERVICE_NAME", "")
-DD_ENV = os.environ.get("DD_ENV", "")
-DD_VERSION = os.environ.get("DD_VERSION", "")
+OTLP_ENDPOINT = os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT", "")
+OTLP_IS_SECURE = os.getenv("OTLP_IS_SECURE", False)
+OTEL_SERVICE_NAME = os.getenv("OTEL_SERVICE_NAME", "")
+DD_ENV = os.getenv("DD_ENV", "")
+DD_VERSION = os.getenv("DD_VERSION", "")

 if not DEBUG:
     LOGGING = {

Ran GitHub Actions for 93556d7c26945aee04b317eb383d784a7881721b:

--- 
+++ 
@@ -1,4 +1,5 @@
 from django.conf import settings
+import os
 from django.core.exceptions import ImproperlyConfigured
 from opentelemetry import trace
 from opentelemetry._logs import set_logger_provider
@@ -59,7 +60,7 @@

         try:
             # load and return
-            return getattr(settings, var)
+            return os.getenv(var, default)
         except AttributeError:
             # setting is not defined
             if default is not None:

Ran GitHub Actions for 6a6dcf5a8bb023e96089ae36e4e69de67320c599:

--- 
+++ 
@@ -4,27 +4,27 @@
     env_file:
       - .env
     environment:
-      DATABASE_NAME: ${DATABASE_NAME}
-      DATABASE_USER: ${DATABASE_USER}
-      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
-      DATABASE_HOST: ${DATABASE_HOST}
-      DATABASE_PORT: ${DATABASE_PORT}
-      CELERY_BROKER_URL: ${CELERY_BROKER_URL}
-      CELERY_RESULT_URL: ${CELERY_RESULT_URL}
-      CHANNELS_URLS: ${CHANNELS_URLS}
-      ELASTIC_SEARCH_HOST: ${ELASTIC_SEARCH_HOST}
-      AUTH_DOMAIN: ${AUTH_DOMAIN}
-      AUTH_IDENTIFIER: ${AUTH_IDENTIFIER}
-      DD_ENV: ${DD_ENV}
-      DD_TRACE_ENABLED: ${DD_TRACE_ENABLED}
-      FLOWER_USER: ${FLOWER_USER}
-      FLOWER_PASSWORD: ${FLOWER_PASSWORD}
-      DJANGO_HOT_RELOAD: ${DJANGO_HOT_RELOAD}
-      GMAPS_API_KEY: ${GMAPS_API_KEY}
-      BUCKET_NAME: ${BUCKET_NAME}
-      BUCKET_USERNAME: ${BUCKET_USERNAME}
-      BUCKET_KEY: ${BUCKET_KEY}
-      BUCKET_SECRET: ${BUCKET_SECRET}
-      BUCKET_ENDPOINT: ${BUCKET_ENDPOINT}
-      SENDGRID_API_KEY: ${SENDGRID_API_KEY}
-      CELERY_QUEUE: ${CELERY_QUEUE}
+      DATABASE_NAME: $(shell source .env; echo $$DATABASE_NAME)
+      DATABASE_USER: $(shell source .env; echo $$DATABASE_USER)
+      DATABASE_PASSWORD: $(shell source .env; echo $$DATABASE_PASSWORD)
+      DATABASE_HOST: $(shell source .env; echo $$DATABASE_HOST)
+      DATABASE_PORT: $(shell source .env; echo $$DATABASE_PORT)
+      CELERY_BROKER_URL: $(shell source .env; echo $$CELERY_BROKER_URL)
+      CELERY_RESULT_URL: $(shell source .env; echo $$CELERY_RESULT_URL)
+      CHANNELS_URLS: $(shell source .env; echo $$CHANNELS_URLS)
+      ELASTIC_SEARCH_HOST: $(shell source .env; echo $$ELASTIC_SEARCH_HOST)
+      AUTH_DOMAIN: $(shell source .env; echo $$AUTH_DOMAIN)
+      AUTH_IDENTIFIER: $(shell source .env; echo $$AUTH_IDENTIFIER)
+      DD_ENV: $(shell source .env; echo $$DD_ENV)
+      DD_TRACE_ENABLED: $(shell source .env; echo $$DD_TRACE_ENABLED)
+      FLOWER_USER: $(shell source .env; echo $$FLOWER_USER)
+      FLOWER_PASSWORD: $(shell source .env; echo $$FLOWER_PASSWORD)
+      DJANGO_HOT_RELOAD: $(shell source .env; echo $$DJANGO_HOT_RELOAD)
+      GMAPS_API_KEY: $(shell source .env; echo $$GMAPS_API_KEY)
+      BUCKET_NAME: $(shell source .env; echo $$BUCKET_NAME)
+      BUCKET_USERNAME: $(shell source .env; echo $$BUCKET_USERNAME)
+      BUCKET_KEY: $(shell source .env; echo $$BUCKET_KEY)
+      BUCKET_SECRET: $(shell source .env; echo $$BUCKET_SECRET)
+      BUCKET_ENDPOINT: $(shell source .env; echo $$BUCKET_ENDPOINT)
+      SENDGRID_API_KEY: $(shell source .env; echo $$SENDGRID_API_KEY)
+      CELERY_QUEUE: $(shell source .env; echo $$CELERY_QUEUE)

Ran GitHub Actions for 2a720b6ab4b5c70ca3a20ef1f39eb36dcbd77e85:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add_env_file_in_root_of_each_project_wit.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord