ydshieh HF Staff commited on
Commit
c478de9
Β·
verified Β·
1 Parent(s): b2686d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -33
app.py CHANGED
@@ -197,9 +197,13 @@ def _filter_records(repo: str, pr: str, sha: str) -> List[dict]:
197
  records: List[dict] = []
198
  for file_path in file_paths:
199
  commit = _extract_commit_from_path(file_path)
200
- if sha and not commit.lower().startswith(sha):
 
 
 
201
  print(f"DEBUG: Skipping {file_path} - commit {commit} doesn't match sha {sha}")
202
  continue
 
203
  payload = _load_payload(file_path)
204
  if payload is None:
205
  print(f"DEBUG: Skipping {file_path} - failed to load payload")
@@ -415,7 +419,6 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
415
  str, # metadata_info
416
  str, # by_test_html
417
  str, # by_model_html
418
- str, # markdown_summary
419
  str, # pytest_commands
420
  str, # raw_json
421
  str, # status
@@ -427,13 +430,24 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
427
 
428
  print(f"DEBUG: Query called with repo='{repo}', pr='{pr}', sha='{sha}'")
429
 
 
 
 
 
 
 
 
 
 
 
 
 
430
  if not pr:
431
  return (
432
  "**Error:** PR number is required.",
433
  "",
434
  "",
435
  "",
436
- "",
437
  json.dumps({"error": "PR number is required."}, indent=2),
438
  "❌ Provide a PR number to search.",
439
  ""
@@ -448,7 +462,6 @@ def query(repo: str, pr: str, sha: str) -> Tuple[
448
  "",
449
  "",
450
  "",
451
- "",
452
  json.dumps({"error": "No records found."}, indent=2),
453
  f"❌ No records found for PR {pr}.",
454
  ""
@@ -469,14 +482,12 @@ Files are organized as `pr-{{PR}}/sha-{{COMMIT}}/failure_summary.json`
469
 
470
  metadata = latest_record.get("metadata", {})
471
 
472
- # Generate metadata info
 
473
  metadata_lines = [
474
- f"**Repository:** {metadata.get('repository', 'N/A')}",
475
- f"**Branch:** {metadata.get('branch', 'N/A')}",
476
- f"**PR:** #{metadata.get('pull_request_number', 'N/A')}",
477
- f"**Commit:** `{metadata.get('commit_sha', 'N/A')[:12]}`",
478
- f"**Workflow ID:** {metadata.get('workflow_id', 'N/A')}",
479
- f"**Collected at:** {metadata.get('collected_at', 'N/A')}",
480
  f"**Total failures:** {len(latest_record.get('failures', []))}",
481
  ]
482
  metadata_info = "\n\n".join(metadata_lines)
@@ -484,22 +495,19 @@ Files are organized as `pr-{{PR}}/sha-{{COMMIT}}/failure_summary.json`
484
  # Generate HTML tables
485
  by_test_html, by_model_html = _generate_html_tables(latest_record)
486
 
487
- # Generate markdown summary
488
- markdown_summary = _generate_markdown_summary(latest_record)
489
-
490
  # Generate pytest commands
491
  pytest_commands = _generate_pytest_commands(latest_record)
492
 
493
  # Raw JSON
494
  raw_json = json.dumps(latest_record, indent=2)
495
 
496
- status = f"βœ… Showing latest result from {len(records)} record(s) for PR {pr}."
 
497
 
498
  return (
499
  metadata_info,
500
  by_test_html,
501
  by_model_html,
502
- markdown_summary,
503
  pytest_commands,
504
  raw_json,
505
  status,
@@ -556,8 +564,8 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
556
  with gr.Column(scale=1):
557
  sha_box = gr.Textbox(
558
  label="Commit SHA",
559
- placeholder="50947fc",
560
- info="Optional: commit SHA prefix"
561
  )
562
 
563
  with gr.Row():
@@ -582,18 +590,6 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
582
 
583
  by_model_html = gr.HTML(label="Model Failures")
584
 
585
- with gr.Tab("πŸ“‹ Copy for GitHub"):
586
- gr.Markdown(
587
- """
588
- Copy the markdown below to paste directly into a GitHub comment.
589
- """
590
- )
591
- markdown_output = gr.Textbox(
592
- label="Markdown Summary",
593
- lines=20,
594
- max_lines=30,
595
- )
596
-
597
  with gr.Tab("πŸ§ͺ Pytest Commands"):
598
  gr.Markdown(
599
  """
@@ -642,7 +638,6 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
642
  "",
643
  "",
644
  "",
645
- "",
646
  "πŸ’‘ Enter a PR number above to get started",
647
  ""
648
  )
@@ -655,7 +650,6 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
655
  metadata_box,
656
  by_test_html,
657
  by_model_html,
658
- markdown_output,
659
  pytest_output,
660
  json_view,
661
  status_md,
@@ -677,7 +671,6 @@ with gr.Blocks(title="CircleCI Test Results Viewer") as demo:
677
  metadata_box,
678
  by_test_html,
679
  by_model_html,
680
- markdown_output,
681
  pytest_output,
682
  json_view,
683
  status_md,
 
197
  records: List[dict] = []
198
  for file_path in file_paths:
199
  commit = _extract_commit_from_path(file_path)
200
+
201
+ # Fixed SHA matching: works with both short and full SHAs
202
+ # Check if stored commit starts with input SHA OR if input SHA starts with stored commit
203
+ if sha and not (commit.lower().startswith(sha) or sha.startswith(commit.lower())):
204
  print(f"DEBUG: Skipping {file_path} - commit {commit} doesn't match sha {sha}")
205
  continue
206
+
207
  payload = _load_payload(file_path)
208
  if payload is None:
209
  print(f"DEBUG: Skipping {file_path} - failed to load payload")
 
419
  str, # metadata_info
420
  str, # by_test_html
421
  str, # by_model_html
 
422
  str, # pytest_commands
423
  str, # raw_json
424
  str, # status
 
430
 
431
  print(f"DEBUG: Query called with repo='{repo}', pr='{pr}', sha='{sha}'")
432
 
433
+ # Validate SHA length if provided
434
+ if sha and len(sha) < 6:
435
+ return (
436
+ "**Error:** Commit SHA must be at least 6 characters.",
437
+ "",
438
+ "",
439
+ "",
440
+ json.dumps({"error": "Commit SHA must be at least 6 characters."}, indent=2),
441
+ "⚠️ Commit SHA must be at least 6 characters.",
442
+ ""
443
+ )
444
+
445
  if not pr:
446
  return (
447
  "**Error:** PR number is required.",
448
  "",
449
  "",
450
  "",
 
451
  json.dumps({"error": "PR number is required."}, indent=2),
452
  "❌ Provide a PR number to search.",
453
  ""
 
462
  "",
463
  "",
464
  "",
 
465
  json.dumps({"error": "No records found."}, indent=2),
466
  f"❌ No records found for PR {pr}.",
467
  ""
 
482
 
483
  metadata = latest_record.get("metadata", {})
484
 
485
+ # Generate simplified metadata info
486
+ commit_sha = latest_record.get("__commit", "N/A")
487
  metadata_lines = [
488
+ f"**Repository:** huggingface/transformers",
489
+ f"**PR:** #{pr}",
490
+ f"**Commit:** `{commit_sha}`",
 
 
 
491
  f"**Total failures:** {len(latest_record.get('failures', []))}",
492
  ]
493
  metadata_info = "\n\n".join(metadata_lines)
 
495
  # Generate HTML tables
496
  by_test_html, by_model_html = _generate_html_tables(latest_record)
497
 
 
 
 
498
  # Generate pytest commands
499
  pytest_commands = _generate_pytest_commands(latest_record)
500
 
501
  # Raw JSON
502
  raw_json = json.dumps(latest_record, indent=2)
503
 
504
+ # Updated status message format
505
+ status = f"βœ… Showing result from {len(records)} record (commit: {commit_sha}) PR {pr}."
506
 
507
  return (
508
  metadata_info,
509
  by_test_html,
510
  by_model_html,
 
511
  pytest_commands,
512
  raw_json,
513
  status,
 
564
  with gr.Column(scale=1):
565
  sha_box = gr.Textbox(
566
  label="Commit SHA",
567
+ placeholder="50947fc (min 6 chars)",
568
+ info="Optional: commit SHA (min 6 characters)"
569
  )
570
 
571
  with gr.Row():
 
590
 
591
  by_model_html = gr.HTML(label="Model Failures")
592
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  with gr.Tab("πŸ§ͺ Pytest Commands"):
594
  gr.Markdown(
595
  """
 
638
  "",
639
  "",
640
  "",
 
641
  "πŸ’‘ Enter a PR number above to get started",
642
  ""
643
  )
 
650
  metadata_box,
651
  by_test_html,
652
  by_model_html,
 
653
  pytest_output,
654
  json_view,
655
  status_md,
 
671
  metadata_box,
672
  by_test_html,
673
  by_model_html,
 
674
  pytest_output,
675
  json_view,
676
  status_md,