-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add upload pipeline timeline to CommitAdmin #717
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| from shared.django_apps.reports.models import ReportType | ||
| from shared.django_apps.ta_timeseries.models import Testrun | ||
| from shared.django_apps.timeseries.models import Measurement, MeasurementName | ||
| from shared.django_apps.upload_breadcrumbs.models import UploadBreadcrumb | ||
| from shared.django_apps.utils.paginator import EstimatedCountPaginator | ||
| from shared.helpers.redis import get_redis_connection | ||
| from shared.reports.enums import UploadState | ||
|
|
@@ -270,6 +271,7 @@ class CommitAdmin(AdminMixin, admin.ModelAdmin): | |
| "deleted", | ||
| "notified", | ||
| "reprocess_actions", | ||
| "upload_pipeline_timeline", | ||
| ) | ||
| fields = readonly_fields | ||
| paginator = EstimatedCountPaginator | ||
|
|
@@ -359,6 +361,84 @@ def reprocess_actions(self, obj): | |
|
|
||
| return format_html("<div>{}</div>", format_html("".join(buttons))) | ||
|
|
||
| @admin.display(description="Upload Pipeline Timeline") | ||
| def upload_pipeline_timeline(self, obj): | ||
| if obj.pk is None: | ||
| return "" | ||
|
|
||
| breadcrumbs = UploadBreadcrumb.objects.filter( | ||
| commit_sha=obj.commitid, | ||
| repo_id=obj.repository.repoid, | ||
| ).order_by("created_at")[:200] | ||
|
|
||
| if not breadcrumbs: | ||
| return format_html("<em>No breadcrumbs recorded for this commit.</em>") | ||
|
|
||
| rows = [] | ||
| for bc in breadcrumbs: | ||
| data = bc.breadcrumb_data or {} | ||
| milestone = data.get("milestone", "") | ||
| error = data.get("error", "") | ||
| error_text = data.get("error_text", "") | ||
| task_name = data.get("task_name", "") | ||
| parent_task_id = data.get("parent_task_id", "") | ||
| endpoint = data.get("endpoint", "") | ||
|
|
||
| if error: | ||
| color = "#d32f2f" | ||
| elif milestone in ("lac", "lr", "uc", "ns"): | ||
| color = "#388e3c" | ||
| elif milestone in ("la", "pu", "nt"): | ||
| color = "#1565c0" | ||
| else: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Milestone color-coding values don't match actual enumMedium Severity The milestone color-coding checks for values |
||
| color = "#555" | ||
|
|
||
| upload_ids_str = ( | ||
| ", ".join(str(uid) for uid in bc.upload_ids) if bc.upload_ids else "" | ||
| ) | ||
|
|
||
| detail_parts = [] | ||
| if milestone: | ||
| detail_parts.append(f"<strong>{milestone}</strong>") | ||
| if endpoint: | ||
| detail_parts.append(f"endpoint={endpoint}") | ||
| if error: | ||
| detail_parts.append(f'<span style="color:#d32f2f">err={error}</span>') | ||
| if error_text: | ||
| detail_parts.append( | ||
| f'<span style="color:#d32f2f">{error_text[:120]}</span>' | ||
| ) | ||
| detail = " · ".join(detail_parts) if detail_parts else "—" | ||
|
|
||
| rows.append( | ||
| f"<tr>" | ||
| f'<td style="white-space:nowrap;color:{color};padding:4px 8px">' | ||
| f"{bc.created_at:%Y-%m-%d %H:%M:%S}</td>" | ||
| f'<td style="padding:4px 8px;font-family:monospace;font-size:12px">' | ||
| f"{task_name}</td>" | ||
| f'<td style="padding:4px 8px;font-family:monospace;font-size:12px">' | ||
| f"{parent_task_id}</td>" | ||
| f'<td style="padding:4px 8px">{detail}</td>' | ||
| f'<td style="padding:4px 8px;font-family:monospace;font-size:12px">' | ||
| f"{upload_ids_str}</td>" | ||
| f"</tr>" | ||
| ) | ||
|
|
||
| table = ( | ||
| '<table style="border-collapse:collapse;width:100%">' | ||
| "<thead><tr>" | ||
| '<th style="text-align:left;padding:4px 8px;border-bottom:2px solid #ccc">Time</th>' | ||
| '<th style="text-align:left;padding:4px 8px;border-bottom:2px solid #ccc">Task</th>' | ||
| '<th style="text-align:left;padding:4px 8px;border-bottom:2px solid #ccc">Parent Task ID</th>' | ||
| '<th style="text-align:left;padding:4px 8px;border-bottom:2px solid #ccc">Detail</th>' | ||
| '<th style="text-align:left;padding:4px 8px;border-bottom:2px solid #ccc">Upload IDs</th>' | ||
| "</tr></thead><tbody>" + "".join(rows) + "</tbody></table>" | ||
| ) | ||
|
|
||
| return format_html( | ||
| '<div style="max-height:600px;overflow:auto">{}</div>', format_html(table) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unescaped user data in HTML creates XSS riskLow Severity HTML table rows are constructed using f-strings with values from |
||
| ) | ||
|
|
||
| def _reprocess_uploads( | ||
| self, request, commit: Commit, config: ReprocessConfig | ||
| ) -> HttpResponseRedirect: | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referencing non-existent fields from breadcrumb data model
Medium Severity
The code extracts
task_nameandparent_task_idfrombreadcrumb_data, butBreadcrumbDatais a Pydantic model withextra="forbid"that only permitsmilestone,endpoint,uploader,error, anderror_text. These fields can never exist in the data, so the "Task" and "Parent Task ID" table columns will always be empty, wasting space in the timeline UI.Additional Locations (1)
apps/codecov-api/core/admin.py#L416-L420