From 7f14e436b8173e2076e2882b086a1e9db217cc53 Mon Sep 17 00:00:00 2001 From: mugdhadhole1 Date: Fri, 6 Dec 2024 14:27:22 +0530 Subject: [PATCH] feature: support query string as an argument in lobster codebeamer Query string (CBQL query) can be now passed as a command line argument to the lobster codebeamer tool --- lobster/tools/codebeamer/codebeamer.py | 45 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/lobster/tools/codebeamer/codebeamer.py b/lobster/tools/codebeamer/codebeamer.py index fd2ad674..7dab015b 100755 --- a/lobster/tools/codebeamer/codebeamer.py +++ b/lobster/tools/codebeamer/codebeamer.py @@ -152,21 +152,27 @@ def get_many_items(cb_config, item_ids): return rv -def get_query(mh, cb_config, query_id): +def get_query(mh, cb_config, query_id, query_string): assert isinstance(mh, Message_Handler) assert isinstance(cb_config, dict) - assert isinstance(query_id, int) + assert isinstance(query_id, int) or query_id is None + assert isinstance(query_string, str) or query_string is None rv = [] page_id = 1 total_items = None while total_items is None or len(rv) < total_items: print("Fetching page %u of query..." % page_id) - url = "%s/reports/%u/items?page=%u&pageSize=%u" % \ - (cb_config["base"], - query_id, - page_id, - cb_config["page_size"]) + if query_id is not None: + url = "%s/reports/%u/items?page=%u&pageSize=%u" % \ + (cb_config["base"], + query_id, + page_id, + cb_config["page_size"]) + else: + url = "%s/items/query?queryString=%s" % \ + (cb_config["base"], + query_string) data = query_cb_single(cb_config, url) assert len(data) == 4 @@ -183,8 +189,12 @@ def get_query(mh, cb_config, query_id): else: assert total_items == data["total"] - rv += [to_lobster(cb_config, cb_item["item"]) - for cb_item in data["items"]] + if query_id is not None: + rv += [to_lobster(cb_config, cb_item["item"]) + for cb_item in data["items"]] + elif query_string is not None: + rv += [to_lobster(cb_config, cb_item) + for cb_item in data["items"]] page_id += 1 @@ -419,6 +429,10 @@ def main(): metavar="CB_QUERY_ID", default=None) + modes.add_argument("--query-string", + metavar="CB_QUERY_STRING", + default=None) + ap.add_argument("--config", help=("name of codebeamer " "config file, supported references: '%s'" % @@ -531,11 +545,22 @@ def main(): if query_id < 1: ap.error("query-id must be a positive") + elif options.query_string: + try: + if options.query_string.isdigit(): + raise ValueError("query_string must be a string") + options.query_string = str(options.query_string) + except ValueError as e: + ap.error(str(e)) + try: if options.import_tagged: items = import_tagged(mh, cb_config, items_to_import) elif options.import_query: - items = get_query(mh, cb_config, query_id) + items = get_query(mh, cb_config, query_id, options.query_string) + elif options.query_string: + query_id = None + items = get_query(mh, cb_config, query_id, options.query_string) except LOBSTER_Error: return 1