6
6
import click
7
7
from tabulate import tabulate
8
8
9
- from kcidev .libs .common import kci_msg_red
9
+ from kcidev .libs .common import kci_msg_green , kci_msg_red
10
10
from kcidev .libs .dashboard import (
11
11
dashboard_fetch_boot_issues ,
12
12
dashboard_fetch_boots ,
13
13
dashboard_fetch_build ,
14
14
dashboard_fetch_build_issues ,
15
15
dashboard_fetch_builds ,
16
16
dashboard_fetch_commits_history ,
17
+ dashboard_fetch_issues_extra ,
17
18
dashboard_fetch_summary ,
18
19
dashboard_fetch_test ,
19
20
dashboard_fetch_tests ,
20
21
)
21
- from kcidev .libs .git_repo import set_giturl_branch_commit
22
+ from kcidev .libs .git_repo import get_tree_name , set_giturl_branch_commit
22
23
from kcidev .subcommands .results .hardware import hardware
23
24
from kcidev .subcommands .results .issues import issues
24
25
from kcidev .subcommands .results .options import (
@@ -468,12 +469,48 @@ def print_stats(data, headers, max_col_width, table_fmt):
468
469
)
469
470
470
471
472
+ def get_new_issues (origin , tree_name , giturl , branch , commit , arch ):
473
+ """Get new KCIDB issue for a checkout"""
474
+ try :
475
+ data = dashboard_fetch_summary (origin , giturl , branch , commit , arch , True )
476
+ tree_summary = data ["summary" ]
477
+ items = ["builds" , "boots" , "tests" ]
478
+ all_issues = []
479
+ new_issues = []
480
+ for item in items :
481
+ for i in tree_summary [item ]["issues" ]:
482
+ all_issues .append ([i ["id" ], i ["version" ]])
483
+ if not all_issues :
484
+ kci_msg_red (f"{ tree_name } /{ branch } :{ commit } No issues found" )
485
+ return
486
+ issue_extras = dashboard_fetch_issues_extra (all_issues , True )["issues" ]
487
+ for issue_id , extras in issue_extras .items ():
488
+ first_incident = extras .get ("first_incident" )
489
+ if first_incident :
490
+ if all (
491
+ [
492
+ first_incident ["git_commit_hash" ] == commit ,
493
+ first_incident ["git_repository_url" ] == giturl ,
494
+ first_incident ["git_repository_branch" ] == branch ,
495
+ ]
496
+ ):
497
+ new_issues .append (issue_id )
498
+ if not new_issues :
499
+ kci_msg_red (f"{ tree_name } /{ branch } :{ commit } No new issues found" )
500
+ else :
501
+ kci_msg_green (f"{ tree_name } /{ branch } :{ commit } New issues: { new_issues } " )
502
+ except click .ClickException as e :
503
+ print ("Exception:" , e .message )
504
+
505
+
471
506
@click .command (
472
507
name = "detect" ,
473
508
help = """Detect KCIDB issues for builds and boots
474
509
475
510
\b
476
511
The command is used to fetch KCIDB issues associated with builds and boots.
512
+ It can also detect new issues i.e. issues observed for the first time for
513
+ a checkout.
477
514
Provide `--builds` and `--boots` option for builds issue detection and boots
478
515
issue detection respectively.
479
516
`--all-checkouts` option can be used to fetch KCIDB issues for all the
@@ -489,6 +526,9 @@ def print_stats(data, headers, max_col_width, table_fmt):
489
526
# Detect boot issues
490
527
kci-dev issues detect --boots --id <boot-id>
491
528
kci-dev issues detect --boots --all-checkouts --days <number-of-days> --origin <origin>
529
+ # Detect new issues for a checkout
530
+ kci-dev issues detect --new --all-checkouts --days <number-of-days> --origin <origin>
531
+ kci-dev issues detect --new --giturl <git-url> --branch <git-branch> --commit <commit> --origin <origin>
492
532
""" ,
493
533
)
494
534
@click .option (
@@ -506,6 +546,11 @@ def print_stats(data, headers, max_col_width, table_fmt):
506
546
is_flag = True ,
507
547
help = "Fetch KCIDB issues for boots" ,
508
548
)
549
+ @click .option (
550
+ "--new" ,
551
+ is_flag = True ,
552
+ help = "Fetch new KCIDB issues for a checkout" ,
553
+ )
509
554
@click .option (
510
555
"--id" ,
511
556
"item_id" ,
@@ -523,20 +568,70 @@ def print_stats(data, headers, max_col_width, table_fmt):
523
568
type = int ,
524
569
default = "7" ,
525
570
)
571
+ @click .option (
572
+ "--giturl" ,
573
+ help = "Git URL of kernel tree" ,
574
+ )
575
+ @click .option (
576
+ "--branch" ,
577
+ help = "Branch to get results for" ,
578
+ )
579
+ @click .option (
580
+ "--commit" ,
581
+ help = "Commit or tag to get results for" ,
582
+ )
583
+ @click .option (
584
+ "--git-folder" ,
585
+ help = "Path of git repository folder" ,
586
+ type = click .Path (exists = True , file_okay = False , dir_okay = True ),
587
+ )
588
+ @click .option (
589
+ "--latest" ,
590
+ is_flag = True ,
591
+ help = "Select latest results available" ,
592
+ )
526
593
@click .pass_context
527
594
def detect (
528
595
ctx ,
529
596
origin ,
530
597
builds ,
531
598
boots ,
599
+ new ,
532
600
item_id ,
533
601
all_checkouts ,
534
602
arch ,
535
603
days ,
604
+ giturl ,
605
+ branch ,
606
+ commit ,
607
+ latest ,
608
+ git_folder ,
536
609
):
537
610
538
- if not (builds or boots ):
539
- raise click .UsageError ("Provide --builds or --boots to fetch issues for" )
611
+ if not (builds or boots or new ):
612
+ raise click .UsageError (
613
+ "Provide --builds or --boots or --new to fetch issues for"
614
+ )
615
+
616
+ if new :
617
+ if all_checkouts :
618
+ print ("Fetching new issues for all checkouts..." )
619
+ trees_list = ctx .invoke (trees , origin = origin , days = days , verbose = False )
620
+ for tree in trees_list :
621
+ giturl = tree ["git_repository_url" ]
622
+ branch = tree ["git_repository_branch" ]
623
+ commit = tree ["git_commit_hash" ]
624
+ tree_name = tree ["tree_name" ]
625
+ get_new_issues (origin , tree_name , giturl , branch , commit , arch )
626
+ return
627
+
628
+ print ("Fetching new issues for the checkout..." )
629
+ giturl , branch , commit = set_giturl_branch_commit (
630
+ origin , giturl , branch , commit , latest , git_folder
631
+ )
632
+ tree_name = get_tree_name (origin , giturl , branch )
633
+ get_new_issues (origin , tree_name , giturl , branch , commit , arch )
634
+ return
540
635
541
636
if builds and boots :
542
637
raise click .UsageError ("Specify only one option from --builds and --boots" )
0 commit comments