-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
404 additions
and
275 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from .classes import EnvVariables, Database, Timer | ||
import logging | ||
|
||
|
||
def setup_logging(): | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
|
||
__all__ = ['EnvVariables', 'Database', 'Timer'] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
This script contains data classes for code reusing | ||
""" | ||
import logging | ||
import time | ||
import os | ||
|
||
import psycopg2 | ||
|
||
|
||
class EnvVariables: | ||
required_env_vars = [ | ||
"DB_HOST", "DB_PORT", "DB_CSV", "DB_USER", "DB_ORPH", "DB_ZUUL", "DB_PASSWORD", "GITEA_TOKEN", "GITHUB_TOKEN", | ||
"GITHUB_FALLBACK_TOKEN" | ||
] | ||
|
||
def __init__(self): | ||
self.db_host = os.getenv("DB_HOST") | ||
self.db_port = os.getenv("DB_PORT") | ||
self.db_csv = os.getenv("DB_CSV") # main postgres db, open PRs tables for public and hybrid clouds are stored | ||
self.db_user = os.getenv("DB_USER") | ||
self.db_orph = os.getenv("DB_ORPH") | ||
self.db_zuul = os.getenv("DB_ZUUL") | ||
self.db_password = os.getenv("DB_PASSWORD") | ||
self.gitea_token = os.getenv("GITEA_TOKEN") | ||
self.github_token = os.getenv("GITHUB_TOKEN") | ||
self.github_fallback_token = os.getenv("GITHUB_FALLBACK_TOKEN") | ||
self.api_key = os.getenv("OTC_BOT_API") | ||
self.check_env_variables() | ||
|
||
def check_env_variables(self): | ||
for var in self.required_env_vars: | ||
if os.getenv(var) is None: | ||
raise Exception("Missing environment variable: %s" % var) | ||
|
||
|
||
class Database: | ||
def __init__(self, env): | ||
self.db_host = env.db_host | ||
self.db_port = env.db_port | ||
self.db_user = env.db_user | ||
self.db_password = env.db_password | ||
|
||
def connect_to_db(self, db_name): | ||
logging.info("Connecting to Postgres (%s)...", db_name) | ||
try: | ||
return psycopg2.connect( | ||
host=self.db_host, | ||
port=self.db_port, | ||
dbname=db_name, | ||
user=self.db_user, | ||
password=self.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 | ||
|
||
|
||
class Timer: | ||
def __init__(self): | ||
self.start_time = None | ||
self.end_time = None | ||
|
||
def start(self): | ||
self.start_time = time.time() | ||
|
||
def stop(self): | ||
self.end_time = time.time() | ||
self.report() | ||
|
||
def report(self): | ||
if self.start_time and self.end_time: | ||
execution_time = self.end_time - self.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 " | ||
":)") | ||
else: | ||
logging.error("Timer was not properly started or stopped") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
This script is an entry point for all other modules included in Eyes-on-Docs | ||
""" | ||
|
||
import argparse | ||
import sys | ||
from scripts import eod_1_otc_services_dict, eod_2_gitea_info, eod_3_github_info, eod_4_failed_zuul,\ | ||
eod_5_open_issues, eod_6_last_commit_info, eod_7_request_changes, eod_8_ecosystem_issues, eod_9_scheduler | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Eyes-on-Docs scripts run") | ||
parser.add_argument('--eod1', action='store_true', help='OTC services dict') | ||
parser.add_argument('--eod2', action='store_true', help='Gitea info') | ||
parser.add_argument('--eod3', action='store_true', help='Github info') | ||
parser.add_argument('--eod4', action='store_true', help='Failed Zuul') | ||
parser.add_argument('--eod5', action='store_true', help='Open issues') | ||
parser.add_argument('--eod6', action='store_true', help='Last commit info') | ||
parser.add_argument('--eod7', action='store_true', help='Request changes') | ||
parser.add_argument('--eod8', action='store_true', help='Ecosystem issues') | ||
parser.add_argument('--eod9', action='store_true', help='Scheduler') | ||
args = parser.parse_args() | ||
|
||
if args.eod1: | ||
eod_1_otc_services_dict.run() | ||
if args.eod2: | ||
eod_2_gitea_info.run() | ||
if args.eod3: | ||
eod_3_github_info.run() | ||
if args.eod4: | ||
eod_4_failed_zuul.run() | ||
if args.eod5: | ||
eod_5_open_issues.run() | ||
if args.eod6: | ||
eod_6_last_commit_info.run() | ||
if args.eod7: | ||
eod_7_request_changes.run() | ||
if args.eod8: | ||
eod_8_ecosystem_issues.run() | ||
if args.eod9: | ||
eod_9_scheduler.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.