@@ -518,7 +518,13 @@ def get_tree_commit_history(
518518 git_url : Optional [str ],
519519 git_branch : Optional [str ],
520520 tree_name : Optional [str ],
521+ include_types : Optional [list [str ]] = None ,
521522) -> Optional [list [tuple ]]:
523+ if not include_types :
524+ include_types = ["builds" , "boots" , "tests" ]
525+
526+ include_types = [t .lower () for t in include_types ]
527+
522528 field_values = {
523529 "commit_hash" : commit_hash ,
524530 "origin_param" : origin ,
@@ -541,6 +547,62 @@ def get_tree_commit_history(
541547 git_url = git_url , git_branch = git_branch , tree_name = tree_name
542548 )
543549
550+ include_builds = "builds" in include_types
551+ include_boots = "boots" in include_types
552+ include_tests = "tests" in include_types
553+ include_test_data = include_tests or include_boots
554+
555+ build_prefix = "b." if include_builds else "NULL AS "
556+ test_prefix = "t." if include_test_data else "NULL AS "
557+ build_id = "b.id" if include_builds else "NULL"
558+ build_misc = "b.misc" if include_builds else "NULL"
559+ test_misc_runtime = "t.misc->>'runtime'" if include_test_data else "NULL"
560+ test_id = "t.id" if include_test_data else "NULL"
561+
562+ select_clause = f"""c.git_commit_hash,
563+ c.git_commit_name,
564+ c.git_commit_tags,
565+ c.start_time,
566+ { build_prefix } duration,
567+ { build_prefix } architecture,
568+ { build_prefix } compiler,
569+ { build_prefix } config_name,
570+ { build_prefix } status,
571+ { build_prefix } origin,
572+ { build_id } AS build_id,
573+ { build_misc } AS build_misc,
574+ { test_prefix } path,
575+ { test_prefix } status,
576+ { test_prefix } duration,
577+ { test_prefix } environment_compatible,
578+ { test_prefix } environment_misc,
579+ { test_prefix } origin,
580+ { test_misc_runtime } AS test_lab,
581+ { test_id } AS test_id,
582+ ic.id AS incidents_id,
583+ ic.test_id AS incidents_test_id,
584+ i.id AS issues_id,
585+ i.version AS issues_version"""
586+
587+ if include_boots and not include_tests :
588+ test_filter = "AND (t.path IS NULL OR t.path LIKE 'boot%%')"
589+ elif include_tests and not include_boots :
590+ test_filter = "AND (t.path IS NULL OR t.path NOT LIKE 'boot%%')"
591+ else :
592+ test_filter = ""
593+
594+ if include_test_data :
595+ test_join = f"LEFT JOIN tests AS t ON t.build_id = b.id { test_filter } "
596+ incidents_condition = "t.id = ic.test_id OR b.id = ic.build_id"
597+ else :
598+ test_join = ""
599+ incidents_condition = "b.id = ic.build_id"
600+
601+ join_clause = f"""LEFT JOIN builds AS b ON c.id = b.checkout_id
602+ { test_join }
603+ LEFT JOIN incidents AS ic ON { incidents_condition }
604+ LEFT JOIN issues AS i ON ic.issue_id = i.id"""
605+
544606 query = f"""
545607 WITH HEAD_START_TIME AS (
546608 SELECT
@@ -630,37 +692,10 @@ def get_tree_commit_history(
630692 c.start_time DESC
631693 )
632694 SELECT
633- c.git_commit_hash,
634- c.git_commit_name,
635- c.git_commit_tags,
636- c.start_time,
637- b.duration,
638- b.architecture,
639- b.compiler,
640- b.config_name,
641- b.status,
642- b.origin,
643- t.path,
644- t.status,
645- t.duration,
646- t.environment_compatible,
647- t.environment_misc,
648- t.origin,
649- t.misc->>'runtime' AS test_lab,
650- b.id AS build_id,
651- b.misc AS build_misc,
652- t.id AS test_id,
653- ic.id AS incidents_id,
654- ic.test_id AS incidents_test_id,
655- i.id AS issues_id,
656- i.version AS issues_version
695+ { select_clause }
657696 FROM
658697 SELECTED_CHECKOUTS AS c
659- LEFT JOIN builds AS b ON c.id = b.checkout_id
660- LEFT JOIN tests AS t ON t.build_id = b.id
661- LEFT JOIN incidents AS ic ON t.id = ic.test_id
662- OR b.id = ic.build_id
663- LEFT JOIN issues AS i ON ic.issue_id = i.id
698+ { join_clause }
664699 """
665700
666701 with connection .cursor () as cursor :
0 commit comments