Skip to content
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

add workflow for linters #64

Merged
merged 27 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint Code Base

on:
pull_request:
types:
- opened
- closed
- edited
- reopened
- synchronize

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Run linters
run: tox -e lint
43 changes: 25 additions & 18 deletions ecosystem_issues.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""
This script gathers info about github issues in infra repos, for ecosystem squad
"""

import logging
import os
import psycopg2
from github import Github
import time
import logging
from datetime import datetime, timedelta

import psycopg2
from github import Github

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

start_time = time.time()
Expand Down Expand Up @@ -32,7 +37,7 @@ def check_env_variables():


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 @@ -42,7 +47,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 @@ -62,9 +67,10 @@ def create_open_issues_table(conn, cur, table_name):
);'''
)
conn.commit()
logging.info(f"Table {table_name} has been created successfully")
logging.info("Table %s has been created successfully", table_name)
except psycopg2.Error as e:
logging.error(f"Tables creating: an error occurred while trying to create a table {table_name} in the database {db_name}: {e}")
logging.error("Tables creating: an error occurred while trying to create a table %s in the database \
%s: %s", table_name, db_name, e)


def insert_issue_data(conn, cur, table_name, repo, issue):
Expand All @@ -89,7 +95,7 @@ def insert_issue_data(conn, cur, table_name, repo, issue):
)
conn.commit()
except psycopg2.Error as e:
logging.error(f"Error inserting issue data: {e}")
logging.error("Error inserting issue data: %s", e)
conn.rollback()


Expand Down Expand Up @@ -123,20 +129,21 @@ def main(gorg, table_name, token):


if __name__ == "__main__":
gh_org_str = "opentelekomcloud"
issues_table = "open_issues_eco"
GH_ORG_STR = "opentelekomcloud"
ISSUES_TABLE = "open_issues_eco"

done = False
DONE = False
try:
main(gh_org_str, issues_table, github_token)
done = True
except:
main(gh_org_str, issues_table, github_fallback_token)
done = True
if done:
main(GH_ORG_STR, ISSUES_TABLE, github_token)
DONE = True
except Exception as e:
logging.error("Error has been occurred: %s", e)
main(GH_ORG_STR, ISSUES_TABLE, github_fallback_token)
DONE = True
if DONE:
logging.info("Github operations successfully done!")

end_time = time.time()
execution_time = end_time - start_time
minutes, seconds = divmod(execution_time, 60)
logging.info(f"Script executed in {int(minutes)} minutes {int(seconds)} seconds! Let's go drink some beer :)")
logging.info("Script executed in %s minutes %s seconds! Let's go drink some beer :)", int(minutes), int(seconds))
Loading