Skip to content

Commit

Permalink
Store number of found defects for OSH scans (#2641)
Browse files Browse the repository at this point in the history
Store number of found defects for OSH scans

Fixes #2625
RELEASE NOTES BEGIN
N/A
RELEASE NOTES END

Reviewed-by: Matej Focko
  • Loading branch information
softwarefactory-project-zuul[bot] authored Nov 15, 2024
2 parents c0efa63 + 9dc1ba0 commit 0b100f3
Show file tree
Hide file tree
Showing 7 changed files with 42 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
1 change: 1 addition & 0 deletions packit_service/service/api/osh_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def get_scan_info(scan: OSHScanModel) -> dict:
"task_id": scan.task_id,
"status": scan.status,
"url": scan.url,
"issues_added_count": scan.issues_added_count,
"issues_added_url": scan.issues_added_url,
"issues_fixed_url": scan.issues_fixed_url,
"scan_results_url": scan.scan_results_url,
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
2 changes: 2 additions & 0 deletions tests_openshift/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class SampleValues:
# scan
task_id = 123
scan_url = "https://scan-url"
issues_added_count = 3
issues_added_url = "https://issues-added-url"
issues_fixed_url = "https://issues-fixed-url"
scan_results_url = "https://scan-results-url"
Expand Down Expand Up @@ -2503,4 +2504,5 @@ def a_scan(a_copr_build_for_pr):
scan.issues_added_url = SampleValues.issues_added_url
scan.issues_fixed_url = SampleValues.issues_fixed_url
scan.scan_results_url = SampleValues.scan_results_url
scan.issues_added_count = SampleValues.issues_added_count
yield scan
1 change: 1 addition & 0 deletions tests_openshift/service/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ def test_scan_info(
assert response_dict["repo_namespace"] == SampleValues.repo_namespace
assert response_dict["repo_name"] == SampleValues.repo_name
assert response_dict["project_url"] == SampleValues.project_url
assert response_dict["issues_added_count"] == SampleValues.issues_added_count


def test_scans_list(
Expand Down

0 comments on commit 0b100f3

Please sign in to comment.