DPDK CI discussions
 help / color / mirror / Atom feed
From: Ali Alnubani <alialnu@oss.nvidia.com>
To: <ci@dpdk.org>
Cc: <thomas@monjalon.net>, <jerinj@marvell.com>,
	<ferruh.yigit@intel.com>, <david.marchand@redhat.com>,
	<juraj.linkes@pantheon.tech>
Subject: [dpdk-ci] [PATCH v3 05/10] tools: add functionality for setting pw delegates
Date: Mon, 18 Oct 2021 10:44:55 +0300
Message-ID: <20211018074500.16199-6-alialnu@nvidia.com> (raw)
In-Reply-To: <20211018074500.16199-1-alialnu@nvidia.com>

A new command was added to set patch delegates in Patchwork
based on the emails found in DPDK's MAINTAINERS file.

Example usage:
  $ export MAINTAINERS_FILE_PATH=/path/to/dpdk/MAINTAINERS
  $ ./pw_maintainers_cli.py --type series set_pw_delegate SERIES_ID

Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
---
Changes in v3:
- Added an argument to force overriding delegates (Suggested by Thomas
  Monjalon).

 tools/pw_maintainers_cli.py | 57 +++++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 3 deletions(-)

diff --git a/tools/pw_maintainers_cli.py b/tools/pw_maintainers_cli.py
index 4c95755..0e9643f 100755
--- a/tools/pw_maintainers_cli.py
+++ b/tools/pw_maintainers_cli.py
@@ -14,6 +14,7 @@ from requests.exceptions import HTTPError
 from git_pw import config
 from git_pw import api
 from git_pw import utils
+from git_pw import patch as git_pw_patch
 
 """
 Description:
@@ -84,6 +85,33 @@ class GitPW(object):
             else:
                 raise
 
+    def set_delegate(self, patch_list, delegate, force=False):
+        """Set the delegate for a patch.
+        If 'force' isn't set to True, only set a delegate for patches that
+        don't have one set already.
+
+        Reference:
+        https://github.com/getpatchwork/git-pw/blob/76b79097dc0a57c89b45dd53d9cacb7ff7b31bb2/git_pw/patch.py#L167
+        """
+        users = api.index('users', [('q', delegate)])
+        if len(users) != 1:
+            # Zero or multiple users found
+            print('Cannot choose a Patchwork user to delegate to from '
+                  'user list ({}). Skipping..'.format(users))
+            return
+        for patch in patch_list:
+            if patch['delegate'] != None and \
+                    (patch['delegate'].get('email') == users[0].get('email') or \
+                    not force):
+                print('Patch {} is already delegated to {}. '
+                      'Skipping..'.format(
+                          patch['id'], patch['delegate']['email']))
+                continue
+            print("Delegating patch {} to {}..".format(
+                patch['id'], users[0]['email']))
+            _ = api.update(
+                    'patches', patch['id'], [('delegate', users[0]['id'])])
+
 
 class Diff(object):
 
@@ -286,16 +314,22 @@ if __name__ == '__main__':
             default=os.environ.get('PW_TOKEN', utils.git_config('pw.token')),
             help='Authentication token')
 
+    parser.add_argument(
+            '--force_set_delegate',
+            action='store_true', required=False,
+            help='Force setting the PW delegate, '
+                 'even if it is already set.')
     parser.add_argument(
             'command',
             choices=[
-                'list_trees', 'list_maintainers'],
+                'list_trees', 'list_maintainers', 'set_pw_delegate'],
             help='Command to perform')
     parser.add_argument(
             'id', type=int, help='patch/series id')
 
     args = parser.parse_args()
 
+    force_set_delegate = args.force_set_delegate
     command = args.command
     resource_type = args.type
     _id = args.id
@@ -325,5 +359,22 @@ if __name__ == '__main__':
 
     if command == 'list_trees':
         print(tree.split('/')[-1])
-    elif command == 'list_maintainers':
-        print(*maintainers.get_maintainers(tree), sep='\n')
+    if command in ['list_maintainers', 'set_pw_delegate']:
+        maintainer_list = maintainers.get_maintainers(tree)
+        if command == 'list_maintainers':
+            print(*maintainer_list, sep='\n')
+        elif command == 'set_pw_delegate':
+            if len(maintainer_list) > 0:
+                # Get the email of the first maintainer in the list.
+                try:
+                    delegate = re.match(
+                            r".*\<(?P<email>.*)\>",
+                            maintainer_list[0]).group('email')
+                except AttributeError:
+                    print("Unexpected format: '{}'".format(maintainer_list[0]))
+                    sys.exit(1)
+                _git_pw.set_delegate(
+                        patch_list, delegate,
+                        force=force_set_delegate)
+            else:
+                print('No maintainers found. Not setting a delegate.')
-- 
2.25.1


  parent reply	other threads:[~2021-10-18  7:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18  7:44 [dpdk-ci] [PATCH v3 00/10] Automatic patchwork delegation Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 01/10] tools: rename guess_git_tree script Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 02/10] tools: match by tree URL instead of tree name Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 03/10] tools: update script usage Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 04/10] tools: add functionality for detecting tree maintainers Ali Alnubani
2021-10-18  7:44 ` Ali Alnubani [this message]
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 06/10] add git-pw to requirements file Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 07/10] tools: filter new Patchwork IDs by date Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 08/10] tools: support fetching series Ali Alnubani
2021-10-18  7:44 ` [dpdk-ci] [PATCH v3 09/10] tools: filter new patchwork IDs by project name Ali Alnubani
2021-10-18  7:45 ` [dpdk-ci] [PATCH v3 10/10] tools: skip the IDs we already fetched Ali Alnubani
2021-10-18  8:06 ` [dpdk-ci] [PATCH v3 00/10] Automatic patchwork delegation Ali Alnubani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211018074500.16199-6-alialnu@nvidia.com \
    --to=alialnu@oss.nvidia.com \
    --cc=ci@dpdk.org \
    --cc=david.marchand@redhat.com \
    --cc=ferruh.yigit@intel.com \
    --cc=jerinj@marvell.com \
    --cc=juraj.linkes@pantheon.tech \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK CI discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/ci/0 ci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ci ci/ http://inbox.dpdk.org/ci \
		ci@dpdk.org
	public-inbox-index ci

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.ci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git