Skip to content

Commit

Permalink
Refactor fetch_results to remove duplication #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 108db2d commit 2b35f62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
36 changes: 13 additions & 23 deletions dejacode_toolkit/scancodeio.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,40 +224,30 @@ def update_from_scan(self, package, user):

return updated_fields

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

next_url = project_packages_url
next_url = api_url
while next_url:
logger.debug(f"{self.label}: fetch packages from project_packages_url={next_url}")
logger.debug(f"{self.label}: fetch results from api_url={next_url}")
response = self.request_get(url=next_url)
if not response:
raise Exception("Error fetching project packages")
raise Exception("Error fetching results")

packages.extend(response["results"])
results.extend(response["results"])
next_url = response["next"]

return packages
return results

def fetch_project_packages(self, project_uuid):
"""Return the list of packages for the provided `project_uuid`."""
api_url = self.get_scan_action_url(project_uuid, "packages")
return self.fetch_results(api_url)

# 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_scan_action_url(project_uuid, "dependencies")
dependencies = []

next_url = api_url
while next_url:
logger.debug(f"{self.label}: fetch dependencies from project_packages_url={next_url}")
response = self.request_get(url=next_url)
if not response:
raise Exception("Error fetching project dependencies")

dependencies.extend(response["results"])
next_url = response["next"]

return dependencies
return self.fetch_results(api_url)

# (label, scan_field, model_field, input_type)
SCAN_SUMMARY_FIELDS = [
Expand Down
3 changes: 0 additions & 3 deletions product_portfolio/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ class DependencyFilterSet(DataspacedFilterSet):
"resolved_to_package__version",
],
)
is_deployment_path = BooleanChoiceFilter(
widget=DropDownWidget(anchor="#codebase"),
)

class Meta:
model = ProductDependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
{% for dependency in filter_dependency.qs %}
<tr class="{% cycle 'odd' '' %}">
<td>
<strong>
<a href="{{ dependency.for_package.get_absolute_url }}" target="_blank">{{ dependency.for_package }}</a>
</strong>
{% if dependency.for_package %}
<strong>
<a href="{{ dependency.for_package.get_absolute_url }}" target="_blank">{{ dependency.for_package }}</a>
</strong>
{% endif %}
</td>
<td>
{% if dependency.resolved_to_package %}
Expand All @@ -63,7 +65,7 @@
{% endif %}
</td>
<td>
{{ dependency.scope }}
{{ dependency.scpe }}
</td>
<td>
{{ dependency.is_runtime|as_icon }}
Expand Down

0 comments on commit 2b35f62

Please sign in to comment.