diff --git a/alembic/versions/f69687c314c5_add_issues_added_count_for_oshscanmodel.py b/alembic/versions/f69687c314c5_add_issues_added_count_for_oshscanmodel.py new file mode 100644 index 000000000..48770a109 --- /dev/null +++ b/alembic/versions/f69687c314c5_add_issues_added_count_for_oshscanmodel.py @@ -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 ### diff --git a/packit_service/models.py b/packit_service/models.py index 6d63126b6..020c936da 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -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) @@ -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: diff --git a/packit_service/worker/handlers/open_scan_hub.py b/packit_service/worker/handlers/open_scan_hub.py index 4a02dd7cb..a9fcc3cc0 100644 --- a/packit_service/worker/handlers/open_scan_hub.py +++ b/packit_service/worker/handlers/open_scan_hub.py @@ -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) diff --git a/tests/unit/test_open_scan_hub.py b/tests/unit/test_open_scan_hub.py index 5b9b9ef02..cb2160c77 100644 --- a/tests/unit/test_open_scan_hub.py +++ b/tests/unit/test_open_scan_hub.py @@ -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)