From patchwork Fri Sep 11 00:11:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olof Johansson X-Patchwork-Id: 1362121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnblN2mWvz9sTg for ; Fri, 11 Sep 2020 10:11:28 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=lixom.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=lixom-net.20150623.gappssmtp.com header.i=@lixom-net.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Ux3z/4Ou; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BnblM6kHLzDqfC for ; Fri, 11 Sep 2020 10:11:27 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lixom.net (client-ip=2607:f8b0:4864:20::102d; helo=mail-pj1-x102d.google.com; envelope-from=olof@lixom.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=lixom.net Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lixom-net.20150623.gappssmtp.com header.i=@lixom-net.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Ux3z/4Ou; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BnblD51tNzDqdj for ; Fri, 11 Sep 2020 10:11:19 +1000 (AEST) Received: by mail-pj1-x102d.google.com with SMTP id t7so831098pjd.3 for ; Thu, 10 Sep 2020 17:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lixom-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2MHdZYLn6aYdGtGKy8zn7JybnUn7XjboWQQPlhpCBeM=; b=Ux3z/4OuYE5CrWVVvokp/dGjd0tU+B2znWViKfdTIJzJNQKddFYK2H15H8e03icxAf J7L/bBxx5aMIia9Zx9vjA9O4/MqEG6ebhoIMaWgwZHlYY8gCzFd7yKGBZjUt0WEpyqhE FigNoaOYiERQXJ1AF7saj/SBzp4F380KX7eCamUCYxHIMjJkWk9YBV6sEihN0tZZ6DPo vVh1KcHHLsZWXulYuMYZRVnjp98jw30Snk80FoKT0GohNAQ+TylzAmkI5IQRfFyRTaAe SI72WTqIlNXyKfCCB5JLAZv+2Zs9RRLXrfXECqjSfFxi7XBuvqkjlmpAQBRWwy0FvBiM g9Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2MHdZYLn6aYdGtGKy8zn7JybnUn7XjboWQQPlhpCBeM=; b=jdtyEsYcvcSE+fLmysvdaC42zIWzkTXtJmJbBL+KERDE3BT5ANmtRVCjx/arteo+0H zU+H/g8hYc4SGu/MhvfZ87TdgHlBD2A5BZyhfREUAOUN0IsvZsfDbu8vuvbjuhoKDSts 5KsAg9LEBeO169UrBT3IzlSmliAZXzx1JiEEAqiGvLblgCetQjyjxEBVz6KLl+ppHEKm zi8GruYTMVkepFDtPdH7XYBBIAAGszRwv+uVqHF5cVC6M6YSm2vWcTbShcuqmbWGPM30 KnDlVbQDXvyPtEGoJAgp6UWlmL6uvvjzlgKD7jQQ9S4qOHrkc+fb3up6rCsE3vVHNZQr 5FWg== X-Gm-Message-State: AOAM533IIfpP0vhQrlqEh/Fmy11fyo3bzJOvSdNSnYGVrXBGdbKTWXoP MACuxjYQvargs09CWrAJe4gog0xBvT6u2A== X-Google-Smtp-Source: ABdhPJwqStnSTPKeShnNmEmvu+ojF3QzpujSZbUeHQskZbh0DxbrYUyVg8ONv4KYldE6XXz7dMDAbQ== X-Received: by 2002:a17:90a:b292:: with SMTP id c18mr2108193pjr.223.1599783075764; Thu, 10 Sep 2020 17:11:15 -0700 (PDT) Received: from lx2k.lixom.net (99-152-116-91.lightspeed.sntcca.sbcglobal.net. [99.152.116.91]) by smtp.gmail.com with ESMTPSA id 68sm225506pfd.64.2020.09.10.17.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 17:11:14 -0700 (PDT) From: Olof Johansson To: patchwork@lists.ozlabs.org Subject: [PATCH] pwclient: Add check-get subcommand Date: Thu, 10 Sep 2020 17:11:09 -0700 Message-Id: <20200911001109.24945-1-olof@lixom.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Provide a subcommand to query the checks ran against a specific patch_id. Also allows formatting of the output, to make it easier to query whether a specific patch has seen any tests (and what their status is). Signed-off-by: Olof Johansson --- pwclient/checks.py | 29 +++++++++++++++++++++++++++++ pwclient/parser.py | 13 +++++++++++++ pwclient/shell.py | 5 +++++ tests/fakes.py | 14 ++++++++++++++ tests/test_checks.py | 19 +++++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/pwclient/checks.py b/pwclient/checks.py index fcb8d07..767729d 100644 --- a/pwclient/checks.py +++ b/pwclient/checks.py @@ -5,6 +5,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import sys +import re from pwclient.xmlrpc import xmlrpclib @@ -29,6 +30,34 @@ def action_info(rpc, check_id): print("- %- 14s: %s" % (key, value)) +def action_get(rpc, patch_id, format_str=None): + checks_list = rpc.patch_check_get(patch_id) + checks = checks_list.get('checks', None) + if checks == None: + return + + if format_str: + format_field_re = re.compile("%{([a-z0-9_]+)}") + + def check_field(matchobj): + fieldname = matchobj.group(1) + + return str(check[fieldname]) + + for check in checks: + print(format_field_re.sub(check_field, format_str)) + else: + s = "Check information for patch id %d" % patch_id + print(s) + print('-' * len(s)) + out = [] + for check in checks: + cout = [] + for key, value in sorted(check.items()): + cout.append("- %- 14s: %s" % (key, value)) + out.append("\n".join(cout)) + print("\n\n".join(out)) + def action_create(rpc, patch_id, context, state, url, description): try: rpc.check_create(patch_id, context, state, url, description) diff --git a/pwclient/parser.py b/pwclient/parser.py index dc3934a..54c9bdd 100644 --- a/pwclient/parser.py +++ b/pwclient/parser.py @@ -111,6 +111,19 @@ installed locales. help="list all projects") projects_parser.set_defaults(subcmd='projects') + check_get_parser = subparsers.add_parser( + 'check-get', add_help=False, + help="get checks for a patch" + ) + check_get_parser.add_argument( + 'patch_id', metavar='PATCH_ID', action='store', type=int, + help="patch ID") + check_get_parser.add_argument( + '-f', '--format', metavar='FORMAT', + help=("print output in the given format. You can use tags matching " + "fields, e.g. %%{context}, %%{state}, or %%{msgid}.")) + check_get_parser.set_defaults(subcmd='check_get') + check_list_parser = subparsers.add_parser( 'check-list', add_help=False, help="list all checks" diff --git a/pwclient/shell.py b/pwclient/shell.py index 1f127ea..02165ba 100644 --- a/pwclient/shell.py +++ b/pwclient/shell.py @@ -211,6 +211,11 @@ def main(argv=sys.argv[1:]): rpc, patch_id, state=args.state, archived=args.archived, commit=args.commit_ref) + elif action == 'check_get': + patch_id = args.patch_id + format_str = args.format + checks.action_get(rpc, patch_id, format_str) + elif action == 'check_list': checks.action_list(rpc) diff --git a/tests/fakes.py b/tests/fakes.py index a2dcc8c..5a8761b 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -69,6 +69,20 @@ def fake_checks(): }, ] +def fake_patch_check(): + return { + 'checks': [{ + 'context': 'hello-world', + 'id': 1, + 'patch_id': 1, + 'state': 'success', + 'target_url': '', + 'user_id': 1 + }], + 'state': 'success', + 'total': 1 + } + def fake_states(): return [ diff --git a/tests/test_checks.py b/tests/test_checks.py index 625d375..1f4038e 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -6,6 +6,25 @@ from pwclient import xmlrpc from . import fakes +def test_action_check_get(capsys): + rpc = mock.Mock() + rpc.patch_check_get.return_value = fakes.fake_patch_check() + + checks.action_get(rpc, 1) + + captured = capsys.readouterr() + + assert captured.out == """\ +Check information for patch id 1 +-------------------------------- +- context : hello-world +- id : 1 +- patch_id : 1 +- state : success +- target_url : +- user_id : 1 +""" + def test_action_check_list(capsys): rpc = mock.Mock() rpc.check_list.return_value = fakes.fake_checks()