Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ptichoid committed Jun 4, 2024
1 parent 1f8ef66 commit 7412f59
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
91 changes: 46 additions & 45 deletions gitea_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def csv_erase(filenames):
else:
continue
except Exception as e:
logging.error(f"CSV erase: error has been occured: {e}")
logging.error("CSV erase: error has been occured: %s", e)


def connect_to_db(db_name):
logging.info(f"Connecting to Postgres ({db_name})...")
logging.info("Connecting to Postgres (%s)...", db_name)
try:
return psycopg2.connect(
host=db_host,
Expand All @@ -68,7 +68,7 @@ def connect_to_db(db_name):
password=db_password
)
except psycopg2.Error as e:
logging.error(f"Connecting to Postgres: an error occurred while trying to connect to the database: {e}")
logging.error("Connecting to Postgres: an error occurred while trying to connect to the database: %s", e)
return None


Expand All @@ -91,8 +91,8 @@ def create_prs_table(conn_csv, cur_csv, table_name):
conn_csv.commit()
logging.info(f"Table {table_name} has been created successfully")
except psycopg2.Error as e:
logging.error(f"Tables creating: an error occurred while trying to create a table {table_name} in the database:"
f" {e}")
logging.error("Tables creating: an error occurred while trying to create a table %s in the database: %s",
table_name, e)


def get_repos(org, cur_csv, gitea_token, rtc_table):
Expand All @@ -102,7 +102,7 @@ def get_repos(org, cur_csv, gitea_token, rtc_table):
cur_csv.execute(f"SELECT DISTINCT \"Title\" FROM {rtc_table} WHERE \"Env\" IN ('internal', 'hidden');")
exclude_repos = [row[0] for row in cur_csv.fetchall()]
except Exception as e:
logging.error(f"Fetching exclude repos for internal services: {e}")
logging.error("Fetching exclude repos for internal services: %s", e)
return repos

page = 1
Expand All @@ -112,13 +112,13 @@ def get_repos(org, cur_csv, gitea_token, rtc_table):
repos_resp = session.get(f"{GITEA_API_ENDPOINT}/orgs/{org}/repos?page={page}&limit=50&token={gitea_token}")
repos_resp.raise_for_status()
except requests.exceptions.RequestException as e:
logging.error(f"Get repos: an error occurred while trying to get repos: {e}")
logging.error("Get repos: an error occurred while trying to get repos: %s", e)
break

try:
repos_dict = json.loads(repos_resp.content.decode())
except json.JSONDecodeError as e:
logging.error(f"JSON decode: an error occurred while trying to decode JSON: {e}")
logging.error("JSON decode: an error occurred while trying to decode JSON: %s", e)
break

for repo in repos_dict:
Expand All @@ -133,7 +133,7 @@ def get_repos(org, cur_csv, gitea_token, rtc_table):
else:
page += 1

logging.info(f"{len(repos)} repos have been processed")
logging.info("%s repos have been processed", len(repos))
return repos


Expand All @@ -144,18 +144,18 @@ def check_pull_requests_exist(org, repo):
initial_resp.raise_for_status()
pulls = json.loads(initial_resp.content.decode())
if not pulls:
logging.info(f"No pull requests found in {repo}. Skipping.")
logging.info("No pull requests found in %s. Skipping.", repo)
return False
return True
except requests.exceptions.HTTPError as e:
if e.response.status_code == 404:
logging.info(f"No repository or pull requests found in {repo} (404 error). Skipping.")
logging.info("No repository or pull requests found in %s (404 error). Skipping.", repo)
return False
else:
logging.error(f"Error checking pull requests in {repo}: {e}")
logging.error("Error checking pull requests in %s: %s", repo, e)
return False
except requests.exceptions.RequestException as e:
logging.error(f"Unexpected error when checking pull requests in {repo}: {e}")
logging.error("Unexpected error when checking pull requests in %s: %s", repo, e)
return False


Expand All @@ -173,7 +173,7 @@ def get_parent_pr(org, repo):
csv_2 = open("proposalbot_prs.csv", "a")
csv_writer = csv.writer(csv_2)
except IOError as e:
logging.error(f"Proposalbot_prs.csv: an error occurred while trying to open or write to CSV file: {e}")
logging.error("Proposalbot_prs.csv: an error occurred while trying to open or write to CSV file: %s", e)
return
if repo != "doc-exports" and repo != "dsf":
page = 1
Expand All @@ -183,13 +183,13 @@ def get_parent_pr(org, repo):
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}")
logging.error("Error occurred while trying to get repo pull requests: %s", e)
break

try:
pull_request = json.loads(repo_resp.content.decode())
except json.JSONDecodeError as e:
logging.error(f"Error occurred while trying to decode JSON: {e}")
logging.error("Error occurred while trying to decode JSON: %s", e)
break

dependency_pull_requests = []
Expand All @@ -212,7 +212,7 @@ def get_parent_pr(org, repo):
try:
csv_writer.writerow([parent_pr, service, auto_url, auto_state, if_merged, env])
except csv.Error as e:
logging.error(f"Error occurred while trying to write to CSV file: {e}")
logging.error("Error occurred while trying to write to CSV file: %s", e)
break
link_header = repo_resp.headers.get("Link")
if link_header is None or "rel=\"next\"" not in link_header:
Expand All @@ -223,7 +223,7 @@ def get_parent_pr(org, repo):
csv_2.close()

except IOError as e:
logging.error(f"Error occurred while trying to close CSV file: {e}")
logging.error("Error occurred while trying to close CSV file: %s", e)


def extract_number_from_body(text):
Expand All @@ -232,10 +232,10 @@ def extract_number_from_body(text):
if match:
return int(match.group()[1:])
except ValueError as e:
logging.error(f"An error occurred while converting match group to int: {e}")
logging.error("An error occurred while converting match group to int: %s", e)
return None
except re.error as e:
logging.error(f"An error occurred while searching text: {e}")
logging.error("An error occurred while searching text: %s", e)
return None
return None

Expand All @@ -249,7 +249,7 @@ def get_pull_requests(org, repo):
csv_writer = csv.writer(csv_file)
csv_writer.writerow(["Parent PR index", "Parent PR title", "Parent PR URL", "Parent PR state", "If merged"])
except IOError as e:
logging.error(f"Child PRs: an error occurred while opening or writing to the CSV file: {e}")
logging.error("Child PRs: an error occurred while opening or writing to the CSV file: %s", e)
return pull_requests

for state in states:
Expand All @@ -260,13 +260,14 @@ def get_pull_requests(org, repo):
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}")
logging.error("Child PRs: an error occurred while trying to get pull requests of %s repo: %s",
repo, e)
break

try:
pull_requests = json.loads(pull_requests_resp.content.decode("utf-8"))
except json.JSONDecodeError as e:
logging.error(f"Child PRs: an error occurred while trying to decode JSON: {e}")
logging.error("Child PRs: an error occurred while trying to decode JSON: %s", e)
break

for pr in pull_requests:
Expand All @@ -278,7 +279,7 @@ def get_pull_requests(org, repo):
try:
csv_writer.writerow([index, title, url, state, if_merged])
except csv.Error as e:
logging.error(f"Child PRs: an error occurred while trying to write to CSV file: {e}")
logging.error("Child PRs: an error occurred while trying to write to CSV file: %s", e)
break

link_header = pull_requests_resp.headers.get("Link")
Expand All @@ -289,27 +290,27 @@ def get_pull_requests(org, repo):
try:
csv_file.close()
except IOError as e:
logging.error(f"Child PRs: n error occurred while trying to close CSV file: {e}")
logging.error("Child PRs: n error occurred while trying to close CSV file: %s", e)

return pull_requests


def fetch_repo_title_category(cur_csv, rtctable):
logging.info(f"Fetching RTC table {rtctable}...")
logging.info("Fetching RTC table %s...", rtctable)
try:
cur_csv.execute(f"SELECT * FROM {rtctable}")
return cur_csv.fetchall()
except Exception as e:
logging.error(f"Fetch: an error occurred while trying to fetch data from the table: {e}")
logging.error("Fetch: an error occurred while trying to fetch data from the table: %s", e)
return None


def update_service_titles(cur_csv, rtctable):
logging.info(f"Updating service titles using {rtctable}..")
logging.info("Updating service titles using %s..", rtctable)
try:
repo_title_category = fetch_repo_title_category(cur_csv, rtctable)
except Exception as e:
logging.error(f"Titles: an error occurred while fetching repo title category: {e}")
logging.error("Titles: an error occurred while fetching repo title category: %s", e)
return

try:
Expand All @@ -323,10 +324,10 @@ def update_service_titles(cur_csv, rtctable):
title_index = header.index("Service Name")
row[title_index] = title
except IOError as e:
logging.error(f"Titles: an error occurred while reading the file: {e}")
logging.error("Titles: an error occurred while reading the file: %s", e)
return
except Exception as e:
logging.error(f"Titles: an unexpected error occurred: {e}")
logging.error("Titles: an unexpected error occurred: %s", e)
return

try:
Expand All @@ -335,10 +336,10 @@ def update_service_titles(cur_csv, rtctable):
writer.writerow(header)
writer.writerows(rows)
except IOError as e:
logging.error(f"Titles: an error occurred while writing to the file: {e}")
logging.error("Titles: an error occurred while writing to the file: %s", e)
return
except Exception as e:
logging.error(f"Titles: an unexpected error occurred: {e}")
logging.error("Titles: an unexpected error occurred: %s", e)
return


Expand All @@ -347,7 +348,7 @@ def add_squad_column(cur_csv, rtctable):
try:
repo_title_category = fetch_repo_title_category(cur_csv, rtctable)
except Exception as e:
logging.error(f"Squad column: an error occurred while fetching repo title category: {e}")
logging.error("Squad column: an error occurred while fetching repo title category: %s", e)
return

try:
Expand All @@ -362,10 +363,10 @@ def add_squad_column(cur_csv, rtctable):
if title == name_service:
row.insert(2, squad)
except IOError as e:
logging.error(f"Squad column: an error occurred while reading the file: {e}")
logging.error("Squad column: an error occurred while reading the file: %s", e)
return
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
logging.error("An unexpected error occurred: %s", e)
return

try:
Expand All @@ -374,10 +375,10 @@ def add_squad_column(cur_csv, rtctable):
writer.writerow(header)
writer.writerows(rows)
except IOError as e:
logging.info(f"Squad column: an error occurred while writing to the file: {e}")
logging.info("Squad column: an error occurred while writing to the file: %s", e)
return
except Exception as e:
logging.error(f"Squad column: an unexpected error occurred: {e}")
logging.error("Squad column: an unexpected error occurred: %s", e)
return


Expand All @@ -398,7 +399,7 @@ def compare_csv_files(conn_csv, cur_csv, conn_orph, cur_orph, opentable):
doc_exports_prs.append(row)

except IOError as e:
logging.error(f"Open and orphans for {opentable}: an error occurred while trying to read the file: {e}")
logging.error("Open and orphans for %s: an error occurred while trying to read the file: %s", opentable, e)
return

orphaned = []
Expand All @@ -418,8 +419,8 @@ def compare_csv_files(conn_csv, cur_csv, conn_orph, cur_orph, opentable):
""", tuple(pr1))
conn_orph.commit()
except Exception as e:
logging.error(f"Open and orphans for ORPHANS and {opentable}: an error occurred while"
f" inserting into the orphaned_prs table: {e}")
logging.error("Open and orphans for ORPHANS and %s: an error occurred while inserting into "
"the orphaned_prs table: %s", opentable, e)

elif pr1[0] == pr2[0] and pr1[4] == pr2[3] == "open":
if pr1 not in open_prs:
Expand All @@ -434,8 +435,8 @@ def compare_csv_files(conn_csv, cur_csv, conn_orph, cur_orph, opentable):
""", 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("Open and orphans for OPEN and %s: an error occurred while inserting"
" into the open_prs table: %s", opentable, e)


def gitea_pr_info(org, parent_pr_name):
Expand All @@ -453,7 +454,7 @@ def gitea_pr_info(org, parent_pr_name):


def get_github_open_prs(github_org, conn_csv, cur_csv, opentable, string):
logging.info(f"Gathering Github open PRs for {string}...")
logging.info("Gathering Github open PRs for %s...", string)

if not github_org or not conn_csv or not cur_csv:
logging.error("Github PRs: error: Invalid input parameters.")
Expand Down Expand Up @@ -517,7 +518,7 @@ def update_squad_and_title(cursors, conns, rtctable, opentable):
conn.commit()

except Exception as e:
logging.error(f"Error updating squad and title: {e}")
logging.error("Error updating squad and title: %s", e)


def main(org, gh_org, rtctable, opentable, string, token):
Expand Down
Loading

0 comments on commit 7412f59

Please sign in to comment.