[dpdk-ci] [PATCH 5/9] tools: add functionality for setting pw delegates

Ali Alnubani alialnu at oss.nvidia.com
Mon Sep 6 17:45:33 CEST 2021


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
  $ ./maintainers.py --command set_pw_delegate --type series SERIES_ID

Signed-off-by: Ali Alnubani <alialnu at nvidia.com>
---
 tools/maintainers.py | 46 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/tools/maintainers.py b/tools/maintainers.py
index c9b0502..a1ba5fc 100755
--- a/tools/maintainers.py
+++ b/tools/maintainers.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,29 @@ class GitPW(object):
             else:
                 raise
 
+    def set_delegate(self, patch_list, delegate):
+        """Set the delegate for a patch.
+        Only tries to 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']:
+                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):
 
@@ -267,7 +291,8 @@ if __name__ == '__main__':
             '--command',
             choices=(
                 'list_trees',
-                'list_maintainers'),
+                'list_maintainers',
+                'set_pw_delegate'),
             required=True, help='Command to perform')
     options_parser.add_argument(
             '--type',
@@ -325,5 +350,20 @@ 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)
+            else:
+                print('No maintainers found. Not setting a delegate.')
-- 
2.25.1



More information about the ci mailing list