Skip to content

Commit

Permalink
Move issues to the correct statuses (#728)
Browse files Browse the repository at this point in the history
* Notify about testing status

Resolves: AlmaLinux/build-system#70

* Move create issue functionality in to web server

Resolves: AlmaLinux/build-system#193

* Move issue to the "Building" section

Resolves: AlmaLinux/build-system#185

* Move issue to the "Released" section

Resolves: AlmaLinux/build-system#191

* Add second type of issues from git-updater
  • Loading branch information
maccelf authored Mar 7, 2024
1 parent 786479a commit 26b10ce
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 9 deletions.
6 changes: 6 additions & 0 deletions alws/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class Settings(BaseSettings):
sentry_dsn: Optional[str] = None
sentry_traces_sample_rate: float = 0.2

github_integration_enabled: bool = False
github_token: Optional[str] = None
github_organization_name: str = 'AlmaLinux'
github_project_number: Optional[int] = None
github_default_repository_name: str = 'updates'

@property
def codenotary_enabled(self) -> bool:
return bool(self.immudb_username) and bool(self.immudb_password)
Expand Down
8 changes: 8 additions & 0 deletions alws/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ class SignStatusEnum(enum.IntEnum):
WRONG_SIGNATURE = 4


class GitHubIssueStatus(enum.Enum):
TODO = "Todo"
DEVELOPMENT = "In Development"
BUILDING = "Building"
TESTING = "Testing"
RELEASED = "Released"


class BeholderMatchMethod(enum.Enum):
EXACT = "exact"
CLOSEST = "closest"
Expand Down
50 changes: 44 additions & 6 deletions alws/crud/build_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

from alws import models
from alws.config import settings
from alws.constants import BuildTaskStatus, ErrataPackageStatus
from alws.constants import (
BuildTaskStatus,
ErrataPackageStatus,
GitHubIssueStatus,
)
from alws.errors import (
ArtifactChecksumError,
ArtifactConversionError,
Expand All @@ -23,6 +27,12 @@
)
from alws.schemas import build_node_schema
from alws.schemas.build_node_schema import BuildDoneArtifact
from alws.utils.github_integration_helper import (
find_issues_by_build_id,
find_issues_by_record_id,
get_github_client,
move_issues,
)
from alws.utils.modularity import IndexWrapper, RpmArtifact
from alws.utils.multilib import MultilibProcessor
from alws.utils.noarch import save_noarch_packages
Expand Down Expand Up @@ -323,6 +333,7 @@ async def get_srpm_artifact_by_build_task_id(
async def __process_rpms(
db: AsyncSession,
pulp_client: PulpClient,
build_id: int,
task_id: int,
task_arch: str,
task_artifacts: list,
Expand Down Expand Up @@ -410,6 +421,7 @@ def append_errata_package(_, errata_package, artifact, rpm_info):
for href, _, artifact in processed_packages
]
rpms_info = get_rpm_packages_info(rpms)
errata_record_ids = set()
for build_task_artifact in rpms:
rpm_info = rpms_info[build_task_artifact.href]
if rpm_info["arch"] != "src":
Expand Down Expand Up @@ -454,6 +466,31 @@ def append_errata_package(_, errata_package, artifact, rpm_info):
build_task_artifact,
rpm_info,
)
errata_record_ids.add(errata_package.errata_record_id)
if settings.github_integration_enabled:
try:
github_client = await get_github_client()
issues = await find_issues_by_record_id(
github_client=github_client,
record_ids=list(errata_record_ids),
)
issues.extend(
await find_issues_by_build_id(
github_client=github_client,
build_ids=[build_id],
)
)
if issues:
await move_issues(
github_client=github_client,
issues=issues,
status=GitHubIssueStatus.TESTING,
)
except Exception as err:
logging.exception(
"Cannot move issue to the Testing section: %s",
err,
)

# we need to put source RPM in module as well, but it can be skipped
# because it's built before
Expand Down Expand Up @@ -654,6 +691,7 @@ def _get_srpm_name(
rpm_entries = await __process_rpms(
db,
pulp_client,
build_task.build_id,
build_task.id,
build_task.arch,
rpm_artifacts,
Expand Down Expand Up @@ -780,10 +818,10 @@ async def __update_built_srpm_url(
):
# Set the error field to describe the reason why they are fast failing
fast_fail_msg = (
f"Fast failed: SRPM build failed in the initial "
"Fast failed: SRPM build failed in the initial "
f"architecture ({build_task.arch}). "
f"Please refer to the initial architecture build "
f"logs for more information about the failure."
"Please refer to the initial architecture build "
"logs for more information about the failure."
)
update_query = (
update(models.BuildTask)
Expand Down Expand Up @@ -860,9 +898,9 @@ async def fast_fail_other_tasks_by_ref(
if len(build_tasks) != len(uncompleted_tasks):
return
fast_fail_msg = (
f"Fast failed: build processing failed in the initial "
"Fast failed: build processing failed in the initial "
f"architecture ({current_task.arch}). Please refer to the initial "
f"architecture build logs for more information about the failure."
"architecture build logs for more information about the failure."
)
uncompleted_tasks_ids = [task.id for task in uncompleted_tasks]
await db.execute(
Expand Down
65 changes: 64 additions & 1 deletion alws/crud/errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ErrataPackageStatus,
ErrataReferenceType,
ErrataReleaseStatus,
GitHubIssueStatus,
)
from alws.dependencies import get_db, get_pulp_db
from alws.pulp_models import (
Expand All @@ -50,6 +51,12 @@
get_oval_title,
get_verbose_errata_title,
)
from alws.utils.github_integration_helper import (
create_github_issue,
find_issues_by_record_id,
get_github_client,
move_issues,
)
from alws.utils.parsing import clean_release, parse_rpm_nevra
from alws.utils.pulp_client import PulpClient
from alws.utils.pulp_utils import (
Expand Down Expand Up @@ -505,7 +512,7 @@ async def get_matching_albs_packages(
errata_package: models.NewErrataPackage,
prod_repos_cache,
module,
) -> List[models.NewErrataToALBSPackage]:
) -> List[models.ErrataToALBSPackage]:
items_to_insert = []
# We're going to check packages that match name-version-clean_release
# Note that clean_release doesn't include the .module... str, we match:
Expand Down Expand Up @@ -537,6 +544,24 @@ async def get_matching_albs_packages(
errata_package.source_srpm = src_nevra.name
items_to_insert.append(mapping)
errata_package.albs_packages.append(mapping)
if settings.github_integration_enabled:
try:
github_client = await get_github_client()
issues = await find_issues_by_record_id(
github_client,
[errata_package.errata_record_id],
)
if issues:
await move_issues(
github_client=github_client,
issues=issues,
status=GitHubIssueStatus.RELEASED,
)
except Exception as err:
logging.exception(
"Cannot move issue to the Released section: %s",
err,
)
return items_to_insert

# If we couldn't find any pkg in production repos
Expand Down Expand Up @@ -617,6 +642,7 @@ async def create_errata_record(db: AsyncSession, errata: BaseErrataRecord):
)
platform = platform.scalars().first()
items_to_insert = []
original_id = errata.id

# Rebranding RHEL -> AlmaLinux
for key in ("description", "title"):
Expand Down Expand Up @@ -674,6 +700,25 @@ async def create_errata_record(db: AsyncSession, errata: BaseErrataRecord):
)
items_to_insert.append(db_errata)

if settings.github_integration_enabled:
try:
github_client = await get_github_client()
await create_github_issue(
client=github_client,
title=errata.title,
description=errata.description,
advisory_id=alma_errata_id,
original_id=original_id,
platform_name=platform.name,
severity=errata.severity,
packages=errata.packages,
)
except Exception as err:
logging.exception(
"Cannot create GitHub issue: %s",
err,
)

# References
self_ref_exists = False
for ref in errata.references:
Expand Down Expand Up @@ -1479,6 +1524,24 @@ async def bulk_errata_records_release(records_ids: List[str]):
missing_pkg_names=missing_pkg_names,
force_flag=False,
)
if settings.github_integration_enabled:
try:
github_client = await get_github_client()
issues = await find_issues_by_record_id(
github_client,
[db_record.id],
)
if issues:
await move_issues(
github_client=github_client,
issues=issues,
status=GitHubIssueStatus.RELEASED,
)
except Exception as err:
logging.exception(
"Cannot move issue to the Released section: %s",
err,
)
if not tasks:
continue
repos_to_publish.extend(repo_mapping.keys())
Expand Down
44 changes: 43 additions & 1 deletion alws/dramatiq/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

from alws import models
from alws.build_planner import BuildPlanner
from alws.constants import DRAMATIQ_TASK_TIMEOUT, BuildTaskStatus
from alws.config import settings
from alws.constants import (
DRAMATIQ_TASK_TIMEOUT,
BuildTaskStatus,
GitHubIssueStatus,
)
from alws.crud import build_node as build_node_crud
from alws.crud import test
from alws.database import SyncSession
Expand All @@ -25,6 +30,12 @@
SrpmProvisionError,
)
from alws.schemas import build_node_schema, build_schema
from alws.utils.github_integration_helper import (
find_issues_by_repo_name,
get_github_client,
move_issues,
set_build_id_to_issues,
)

__all__ = ['start_build', 'build_done']

Expand Down Expand Up @@ -100,6 +111,37 @@ async def _start_build(build_id: int, build_request: build_schema.BuildCreate):
db.commit()
db.close()

if settings.github_integration_enabled:
try:
github_client = await get_github_client()
repos = set()
for task in build_request.tasks:
if isinstance(task, build_schema.BuildTaskModuleRef):
repos.add(f"module {task.module_name}")
continue

repos.add(f"{task.url} {task.git_ref}")
issues = await find_issues_by_repo_name(
github_client=github_client,
repo_names=list(repos),
)
if issues:
await set_build_id_to_issues(
github_client=github_client,
issues=issues,
build_id=build_id,
)
await move_issues(
github_client=github_client,
issues=issues,
status=GitHubIssueStatus.BUILDING,
)
except Exception as err:
logging.exception(
"Cannot move issue to the Building section: %s",
err,
)


async def _build_done(request: build_node_schema.BuildDone):
async for db in get_db():
Expand Down
24 changes: 24 additions & 0 deletions alws/release_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
BeholderMatchMethod,
ErrataPackageStatus,
ErrataReleaseStatus,
GitHubIssueStatus,
PackageNevra,
ReleasePackageTrustness,
ReleaseStatus,
Expand All @@ -44,6 +45,11 @@
from alws.schemas import release_schema
from alws.utils.beholder_client import BeholderClient
from alws.utils.debuginfo import clean_debug_name, is_debuginfo_rpm
from alws.utils.github_integration_helper import (
find_issues_by_build_id,
get_github_client,
move_issues,
)
from alws.utils.measurements import class_measure_work_time_async
from alws.utils.modularity import IndexWrapper, ModuleWrapper
from alws.utils.parsing import get_clean_distr_name
Expand Down Expand Up @@ -576,6 +582,24 @@ async def commit_release(
message += "\n".join(release_messages)
release.status = ReleaseStatus.COMPLETED
builds_released = True
if settings.github_integration_enabled:
try:
github_client = await get_github_client()
issues = await find_issues_by_build_id(
github_client=github_client,
build_ids=release.build_ids,
)
if issues:
await move_issues(
github_client=github_client,
issues=issues,
status=GitHubIssueStatus.RELEASED,
)
except Exception as err:
logging.exception(
"Cannot move issue to the Released section: %s",
err,
)

await self.db.execute(
update(models.Build)
Expand Down
1 change: 1 addition & 0 deletions alws/routers/errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sqlalchemy.ext.asyncio import AsyncSession

from alws.auth import get_current_user
from alws.config import settings
from alws.constants import ErrataReleaseStatus
from alws.crud import errata as errata_crud
from alws.dependencies import get_db
Expand Down
Loading

1 comment on commit 26b10ce

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total coverage

Coverage report for changed files •
FileStmtsMissCoverMissing
config.py590100% 
constants.py134794%95, 99, 169, 173, 206, 211, 216
release_planner.py82744546%81, 100, 103, 108–113, 133, 142–145, 151, 154, 162, 176, 184, 191, 199, 202–204, 207–208, 218, 226, 234, 277–280, 288–300, 304–317, 323–324, 332, 335–338, 341, 357, 423, 425, 442–443, 448, 467–469, 473–474, 478–483, 489–496, 498–499, 508–509, 511–513, 515–516, 520–522, 525–528, 534, 536–543, 556, 559, 567, 573–577, 586–588, 592–593, 598–599, 707, 718, 720–721, 726, 733–734, 738–745, 750–752, 756–759, 766–767, 769–771, 773–774, 777, 779, 789, 800, 831, 851, 894–895, 897, 913, 917–922, 1014, 1023–1029, 1045–1059, 1079, 1098, 1120, 1128, 1132, 1135, 1167–1168, 1176–1182, 1186–1187, 1192–1197, 1209–1210, 1218–1220, 1224, 1227–1229, 1233, 1236–1237, 1246, 1250, 1254–1258, 1262–1264, 1271–1273, 1277–1282, 1307–1309, 1313, 1315–1316, 1323–1325, 1327–1328, 1330, 1335, 1342–1346, 1350–1352, 1354, 1357, 1363–1365, 1371–1372, 1376–1385, 1394–1396, 1399, 1406–1409, 1415–1417, 1421–1422, 1430–1432, 1434–1435, 1443–1447, 1450, 1456–1457, 1460, 1469–1470, 1476–1489, 1500–1501, 1510–1514, 1519–1520, 1526–1527, 1531–1538, 1543, 1545–1546, 1551, 1557–1559, 1563–1566, 1568–1575, 1580–1583, 1590–1591, 1593, 1597, 1617, 1626–1628, 1630–1631, 1638, 1650, 1662, 1677–1680, 1695–1700, 1707–1709, 1712–1714, 1717–1723, 1726–1727, 1729–1731, 1738–1739, 1743–1744, 1751, 1754, 1768–1770, 1774, 1781, 1784, 1794, 1818, 1824–1825, 1837–1840, 1848–1850, 1856–1858
crud
   build_node.py46617662%48, 50, 53, 89–95, 103, 107, 116–124, 126–131, 133, 140–145, 147–153, 155–157, 159, 164–172, 175–178, 181–182, 185, 188–190, 194–195, 197–199, 204–206, 208–214, 217–218, 236, 240, 245, 249, 252–258, 262, 264–267, 275–278, 283, 291, 295, 300, 311, 316, 380–381, 384, 392–393, 396, 461, 471–473, 477, 483–484, 489–490, 510–511, 523–524, 531–533, 541, 550, 553–555, 643, 655–658, 670–672, 680–681, 738, 773–776, 820, 826, 833, 835, 840–841, 885, 891–892, 898–900, 905–906, 913, 940–943, 948–952, 975, 1052–1053
   errata.py67050125%79–85, 98–99, 102–110, 115, 118, 122–123, 129, 139, 142–143, 145–146, 151–152, 156–157, 163, 168, 172–180, 185–187, 190–211, 214–222, 225, 233–234, 238–240, 243–250, 252–253, 320–328, 332, 335–339, 342–355, 358–367, 370, 373–378, 381–392, 395–396, 400–404, 407, 432, 436, 454–461, 468–478, 486, 491–493, 495–497, 500–502, 504–507, 534, 543–550, 554–555, 560–561, 565, 581–582, 605–608, 615, 619–620, 629–633, 704–706, 716–717, 756, 812, 821, 830, 844–846, 852, 864–870, 873–876, 882–883, 886–887, 890–891, 894–896, 898, 911–913, 927–934, 938, 942–945, 957–958, 962, 964–981, 995–1000, 1009–1014, 1024, 1028, 1031, 1068, 1073–1075, 1087–1089, 1106–1107, 1121, 1134–1138, 1141, 1156–1162, 1171–1175, 1179–1181, 1189–1191, 1205, 1215–1219, 1223–1229, 1233–1238, 1242–1244, 1246–1253, 1258–1260, 1270–1278, 1284–1286, 1294–1296, 1301, 1312–1319, 1323, 1337, 1350, 1354, 1361, 1365–1369, 1371, 1376, 1378–1379, 1381, 1391, 1395, 1400, 1402–1405, 1408–1410, 1412–1415, 1420–1421, 1426–1431, 1433, 1439, 1441, 1450–1451, 1455, 1460–1463, 1471, 1473, 1475, 1478–1480, 1484, 1486, 1491–1494, 1499–1500, 1504–1508, 1510, 1517–1518, 1527–1530, 1534–1535, 1540–1541, 1545–1553, 1556, 1571, 1596, 1637, 1642, 1650, 1669–1673, 1679, 1686–1687, 1695–1696
dramatiq
   build.py1145452%106–108, 115–121, 123–124, 128–129, 134, 139–140, 147–151, 157, 168–172, 178, 182–184, 191–195, 200–201, 206, 210–211, 222, 228–229, 237, 253, 259–261, 271–272, 289–290
routers
   errata.py682957%36, 45, 50–51, 55, 64, 78, 106, 118, 128–129, 146–147, 150–151, 164, 169–177, 186–187, 200–201
utils
   github_integration_helper.py776416%19–22, 26, 32–33, 40–43, 46–54, 61–64, 67–72, 79–89, 97–100, 112–114, 124–130, 143, 149–152, 157, 160–162
TOTAL9852435555% 

Tests Skipped Failures Errors Time
81 2 💤 0 ❌ 0 🔥 42.415s ⏱️

Please sign in to comment.