From 7daab2ac908bbcb8703ce80f2864200e1282e6d0 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Fri, 13 Dec 2024 08:51:40 -0300 Subject: [PATCH 1/5] results: move action handling to main results() function We will be fetching different API endpoints for each command, so it easier to do that from results() instead of passing all it cmd args parameter to yet another function. Signed-off-by: Gustavo Padovan --- kcidev/subcommands/results.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index 8483f54..3ee6bb8 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -93,13 +93,6 @@ def cmd_failed_builds(data, download_logs): kci_print(f" id: {build['id']}") -def process_action(action, data, download_logs): - if action == None or action == "summary": - cmd_summary(data) - elif action == "failed-builds": - cmd_failed_builds(data, download_logs) - - def fetch_full_results(origin, giturl, branch, commit): endpoint = f"tree/{commit}/full" params = { @@ -145,7 +138,10 @@ def fetch_full_results(origin, giturl, branch, commit): @click.pass_context def results(ctx, origin, giturl, branch, commit, action, download_logs): data = fetch_full_results(origin, giturl, branch, commit) - process_action(action, data, download_logs) + if action == None or action == "summary": + cmd_summary(data) + elif action == "failed-builds": + cmd_failed_builds(data, download_logs) if __name__ == "__main__": From c4e23306090455c0f461ca1cc69ed0bf45311cca Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Fri, 13 Dec 2024 09:19:24 -0300 Subject: [PATCH 2/5] results: make checking for required options local for each cmd Each action has its own arguments needs, so let's keep this simple and check under each action if the required options are being passed on. Signed-off-by: Gustavo Padovan --- kcidev/subcommands/results.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index 3ee6bb8..c7a3652 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -114,17 +114,14 @@ def fetch_full_results(origin, giturl, branch, commit): @click.option( "--giturl", help="Git URL of kernel tree ", - required=True, ) @click.option( "--branch", help="Branch to get results for", - required=True, ) @click.option( "--commit", help="Commit or tag to get results for", - required=True, ) @click.option( "--action", @@ -137,10 +134,17 @@ def fetch_full_results(origin, giturl, branch, commit): ) @click.pass_context def results(ctx, origin, giturl, branch, commit, action, download_logs): - data = fetch_full_results(origin, giturl, branch, commit) if action == None or action == "summary": + if not giturl or not branch or not commit: + kci_err("--giturl AND --branch AND --commit are required") + raise click.Abort() + data = fetch_full_results(origin, giturl, branch, commit) cmd_summary(data) elif action == "failed-builds": + if not giturl or not branch or not commit: + kci_err("--giturl AND --branch AND commit are required") + raise click.Abort() + data = fetch_full_results(origin, giturl, branch, commit) cmd_failed_builds(data, download_logs) From 2b51339d424c062f52a5a8900ec8f79cc09793fb Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Fri, 13 Dec 2024 09:35:36 -0300 Subject: [PATCH 3/5] results: keep functions to fetch for the dashboard together Signed-off-by: Gustavo Padovan --- kcidev/subcommands/results.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index c7a3652..c82531c 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -25,6 +25,18 @@ def fetch_from_api(endpoint, params): return r.json() +def fetch_full_results(origin, giturl, branch, commit): + endpoint = f"tree/{commit}/full" + params = { + "origin": origin, + "git_url": giturl, + "git_branch": branch, + "commit": commit, + } + + return fetch_from_api(endpoint, params) + + def print_summary(type, n_pass, n_fail, n_inconclusive): kci_msg_nonl(f"{type}:\t") kci_msg_green_nonl(f"{n_pass}") if n_pass else kci_msg_nonl(f"{n_pass}") @@ -93,18 +105,6 @@ def cmd_failed_builds(data, download_logs): kci_print(f" id: {build['id']}") -def fetch_full_results(origin, giturl, branch, commit): - endpoint = f"tree/{commit}/full" - params = { - "origin": origin, - "git_url": giturl, - "git_branch": branch, - "commit": commit, - } - - return fetch_from_api(endpoint, params) - - @click.command(help=" [Experimental] Get results from the dashboard") @click.option( "--origin", From 3e7ab58dbff2cf3937b62581721fc818c8890477 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Fri, 13 Dec 2024 09:22:04 -0300 Subject: [PATCH 4/5] results add trees command It list all the available trees for a given origin. Signed-off-by: Gustavo Padovan --- docs/results.md | 10 ++++++++++ kcidev/subcommands/results.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/docs/results.md b/docs/results.md index 8d93ebf..ca2eff7 100644 --- a/docs/results.md +++ b/docs/results.md @@ -31,6 +31,16 @@ Unfortunately the Dashboard API doesn't support git tags as parameters yet. ## Results actions +### --action=trees + +List all available trees for a given origin. + +Example: + +```sh +kci-dev results --action=trees +``` + ### --action=summary Shows a numeric summary of the build, boot and test results. diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index c82531c..2c35b1a 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -37,6 +37,13 @@ def fetch_full_results(origin, giturl, branch, commit): return fetch_from_api(endpoint, params) +def fetch_tree_fast(origin): + params = { + "origin": origin, + } + return fetch_from_api("tree-fast", params) + + def print_summary(type, n_pass, n_fail, n_inconclusive): kci_msg_nonl(f"{type}:\t") kci_msg_green_nonl(f"{n_pass}") if n_pass else kci_msg_nonl(f"{n_pass}") @@ -79,6 +86,15 @@ def cmd_summary(data): print_summary("tests", pass_tests, fail_tests, inconclusive_tests) +def cmd_list_trees(origin): + trees = fetch_tree_fast(origin) + for t in trees: + kci_msg_green_nonl(f"- {t['tree_name']}/{t['git_repository_branch']}:\n") + kci_print(f" giturl: {t['git_repository_url']}") + kci_print(f" latest: {t['git_commit_hash']} ({t['git_commit_name']})") + kci_print(f" latest: {t['start_time']}") + + def cmd_failed_builds(data, download_logs): kci_print("Failed builds:") for build in data["builds"]: @@ -140,6 +156,8 @@ def results(ctx, origin, giturl, branch, commit, action, download_logs): raise click.Abort() data = fetch_full_results(origin, giturl, branch, commit) cmd_summary(data) + elif action == "trees": + cmd_list_trees(origin) elif action == "failed-builds": if not giturl or not branch or not commit: kci_err("--giturl AND --branch AND commit are required") From 7b0a9ec724bc6078eba86076effda4d461008b38 Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Fri, 13 Dec 2024 10:54:24 -0300 Subject: [PATCH 5/5] results: add --latest option to show most recent results Instead of passing --commit HASH, one can juss pass --latest and kci-dev will automatically pull the latest results. Signed-off-by: Gustavo Padovan --- docs/results.md | 4 ++++ kcidev/subcommands/results.py | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/results.md b/docs/results.md index ca2eff7..a8adf1c 100644 --- a/docs/results.md +++ b/docs/results.md @@ -29,6 +29,10 @@ The tip of tree commit being tested. It needs to be the full commit hash. Unfortunately the Dashboard API doesn't support git tags as parameters yet. +### --latest + +Return results for the latest commit for the tree. + ## Results actions ### --action=trees diff --git a/kcidev/subcommands/results.py b/kcidev/subcommands/results.py index 2c35b1a..422eda4 100644 --- a/kcidev/subcommands/results.py +++ b/kcidev/subcommands/results.py @@ -44,6 +44,16 @@ def fetch_tree_fast(origin): return fetch_from_api("tree-fast", params) +def get_latest_commit(origin, giturl, branch): + trees = fetch_tree_fast(origin) + for t in trees: + if t["git_repository_url"] == giturl and t["git_repository_branch"] == branch: + return t["git_commit_hash"] + + kci_err("Tree and branch not found.") + raise click.Abort() + + def print_summary(type, n_pass, n_fail, n_inconclusive): kci_msg_nonl(f"{type}:\t") kci_msg_green_nonl(f"{n_pass}") if n_pass else kci_msg_nonl(f"{n_pass}") @@ -148,20 +158,29 @@ def cmd_failed_builds(data, download_logs): is_flag=True, help="Select desired results action", ) +@click.option( + "--latest", + is_flag=True, + help="Select latest results available", +) @click.pass_context -def results(ctx, origin, giturl, branch, commit, action, download_logs): +def results(ctx, origin, giturl, branch, commit, action, download_logs, latest): if action == None or action == "summary": - if not giturl or not branch or not commit: - kci_err("--giturl AND --branch AND --commit are required") + if not giturl or not branch or not ((commit != None) ^ latest): + kci_err("--giturl AND --branch AND (--commit XOR --latest) are required") raise click.Abort() + if latest: + commit = get_latest_commit(origin, giturl, branch) data = fetch_full_results(origin, giturl, branch, commit) cmd_summary(data) elif action == "trees": cmd_list_trees(origin) elif action == "failed-builds": - if not giturl or not branch or not commit: - kci_err("--giturl AND --branch AND commit are required") + if not giturl or not branch or not ((commit != None) ^ latest): + kci_err("--giturl AND --branch AND (--commit XOR --latest) are required") raise click.Abort() + if latest: + commit = get_latest_commit(origin, giturl, branch) data = fetch_full_results(origin, giturl, branch, commit) cmd_failed_builds(data, download_logs)