-
Notifications
You must be signed in to change notification settings - Fork 1
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
New script requested_changes #65
Conversation
YustinaKvr
commented
Jun 12, 2024
- Script requested_changes.py has been added
db_host = os.getenv("DB_HOST") | ||
db_port = os.getenv("DB_PORT") | ||
db_csv = os.getenv("DB_CSV") # main postgres db, where open PRs tables for both public and hybrid clouds are stored | ||
db_user = os.getenv("DB_USER") | ||
db_password = os.getenv("DB_PASSWORD") | ||
|
||
|
||
def check_env_variables(): | ||
required_env_vars = [ | ||
"DB_HOST", "DB_PORT", | ||
"DB_CSV", "DB_USER", "DB_PASSWORD", "GITEA_TOKEN" | ||
] | ||
for var in required_env_vars: | ||
if os.getenv(var) is None: | ||
raise Exception("Missing environment variable: %s", var) | ||
|
||
|
||
def connect_to_db(db_name): | ||
logging.info("Connecting to Postgres (%s)...", db_name) | ||
try: | ||
return psycopg2.connect( | ||
host=db_host, | ||
port=db_port, | ||
dbname=db_name, | ||
user=db_user, | ||
password=db_password | ||
) | ||
except psycopg2.Error as e: | ||
logging.error("Connecting to Postgres: an error occurred while trying to connect to the database: %s", e) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand why are you using same code in all files, please introduce db class and reuse it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for env variables
org_string = "docs" | ||
rtc_table = "repo_title_category" | ||
changes_table = "requested_changes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if using const, better not to store them here, move to first lines and probably good to have ability to change them through env variables
main(org_string, rtc_table, changes_table) | ||
main(f"{org_string}-swiss", f"{rtc_table}_swiss", f"{changes_table}_swiss") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use for cycle by dictionary with envs, in case that in future there will be more environments and add logging for each call. Also main is a bad name for this func