-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (53 loc) · 1.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import asyncio
import logging
from config import load_config
from database import models
from database.engine import get_dbsession
from database.models.enums import CiProviders, GitProviders
from services.fetch_data import FetchDataService
from services.process_data import ProcessDataService
from utils.logging_config import LOGGER_NAME, configure_logger
logger = logging.getLogger(LOGGER_NAME)
async def collect_data(config, dbsession, project):
fetch_service = FetchDataService(dbsession, config)
await fetch_service.sync_project(project)
logger.info("Finished syncing project data")
dbsession.flush()
def process_data(config, dbsession, project):
process_service = ProcessDataService(dbsession, config)
process_service.sync_project_metrics(project)
logger.info("Finished processing data")
dbsession.flush()
logger.info("Generating Workflow data plot")
process_service.plot_workflow_durations(project)
def create_base_classes(dbsession):
organization = models.Organization(name="codecov")
dbsession.add(organization)
project = models.Project(
ci_provider=CiProviders.circleci,
git_provider=GitProviders.github,
name="worker",
organization=organization,
label_analysis_job_name="ATS",
regular_tests_job_name="test",
)
dbsession.add(project)
dbsession.flush()
return project
async def main():
configure_logger(logger=logger)
config = load_config()
dbsession = get_dbsession()
project = (
dbsession.query(models.Project).filter(models.Project.name == "worker").first()
)
if project is None:
project = create_base_classes(dbsession)
await collect_data(config, dbsession, project)
process_data(config, dbsession, project)
# TODO: Actually save info in the DB
dbsession.commit()
logger.info("=> Project totals")
print(project.totals)
if __name__ == "__main__":
asyncio.run(main())