Skip to content

Commit

Permalink
now it works
Browse files Browse the repository at this point in the history
  • Loading branch information
ptichoid committed Jun 4, 2024
1 parent 9e81d17 commit 01bae29
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions gitea_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@

db_host = os.getenv("DB_HOST")
db_port = os.getenv("DB_PORT")
db_csv = os.getenv("DB_CSV") # this is main postgres db, where open PRs tables for both public and hybrid clouds are
# stored
db_orph = os.getenv(
"DB_ORPH") # this is dedicated db for orphans PRs (for both clouds) tables. This is so because grafana dashboards
# query limitations
db_csv = os.getenv("DB_CSV") # main postgres db, where open PRs tables for both public and hybrid clouds are stored
db_orph = os.getenv("DB_ORPH") # dedicated db for orphans PRs (for both clouds) tables
db_user = os.getenv("DB_USER")
db_password = os.getenv("DB_PASSWORD")

Expand Down Expand Up @@ -138,8 +135,8 @@ def get_repos(org, cur_csv, gitea_token, rtc_table):

def check_pull_requests_exist(org, repo):
try:
initial_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state=all&limit=1&token=\
{gitea_token}")
initial_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state=all&limit=1&token="
f"{gitea_token}")
initial_resp.raise_for_status()
pulls = json.loads(initial_resp.content.decode())
if not pulls:
Expand Down Expand Up @@ -178,8 +175,8 @@ def get_parent_pr(org, repo):
page = 1
while True:
try:
repo_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state=all&page={page}\
&limit=1000&token={gitea_token}")
repo_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state=all&page={page}"
f"&limit=1000&token={gitea_token}")
repo_resp.raise_for_status()
except requests.exceptions.RequestException as e:
logging.error(f"Error occurred while trying to get repo pull requests: {e}")
Expand Down Expand Up @@ -255,8 +252,8 @@ def get_pull_requests(org, repo):
page = 1
while True:
try:
pull_requests_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state={state}&page=\
{page}&limit=50&token={gitea_token}")
pull_requests_resp = session.get(f"{gitea_api_endpoint}/repos/{org}/{repo}/pulls?state={state}&page="
f"{page}&limit=50&token={gitea_token}")
pull_requests_resp.raise_for_status()
except requests.exceptions.RequestException as e:
logging.error(f"Child PRs: an error occurred while trying to get pull requests of {repo} repo: {e}")
Expand Down Expand Up @@ -412,13 +409,13 @@ def compare_csv_files(conn_csv, cur_csv, conn_orph, cur_orph, opentable):
cur_orph.execute(f"""
INSERT INTO public.{opentable}
("Parent PR Number", "Service Name", "Squad", "Auto PR URL", "Auto PR State", "If merged",
"Environment", "Parent PR State", "Parent PR merged")
"Environment", "Parent PR State", "Parent PR merged")
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", tuple(pr1))
conn_orph.commit()
except Exception as e:
logging.error(f"Open and orphans for ORPHANS and {opentable}: an error occurred while inserting"
f" into the orphaned_prs table: {e}")
logging.error(f"Open and orphans for ORPHANS and {opentable}: an error occurred while"
f" inserting into the orphaned_prs table: {e}")

elif pr1[0] == pr2[0] and pr1[4] == pr2[3] == "open":
if pr1 not in open_prs:
Expand All @@ -428,13 +425,13 @@ def compare_csv_files(conn_csv, cur_csv, conn_orph, cur_orph, opentable):
cur_csv.execute(f"""
INSERT INTO public.{opentable}
("Parent PR Number", "Service Name", "Squad", "Auto PR URL", "Auto PR State", "If merged",
"Environment", "Parent PR State", "Parent PR merged")
"Environment", "Parent PR State", "Parent PR merged")
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", tuple(pr1))
conn_csv.commit()
except Exception as e:
logging.error(f"Open and orphans for OPEN and {opentable}: an error occurred while inserting "
f"into the open_prs table: {e}")
logging.error(f"Open and orphans for OPEN and {opentable}: an error occurred while inserting"
f" into the open_prs table: {e}")


def gitea_pr_info(org, parent_pr_name):
Expand Down Expand Up @@ -478,7 +475,7 @@ def get_github_open_prs(github_org, conn_csv, cur_csv, opentable, string):
cur_csv.execute(
f"""
INSERT INTO {opentable} ("Parent PR Number", "Service Name", "Squad", "Auto PR URL",
"Auto PR State", "If merged", "Environment", "Parent PR State", "Parent PR merged")
"Auto PR State", "If merged", "Environment", "Parent PR State", "Parent PR merged")
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s);
""",
(parent_pr_num, name_service, squad, github_pr_url, auto_pr_state, merged, env,
Expand Down

0 comments on commit 01bae29

Please sign in to comment.