Skip to content

Commit

Permalink
Store number of found defects for OSH scans
Browse files Browse the repository at this point in the history
Fixes #2625
  • Loading branch information
lbarcziova committed Nov 14, 2024
1 parent c0efa63 commit 2c2c8e2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add issues_added_count for OSHScanModel
Revision ID: f69687c314c5
Revises: 4387d6ab90e9
Create Date: 2024-11-14 14:02:08.691590
"""

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "f69687c314c5"
down_revision = "4387d6ab90e9"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("scans", sa.Column("issues_added_count", sa.Integer(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("scans", "issues_added_count")
# ### end Alembic commands ###
6 changes: 6 additions & 0 deletions packit_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4064,6 +4064,7 @@ class OSHScanModel(Base):
task_id = Column(Integer, unique=True) # open scan hub id
status = Column(Enum(OSHScanStatus))
url = Column(String)
issues_added_count = Column(Integer)
issues_added_url = Column(String)
issues_fixed_url = Column(String)
scan_results_url = Column(String)
Expand Down Expand Up @@ -4115,6 +4116,11 @@ def set_scan_results_url(self, scan_results_url: str) -> None:
self.scan_results_url = scan_results_url
session.add(self)

def set_issues_added_count(self, issues_added_count: int) -> None:
with sa_session_transaction(commit=True) as session:
self.issues_added_count = issues_added_count
session.add(self)

@classmethod
def get_by_task_id(cls, task_id: int) -> Optional["OSHScanModel"]:
with sa_session_transaction() as session:
Expand Down
2 changes: 2 additions & 0 deletions packit_service/worker/handlers/open_scan_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def run(self) -> TaskResults:
f"{base_description} {number_of_new_findings} new findings identified."
)
external_links.update({"Added issues": self.get_issues_added_url()})
self.event.scan.set_issues_added_count(number_of_new_findings)
else:
description = f"{base_description} No new findings identified."
self.event.scan.set_issues_added_count(number_of_new_findings)

self.event.scan.set_status(OSHScanStatus.succeeded)
self.event.scan.set_issues_added_url(self.event.issues_added_url)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_open_scan_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def test_handle_scan_task_finished(
flexmock(scan_mock).should_receive("set_status").with_args(
"succeeded",
).once()
flexmock(scan_mock).should_receive("set_issues_added_count").with_args(2).once()
flexmock(OpenScanHubTaskFinishedHandler).should_receive(
"get_number_of_new_findings_identified"
).and_return(2)
Expand Down

0 comments on commit 2c2c8e2

Please sign in to comment.