Remove assumption all repos are remotes

This commit is contained in:
Avram Lubkin 2023-06-23 11:54:08 -04:00 коммит произвёл Avram Lubkin
Родитель 4584fb3878
Коммит d739dbcc18
3 изменённых файлов: 26 добавлений и 18 удалений

Просмотреть файл

@ -142,3 +142,13 @@ class DatabaseDriver:
# Add target
session.add(MonitoringSubjects(distroID=name, revision=revision))
LOGGER.info("Successfully added new revision '%s' for distro '%s'", revision, name)
def get_downstream_repos(self):
"""
Get the repos used in downstream targets
"""
with self.get_session() as session:
return tuple(
repo for (repo,) in session.query(MonitoringSubjects.distroID).distinct().all()
)

Просмотреть файл

@ -35,9 +35,15 @@ class Downstream:
repo = self.repo
# Add repos as a remote if not already added
# Add repos as a remote if not already added. Only if used in a downstream target
with self.database.get_session() as session:
for distro_id, url in session.query(Distros.distroID, Distros.repoLink).all():
for distro_id, url in (
session.query(Distros.distroID, Distros.repoLink)
.select_from(MonitoringSubjects)
.join(MonitoringSubjects.distro)
.distinct()
.all()
):
# Skip Debian for now
if distro_id not in self.repo.remotes and not distro_id.startswith("Debian"):
LOGGER.debug("Adding remote %s from %s", distro_id, url)
@ -45,9 +51,8 @@ class Downstream:
# Update stored revisions for repos as appropriate
LOGGER.info("Updating tracked revisions for each repo.")
with self.database.get_session() as session:
for (distro_id,) in session.query(Distros.distroID).all():
self.update_tracked_revisions(distro_id)
for _repo in self.database.get_downstream_repos():
self.update_tracked_revisions(_repo)
with self.database.get_session() as session:
subjects = session.query(MonitoringSubjects).all()

Просмотреть файл

@ -9,7 +9,7 @@ import re
import sys
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Tuple
from typing import Any, Dict, Tuple
import git
import openpyxl
@ -18,7 +18,7 @@ from openpyxl.cell.cell import Cell
from openpyxl.workbook.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet
from comma.database.model import Distros, MonitoringSubjects, PatchData
from comma.database.model import MonitoringSubjects, PatchData
from comma.util.tracking import get_filenames
@ -175,16 +175,6 @@ class Spreadsheet:
workbook.save(out_file)
LOGGER.info("Finished exporting!")
def get_distros(self) -> List[str]:
"""Collect the distros were tracking in the database."""
with self.database.get_session() as session:
# TODO (Issue 51): Handle Debian.
return [
distro
for (distro,) in session.query(Distros.distroID)
if not distro.startswith("Debian")
]
def get_fixed_patches(self, commit: str, commits: Dict[str, int]) -> str:
"""Get the fixed patches for the given commit."""
with self.database.get_session() as session:
@ -217,7 +207,10 @@ class Spreadsheet:
"""Update each row with the 'Fixes' and distro information."""
workbook, worksheet = get_workbook(in_file)
commits = self.get_db_commits()
distros = self.get_distros()
distros = tuple( # TODO (Issue 51): Handle Debian.
repo for repo in self.database.get_downstream_repos() if not repo.startswith("Debian")
)
for distro in distros:
try:
get_column(worksheet, distro)