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 02/10] tools: match by tree URL instead of tree name
Date: Mon, 18 Oct 2021 10:44:52 +0300	[thread overview]
Message-ID: <20211018074500.16199-3-alialnu@nvidia.com> (raw)
In-Reply-To: <20211018074500.16199-1-alialnu@nvidia.com>

The tree URL has more information. It can be used to
get the maintainer of a tree, and it includes the tree name anyway.
Although we can construct the tree URL by prepending
"git://dpdk.org/next/" to the trees that have "next-" in their name,
and prepending "git://dpdk.org/" to anything else, it would be safer
to read the URL from the MAINTAINERS file just in case new trees that
don't follow this rule were added.

Also try to use named capture groups as much as possible.

Signed-off-by: Ali Alnubani <alialnu@nvidia.com>
---
 tools/pw_maintainers_cli.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/tools/pw_maintainers_cli.py b/tools/pw_maintainers_cli.py
index a31f605..343e9f5 100755
--- a/tools/pw_maintainers_cli.py
+++ b/tools/pw_maintainers_cli.py
@@ -46,7 +46,8 @@ Or if you want to use inside other scripts:
     maintainers = Maintainers()
     patch_id = 52199
     files = Diff.find_filenames(_git_pw.api_get('patches', patch_id)['diff'])
-    tree = maintainers.get_tree(files)
+    tree_url = maintainers.get_tree(files)
+    tree_name = tree_url.split('/')[-1]
 """
 
 
@@ -116,9 +117,9 @@ class Diff(object):
 class Maintainers(object):
 
     file_regex = r'F:\s(.*)'
-    tree_regex = r'T: git:\/\/dpdk\.org(?:\/next)*\/(.*)'
+    tree_regex = r'T: (?P<url>git:\/\/dpdk\.org(?:\/next)*\/(?P<name>.*))'
     section_regex = r'([^\n]*)\n-+.*?(?=([^\n]*\n-+)|\Z)'
-    subsection_regex = r'[^\n](?:(?!\n{{2}}).)*?^F: {}(?:(?!\n{{2}}).)*'
+    subsection_regex = r'[^\n](?:(?!\n{{2}}).)*?^{}: {}$(?:(?!\n{{2}}).)*'
 
     def __init__(self):
         with open(MAINTAINERS_FILE_PATH) as fd:
@@ -151,8 +152,8 @@ class Maintainers(object):
             if _tree:
                 tree_list.append(_tree)
         tree = self.get_common_denominator(tree_list)
-        if tree == '':
-            tree = 'dpdk'
+        if not tree:
+            tree = 'git://dpdk.org/dpdk'
         return tree
 
     def _get_tree(self, filename):
@@ -180,7 +181,7 @@ class Maintainers(object):
 
         found_match = False
         # Find the block containing filename.
-        regex = self.subsection_regex.format(re.escape(matching_pattern))
+        regex = self.subsection_regex.format('F', re.escape(matching_pattern))
         subsection_match = re.findall(
                 regex,
                 self.maintainers_txt,
@@ -191,7 +192,7 @@ class Maintainers(object):
             tree_match = re.search(
                     self.tree_regex, subsection)
             if tree_match:
-                tree = tree_match.group(1)
+                tree = tree_match.group('url')
                 self.matched[matching_pattern] = tree
                 found_match = True
 
@@ -204,7 +205,7 @@ class Maintainers(object):
                             self.tree_regex,
                             section.group(0).split('\n\n')[0])
                     if tree_match:
-                        tree = tree_match.group(1)
+                        tree = tree_match.group('url')
 
         self.matched[matching_pattern] = tree
         return tree
@@ -228,8 +229,8 @@ class Maintainers(object):
             os.path.commonprefix(_tree_list).rstrip('-').replace(
                     'dpdk-next-net-virtio', 'dpdk-next-virtio')
         # There is no 'dpdk-next' named tree.
-        if common_prefix == 'dpdk-next':
-            common_prefix = 'dpdk'
+        if common_prefix.endswith('dpdk-next') or common_prefix.endswith('/'):
+            common_prefix = 'git://dpdk.org/dpdk'
         return common_prefix
 
 
@@ -289,4 +290,4 @@ if __name__ == '__main__':
     files = []
     for patch in patch_list:
         files += Diff.find_filenames(patch['diff'])
-    print(maintainers.get_tree(files))
+    print(maintainers.get_tree(files).split('/')[-1])
-- 
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 ` Ali Alnubani [this message]
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 ` [dpdk-ci] [PATCH v3 05/10] tools: add functionality for setting pw delegates Ali Alnubani
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-3-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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).