Skip to content

Commit

Permalink
Remove code duplication to generate SCIO API URLs #138
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 15, 2024
1 parent e9b7fde commit 108db2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,9 +1682,9 @@ def send_scan_data_as_file_view(request, project_uuid, filename):
raise Http404

scancodeio = ScanCodeIO(dataspace)
scan_results_url = scancodeio.get_scan_results_url(project_uuid)
scan_results_url = scancodeio.get_scan_action_url(project_uuid, "results")
scan_results = scancodeio.fetch_scan_data(scan_results_url)
scan_summary_url = scancodeio.get_scan_summary_url(project_uuid)
scan_summary_url = scancodeio.get_scan_action_url(project_uuid, "summary")
scan_summary = scancodeio.fetch_scan_data(scan_summary_url)

in_memory_zip = io.BytesIO()
Expand Down
19 changes: 4 additions & 15 deletions dejacode_toolkit/scancodeio.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,9 @@ def __init__(self, *args, **kwargs):
def get_scan_detail_url(self, project_uuid):
return f"{self.project_api_url}{project_uuid}/"

def get_scan_results_url(self, project_uuid):
def get_scan_action_url(self, project_uuid, action_name):
detail_url = self.get_scan_detail_url(project_uuid)
return f"{detail_url}results/"

def get_scan_summary_url(self, project_uuid):
detail_url = self.get_scan_detail_url(project_uuid)
return f"{detail_url}summary/"

def get_project_packages_url(self, project_uuid):
return f"{self.project_api_url}{project_uuid}/packages/"

# TODO: Remove duplication with get_project_packages_url
def get_project_dependencies_url(self, project_uuid):
return f"{self.project_api_url}{project_uuid}/dependencies/"
return f"{detail_url}{action_name}/"

def get_scan_results(self, download_url, dataspace):
scan_info = self.fetch_scan_info(uri=download_url, dataspace=dataspace)
Expand Down Expand Up @@ -237,7 +226,7 @@ def update_from_scan(self, package, user):

def fetch_project_packages(self, project_uuid):
"""Return the list of packages for the provided `project_uuid`."""
project_packages_url = self.get_project_packages_url(project_uuid)
project_packages_url = self.get_scan_action_url(project_uuid, "packages")
packages = []

next_url = project_packages_url
Expand All @@ -255,7 +244,7 @@ def fetch_project_packages(self, project_uuid):
# TODO: Remove duplication with fetch_project_packages
def fetch_project_dependencies(self, project_uuid):
"""Return the list of dependencies for the provided `project_uuid`."""
api_url = self.get_project_dependencies_url(project_uuid)
api_url = self.get_scan_action_url(project_uuid, "dependencies")
dependencies = []

next_url = api_url
Expand Down

0 comments on commit 108db2d

Please sign in to comment.