Skip to content

Commit 5e2b8e3

Browse files
authored
Merge pull request #204 from JenySadadia/detect-new-issue
Implement command to fetch new issues for checkout
2 parents cb1825d + 3f4719a commit 5e2b8e3

File tree

2 files changed

+113
-4
lines changed

2 files changed

+113
-4
lines changed

kcidev/libs/dashboard.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,17 @@ def dashboard_fetch_issue_tests(origin, issue_id, use_json):
318318
logging.info(f"Fetching tests for issue ID: {issue_id}")
319319
params = {"filter_origin": origin}
320320
return dashboard_api_fetch(f"issue/{issue_id}/tests", params, use_json)
321+
322+
323+
def dashboard_fetch_issues_extra(issues, use_json):
324+
"""Send POST request to "issues/extras/" endpoint
325+
Request body parameter "issues" should be a list containing sub-lists
326+
with issue ID and version.
327+
for example:
328+
[
329+
['maestro:11568c8c555164d721a425c3ee264932a87e9113',1],
330+
['maestro:2779a206c30e0ec91f19f1df949c1b9d65fe1238',1]
331+
]
332+
"""
333+
body = {"issues": issues}
334+
return dashboard_api_post("issue/extras/", {}, use_json, body)

kcidev/subcommands/results/__init__.py

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
import click
77
from tabulate import tabulate
88

9-
from kcidev.libs.common import kci_msg_red
9+
from kcidev.libs.common import kci_msg_green, kci_msg_red
1010
from kcidev.libs.dashboard import (
1111
dashboard_fetch_boot_issues,
1212
dashboard_fetch_boots,
1313
dashboard_fetch_build,
1414
dashboard_fetch_build_issues,
1515
dashboard_fetch_builds,
1616
dashboard_fetch_commits_history,
17+
dashboard_fetch_issues_extra,
1718
dashboard_fetch_summary,
1819
dashboard_fetch_test,
1920
dashboard_fetch_tests,
2021
)
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
2223
from kcidev.subcommands.results.hardware import hardware
2324
from kcidev.subcommands.results.issues import issues
2425
from kcidev.subcommands.results.options import (
@@ -468,12 +469,48 @@ def print_stats(data, headers, max_col_width, table_fmt):
468469
)
469470

470471

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+
471506
@click.command(
472507
name="detect",
473508
help="""Detect KCIDB issues for builds and boots
474509
475510
\b
476511
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.
477514
Provide `--builds` and `--boots` option for builds issue detection and boots
478515
issue detection respectively.
479516
`--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):
489526
# Detect boot issues
490527
kci-dev issues detect --boots --id <boot-id>
491528
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>
492532
""",
493533
)
494534
@click.option(
@@ -506,6 +546,11 @@ def print_stats(data, headers, max_col_width, table_fmt):
506546
is_flag=True,
507547
help="Fetch KCIDB issues for boots",
508548
)
549+
@click.option(
550+
"--new",
551+
is_flag=True,
552+
help="Fetch new KCIDB issues for a checkout",
553+
)
509554
@click.option(
510555
"--id",
511556
"item_id",
@@ -523,20 +568,70 @@ def print_stats(data, headers, max_col_width, table_fmt):
523568
type=int,
524569
default="7",
525570
)
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+
)
526593
@click.pass_context
527594
def detect(
528595
ctx,
529596
origin,
530597
builds,
531598
boots,
599+
new,
532600
item_id,
533601
all_checkouts,
534602
arch,
535603
days,
604+
giturl,
605+
branch,
606+
commit,
607+
latest,
608+
git_folder,
536609
):
537610

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
540635

541636
if builds and boots:
542637
raise click.UsageError("Specify only one option from --builds and --boots")

0 commit comments

Comments
 (0)