From patchwork Wed Sep 20 12:32:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "plaisthos (Code Review)" X-Patchwork-Id: 3355 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:2697:b0:d7:3b0f:3938 with SMTP id ha23csp2286825dyb; Wed, 20 Sep 2023 05:33:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD1RsIasrdzHnKMJSI3NPjdkFNW1pzkiMM4p1SqypzBXFtJDyEs83AYhENtDTK7HSYcElX X-Received: by 2002:a17:903:41d1:b0:1b3:d8ac:8db3 with SMTP id u17-20020a17090341d100b001b3d8ac8db3mr2227391ple.6.1695213224244; Wed, 20 Sep 2023 05:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695213224; cv=none; d=google.com; s=arc-20160816; b=wbG86gTDTt4iJXrCb24z00l+o0BvFNAYGRWu5pug0Ql8gmcxnGIMk7UUWEYEteiCc+ WmP934fMqIW3f4cis3m3OekDnhrVGR54H0U06MB96PlfIZLlQWJlOoclFTDVa/OCACvo Q2eYkLLvoNpFRFgoDonQI+LiaTAVT28UGtvhy+4LtbNuS6JHbO4bfwMgo+QzLyYoaZce G8gmnxiAUbW9kBeAhUvd8PXdHtm9U5c7mVF2L5woxWEQPTq/osTwmm3El4KZzj2b1+2R L4fR3MgA5xULH/Osdva2wq6nB7l7zQDdBjb4Jf2L0pEl983evy/0emDgMrhmZkrOy/Hz B5iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:user-agent:mime-version :message-id:references:auto-submitted:cc:date:from:dkim-signature :dkim-signature:dkim-signature; bh=ZMthSpKCd4P8MI1pqCyvY9jtKmaZYHD57ZD2aVcJz+Q=; fh=smjZBu6iNkWiUqneddhXe9SViGbN07L/0qKvVAHuico=; b=x9Ym7GKkiZ79Wkk+iUt02fsX5/c7lVpSb2vpIG/BHu0JSkT/YLGgWLNFJ3dUTHOVTS CfU2GChs+UQu6dtXr14vjQPOCGGpqY+Kb/td7z9z2ndy/EYV5P7ArzLZNhx+VDv2xWpT KGAhDH64lJqNuyEFSvO/6uNk5IkrfkSfC1GC8dVmfoNUYy3+7CXzcGV/Orf0WUJygHF7 40mHlzgy/OIiykmV4TJY7da010XbClmfeSRUM4HuCtf41VH5VIrbE7kKa4wiNOpM7kuj JArnkKuonBwkyI3qHf7ZRrcgUTVkN3337H5ORQXUhNexOOkQXb1RMbWXYFG6hSC8wCjy 9iYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="QcC5/8vp"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LL2L1xr0; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=GggTNxys; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id n12-20020a170903110c00b001bbc066c626si12192851plh.428.2023.09.20.05.33.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2023 05:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="QcC5/8vp"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LL2L1xr0; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=GggTNxys; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qiwNw-0003TN-TC; Wed, 20 Sep 2023 12:32:53 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qiwNu-0003TG-Uv for openvpn-devel@lists.sourceforge.net; Wed, 20 Sep 2023 12:32:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:Date:From :Sender:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xGrHwRJSBvIIbZJv/xbKgtNxM8NILi29DaABnsFpnec=; b=QcC5/8vpaCSRM6uLk0fCakfU8S 0EmfNto/+Hlpmj/s8+qfHWFgI0P386AFTfDTToNUsspZTH/ZBuWKJxBMZPcayf9dhW03FEeHBGukh BKmEMDqMh2ooykXDoJHmZpnxi6zhqwDvyFDL2thN1rMwW2PQGCdhTwfZqHrgp+/9YqIs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:Date:From:Sender:To:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=xGrHwRJSBvIIbZJv/xbKgtNxM8NILi29DaABnsFpnec=; b=L L2L1xr080YWyXOxoBDQ1mCKZA+6nEuhDX6a6LE+Novbd8a7RuQDpn2qoA7ogt9QXuqmS62LC/FR8D Vm8gxpuXrxl8BIIWQgl8Ezc0shkMhwS6fzf5gk1e4cr5CJNWw0pydCsAWPuNYGNIpA5m9mrJ1ridb bI+s7ytWz91uKEAk=; Received: from mail-wr1-f44.google.com ([209.85.221.44]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qiwNq-0003DH-LW for openvpn-devel@lists.sourceforge.net; Wed, 20 Sep 2023 12:32:51 +0000 Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3214cdb4b27so3203348f8f.1 for ; Wed, 20 Sep 2023 05:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1695213160; x=1695817960; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:date:from:from:to:cc :subject:date:message-id:reply-to; bh=xGrHwRJSBvIIbZJv/xbKgtNxM8NILi29DaABnsFpnec=; b=GggTNxysR01zqAFt1Gd0xJCkC5Rqe+UdN1jXL1OQgcoHoD6xULSwn7I87QziS9CYOr zJ5jd6RKsfoxEDPk84swXbBi+YgPpQSRJNNhIcmlmTxdwMkocPDu+Og0euqE6CjHMeoG iITwKXxPzy3ut5UP7ikC7hA5unVPo+FwlX09TO0uTqKA9d/JXHHnriUkP6Clv20ZRz7J BynegjanZixFZurqxi9bJYHlCX/Njgv80sLTVcBw7LIYqwf3wB9kajz81kFq2TfCLyR7 Hs460dg+eq8cvXhov29HZMnj7ckIb01Mh6sqVJR8mjVy25KUQV/VL0Q0yNtrgMmOLnJj pZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695213160; x=1695817960; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xGrHwRJSBvIIbZJv/xbKgtNxM8NILi29DaABnsFpnec=; b=KJc02LA7u0rKjNFb71o7WDtX4D/quzj3BoNI6FgaiJKgUQhgDr82gLUK2PP57zDkPf MGcUp4apee+dwodaQmzeP7T8JQjXJHmYtoUb8O17mKbrpUaf0XrxW3C7js668ekdBbSe QND6IdrbFOGo1A/QSdKB4REc3YYfqBTidRPywHDOePbYe/GpaZvggm7yktK0j+M9j2zg blXoltvvJFna9c7RgfjrT+dXyu7jxW4x03LyJp+8qlpGH1S3WvnpbTPL1jMKSFJu+OJl 3mH0HP7SR830vqyO1SKfuBasLDWNVY5dedZcgLwIBgoNsWtItFtCHacm5luTx2cKkJ52 4zqQ== X-Gm-Message-State: AOJu0YyraKNoEG/JynRmkKf6A9nfmRHK+BS5db4RHBtXOfiXvI3AIQYU 1q2CKxtxDMCXKePjb/nyqdgQ00/oGfXSUC2tpAQ= X-Received: by 2002:a5d:4dcf:0:b0:319:82c9:8e7d with SMTP id f15-20020a5d4dcf000000b0031982c98e7dmr2296989wru.31.1695213159656; Wed, 20 Sep 2023 05:32:39 -0700 (PDT) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id t3-20020a5d5343000000b00317ab75748bsm18345715wrv.49.2023.09.20.05.32.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:32:39 -0700 (PDT) From: "flichtenheld (Code Review)" X-Google-Original-From: "flichtenheld (Code Review)" X-Gerrit-PatchSet: 1 Date: Wed, 20 Sep 2023 12:32:38 +0000 Cc: openvpn-devel Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: If4e9c2e58441efb3fd00872cd62d1cc6c607f160 X-Gerrit-Change-Number: 361 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 6ec7e8a8ecf567adcf4ecdd95803558faba482ac References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: 1.0 (+) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: flichtenheld has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/361?usp=email ) Change subject: dev-tools/gerrit-send-mail.py: tool to send Gerrit patchsets to Patchwork Content analysis details: (1.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.44 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 1.2 MISSING_HEADERS Missing To: header 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1qiwNq-0003DH-LW Subject: [Openvpn-devel] [M] Change in openvpn[master]: dev-tools/gerrit-send-mail.py: tool to send Gerrit patchsets to Patch... X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: frank@lichtenheld.com, openvpn-devel@lists.sourceforge.net Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1777559901854584999?= X-GMAIL-MSGID: =?utf-8?q?1777559901854584999?= X-getmail-filter-classifier: gerrit message type newchange flichtenheld has uploaded this change for review. ( http://gerrit.openvpn.net/c/openvpn/+/361?usp=email ) Change subject: dev-tools/gerrit-send-mail.py: tool to send Gerrit patchsets to Patchwork ...................................................................... dev-tools/gerrit-send-mail.py: tool to send Gerrit patchsets to Patchwork Since we're trying to use Gerrit for patch reviews, but the actual merge process is still implemented against the ML and Patchwork, I wrote a script that attempts to bridge the gap. It extracts all relevant information about a patch from Gerrit and converts it into a mail compatible to git-am. Mostly this work is done by Gerrit already, since we can get the original patch in git format-patch format. But we add Acked-by information according to the approvals in Gerrit and some other metadata. This should allow the merge to happen based on this one mail alone. Change-Id: If4e9c2e58441efb3fd00872cd62d1cc6c607f160 Signed-off-by: Frank Lichtenheld --- A dev-tools/gerrit-send-mail.py 1 file changed, 116 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/61/361/1 diff --git a/dev-tools/gerrit-send-mail.py b/dev-tools/gerrit-send-mail.py new file mode 100644 index 0000000..9aa7a5a --- /dev/null +++ b/dev-tools/gerrit-send-mail.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 OpenVPN Inc +# Copyright (C) 2023 Frank Lichtenheld +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Extract a patch from Gerrit and transform it in a file suitable as input +# for git send-email. + +import argparse +import base64 +from datetime import timezone +import json +import sys +from urllib.parse import urlparse + +import dateutil.parser +import requests + +def get_details(args): + params = { 'o': [ 'CURRENT_REVISION', 'LABELS', 'DETAILED_ACCOUNTS' ] } + r = requests.get(args.url + '/changes/' + args.changeid, params=params) + print(r.url) + json_txt = r.text.removeprefix(")]}'\n") + json_data = json.loads(json_txt) + assert len(json_data["revisions"]) == 1 # CURRENT_REVISION works as expected + revision = json_data["revisions"].popitem()[1]["_number"] + assert "Code-Review" in json_data["labels"] + acked_by = [] + for reviewer in json_data["labels"]["Code-Review"]["all"]: + if "value" in reviewer: + assert reviewer["value"] >= 0 # no NACK + if reviewer["value"] == 2: + ack = "{} <{}>".format(reviewer["display_name"], reviewer["email"]) + print("Acked-by: " + ack) + acked_by.append(ack) + change_id = json_data["change_id"] + # assumes that the created date in Gerrit is in UTC + utc_stamp = dateutil.parser.parse(json_data["created"]).replace(tzinfo=timezone.utc).timestamp() + # convert to milliseconds as used in message id + created_stamp = int(utc_stamp * 1000) + hostname = urlparse(args.url).hostname + msg_id = f"gerrit.{created_stamp}.{change_id}@{hostname}" + return { "revision": revision, + "project": json_data["project"], + "target": json_data["branch"], + "msg_id": msg_id, + "acked_by": acked_by } + +def get_patch(details, args): + r = requests.get("{}/changes/{}/revisions/{}/patch?download".format(args.url, args.changeid, details["revision"])) + print(r.url) + patch_text = base64.b64decode(r.text).decode() + return patch_text + +def apply_patch_mods(patch_text, details, args): + signed_off_start = patch_text.rindex("\nSigned-off-by: ") + signed_off_end = patch_text.index("\n", signed_off_start + 1) + 1; + comment_start = patch_text.index("\n---\n") + len("\n---\n") + assert comment_start > signed_off_end + acked_by_text = "" + acked_by_names = "" + for ack in details["acked_by"]: + acked_by_text += f"Acked-by: {ack}\n" + acked_by_names += f"{ack}\n" + patch_text_mod = patch_text[:signed_off_end] \ + + acked_by_text \ + + patch_text[signed_off_end:comment_start] \ + + """ +This change was reviewed on Gerrit and approved by at least one +developer. I request to merge it to {target}. + +Gerrit URL: {url}/c/{project}/+/{changeid} +This mail reflects revision {revision} of this Change. +Acked-by according to Gerrit (reflected above): +{acked_by_names} + """.format( + url=args.url, + changeid=args.changeid, + acked_by_names=acked_by_names, + **details + ) \ + + patch_text[comment_start:] + filename = "gerrit-{}-{}.patch".format(args.changeid, details["revision"]) + with open(filename, "w") as patch_file: + patch_file.write(patch_text_mod) + print("send with:") + print("git send-email --in-reply-to {} {}".format(details["msg_id"], filename)) + +def main(): + parser = argparse.ArgumentParser( + prog="gerrit-send-mail", + description="Send patchset from Gerrit to mailing list", + ) + parser.add_argument('changeid') + parser.add_argument('-u', '--url', default='https://gerrit.openvpn.net') + args = parser.parse_args() + + details = get_details(args) + patch = get_patch(details, args) + apply_patch_mods(patch, details, args) + +if __name__ == "__main__": + sys.exit(main())