Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filter capabilities to the treeDetails endpoint #103

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/kernelCI_app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TreeDetailsSerializer(serializers.Serializer):
architecture = serializers.CharField()
config_name = serializers.CharField()
valid = serializers.BooleanField()
start_time = serializers.CharField()
start_time = serializers.DateTimeField()
duration = serializers.CharField()
compiler = serializers.CharField()
config_url = serializers.CharField()
Expand Down
53 changes: 29 additions & 24 deletions backend/kernelCI_app/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.http import JsonResponse
from django.views import View

from querybuilder.query import Query
from kernelCI_app.models import Checkouts, Builds
from kernelCI_app.serializers import TreeSerializer, TreeDetailsSerializer
from kernelCI_app.serializers import TreeSerializer
from kernelCI_app.utils import get_visible_record_identifiers


Expand Down Expand Up @@ -108,25 +108,30 @@ def get_test_staus(self, build_id):
return {k: getattr(builds[0], k) for k in status_keys}

def get(self, request, commit_hash):
builds = Builds.objects.raw(
"""
SELECT
builds.id, builds.architecture, builds.config_name, builds.misc,
builds.config_url, builds.compiler, builds.valid,
builds.start_time, builds.duration, builds.log_url
FROM
builds
INNER JOIN
checkouts ON checkouts.id = builds.checkout_id
WHERE checkouts.git_commit_hash = %s;
""",
[commit_hash]
)

for build in builds:
build.test_status = self.get_test_staus(build.id)

data = TreeDetailsSerializer(builds, many=True).data
summary = self.create_summary(data)
resp = {"builds": data, "summary": summary}
return JsonResponse(resp, safe=False)
build_fields = [
'id', 'architecture', 'config_name', 'misc', 'config_url',
'compiler', 'valid', 'duration', 'log_url', 'start_time']
checkout_fields = [
'git_repository_branch', 'git_repository_url', 'git_repository_branch']

query = Query().from_table(Builds, build_fields).join(
'checkouts',
condition='checkouts.id = builds.checkout_id',
fields=checkout_fields
).where(git_commit_hash__eq=commit_hash)

for k in request.GET.keys():
if k.startswith('filter_'):
field = k[7:]
if field in build_fields or field in checkout_fields:
filter_list = request.GET.getlist(k)
query.where({field: filter_list})

records = query.select()
for r in records:
status = self.get_test_staus(r.get('id'))
r['status'] = status

summary = self.create_summary(records)

return JsonResponse({"builds": records, "summary": summary}, safe=False)
69 changes: 68 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ django = "^5.0.6"
djangorestframework = "^3.15.2"
gunicorn = "^22.0.0"
psycopg = "^3.1.19"
django-query-builder = "^3.2.0"


[tool.poetry.group.dev.dependencies]
Expand Down
Loading