From nobody Fri Apr 26 21:13:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606383787; cv=none; d=zohomail.com; s=zohoarc; b=mB6kqpZvbuc4Ik944FtNJByCLJDWyiHYGkcbNEF+dyu0pfA+7DnGnQlF9bPci2cb2hj3dTTY9MneLSYhK9qsciHPHP2PbCOrOJe/31NEBT4qpGXurH0q6xx7a4hTrrAFTZr2U6kCFiN2NU/S37xH7SKKUZA4wPlQ85sx2IetTeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606383787; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3hc+vQPhXn/SHL5Vsx++q9nLVuCpIP+2vP20FFQLJ34=; b=QWb8J5ua/wUmD9doL6VnW2kUhxi8FqcxMmZjgRGcJ1g+c/lRyXNn7dFhwjk0M+/Lrh7Dn5Ak8f+2trH+El/UjTIU5pwBVRaJiAEu3FIzTZU6vSAmW3Lg2ylb1d82uQuTNMjL5/hmAzpRs4OVM6LjoUCcZWq2NHRZ+xmil3dN2fY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160638378775320.068617246841313; Thu, 26 Nov 2020 01:43:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-9Dve9152OluYjhzPSRtLYw-1; Thu, 26 Nov 2020 04:43:03 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CEB11087D8B; Thu, 26 Nov 2020 09:43:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 145345D9CA; Thu, 26 Nov 2020 09:43:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0BEAE180954D; Thu, 26 Nov 2020 09:43:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AQ9gxo0016129 for ; Thu, 26 Nov 2020 04:42:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8B733100BFD1; Thu, 26 Nov 2020 09:42:59 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87567100BCB0 for ; Thu, 26 Nov 2020 09:42:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B596108C205 for ; Thu, 26 Nov 2020 09:42:56 +0000 (UTC) Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-426-LEkA77WjPBK46MO9mnUQbA-1; Thu, 26 Nov 2020 04:42:50 -0500 Received: from localhost (ec2-52-56-101-76.eu-west-2.compute.amazonaws.com [52.56.101.76]) by mx.zoho.com.cn with SMTPS id 1606383743588589.9879592661945; Thu, 26 Nov 2020 17:42:23 +0800 (CST) X-MC-Unique: 9Dve9152OluYjhzPSRtLYw-1 X-MC-Unique: LEkA77WjPBK46MO9mnUQbA-1 From: fam@euphon.net To: patchew-devel@redhat.com Message-ID: <20201126094219.2333219-1-fam@euphon.net> Date: Thu, 26 Nov 2020 09:42:19 +0000 MIME-Version: 1.0 X-ZohoCNMailClient: External X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Mimecast-Spam-Signature: yes X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0AQ9gxo0016129 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] cli: Add gitlab-pipeline-check subcommand X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=patchew-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fam Zheng A standalone command, just for convenience of checking pipeline status with gitlab public API. Can be used in testing scripts. --- patchew-cli | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/patchew-cli b/patchew-cli index f872c1d..c55ebc3 100755 --- a/patchew-cli +++ b/patchew-cli @@ -30,6 +30,8 @@ COOKIE_FILENAME =3D os.path.expanduser("~/.patchew.cookie= ") class APIError(Exception): pass =20 +def git_head(): + return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().= strip() =20 def git_clone_repo(clone, remote, head, logf, checkout=3DTrue, recursive= =3DFalse): cache_repo =3D os.path.join( @@ -108,6 +110,9 @@ def git_clone_repo(clone, remote, head, logf, checkout= =3DTrue, recursive=3DFalse): ["git", "checkout", head, "-b", "test"], stderr=3Dlogf, stdout= =3Dlogf, cwd=3Dclone ) =20 +def http_get(url): + logging.debug("http get: " + url) + return urllib.request.urlopen(url).read() =20 class SubCommand(object): """ Base class of subcommand""" @@ -698,6 +703,50 @@ class TesterCommand(SubCommand): time.sleep(60) return 0 =20 +class GitlabPipelineCheckCommand(SubCommand): + name =3D "gitlab-pipeline-check" + def arguments(self, parser): + parser.add_argument("--project", "-p", required=3DTrue) + parser.add_argument("--head", "-H", type=3Dstr) + parser.add_argument("--gitlab", "-g", type=3Dstr, default=3D"https= ://gitlab.com/", + help=3D"gitlab server addr") + + def _find_pipeline(self, pipelines, sha): + for p in pipelines: + if p['sha'] =3D=3D sha: + return p + + def do(self, args, argv): + head =3D args.head or git_head() + gitlab =3D args.gitlab + if gitlab.endswith("/"): + gitlab =3D gitlab[:-1] + + project_encoded =3D urllib.parse.quote(args.project, safe=3D'') + print("Looking up pipeline...") + p =3D None + for page in range(10): + url =3D "%s/api/v4/projects/%s/pipelines/?page=3D%d&per_page= =3D100" % ( + gitlab, project_encoded, page) + resp =3D json.loads(http_get(url)) + p =3D self._find_pipeline(resp, head) + if p: + break + if not p: + raise Exception("Pipeline not found") + print("Found pipeline %d: %s" % (p['id'], p['web_url'])) + + while p['status'] not in ['success', 'failed']: + print("Waiting for pipeline to finish...") + time.sleep(120) + url =3D "%s/api/v4/projects/%s/pipelines/%d" % ( + gitlab, project_encoded, p['id']) + p =3D json.loads(http_get(url)) + if p['status'] =3D=3D 'success': + print("Pipeline succeeded") + return 0 + print("Pipeline failed") + return 1 =20 class ApplyFailedException(Exception): pass --=20 2.25.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel