You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "jsancio (via GitHub)" <gi...@apache.org> on 2023/04/05 21:21:28 UTC

[GitHub] [kafka] jsancio commented on a diff in pull request #11096: Adding reviewers.py to help tag reviewers in commit message

jsancio commented on code in PR #11096:
URL: https://github.com/apache/kafka/pull/11096#discussion_r1159029690


##########
reviewers.py:
##########
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from collections import defaultdict
+import operator
+import os
+import re
+
+
+def prompt_for_user():
+    while True:
+        try:
+            user_input = input("\nName or email (case insensitive): ") 
+        except (KeyboardInterrupt, EOFError):
+            return None
+        clean_input = user_input.strip().lower()
+        if clean_input != "":
+            return clean_input
+
+
+if __name__ == "__main__":
+    print("Utility to help generate 'Reviewers' string for Pull Requests. Use Ctrl+D or Ctrl+C to exit")
+    
+    stream = os.popen("git log | grep Reviewers")
+    lines = stream.readlines()
+    all_reviewers = defaultdict(int)
+    for line in lines:
+        stripped = line.strip().lstrip("Reviewers: ")
+        reviewers = stripped.split(",")
+        for reviewer in reviewers:
+            all_reviewers[reviewer.strip()] += 1 
+    parsed_reviewers = []
+
+    for item in all_reviewers.items():
+        m = re.match("(?P<name>.*)\s<(?P<email>.*)>", item[0])
+        if m is not None and len(m.groups()) == 2:
+            if item[1] > 2:
+                parsed_reviewers.append((m.group("name"), m.group("email"), item[1]))
+    
+    selected_reviewers = []
+    while True:
+        if len(selected_reviewers) != 0:
+            print(f"Reviewers so far: {selected_reviewers}")
+        user_input = prompt_for_user()
+        if user_input is None:
+            break
+        candidates = []
+        for reviewer, email, count in parsed_reviewers:
+            if reviewer.lower().startswith(user_input) or email.lower().startswith(user_input):
+                candidates.append((reviewer, email, count))
+            if len(candidates) == 10:
+                break
+        if len(candidates) == 0:
+            continue
+
+        print("\nPossible matches (in order of most recent):")

Review Comment:
   Should we mention that the number in the parenthesis is the number of occurrences? How about something like:
   ```python
           print("\nMatches order by most recent (the number in the parenthesis is the number of occurrences):")
   ```
   or we can change the formatting to something like:
   ```
   Name <email> (reviews=123)
   ```



##########
reviewers.py:
##########
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from collections import defaultdict
+import operator
+import os
+import re
+
+
+def prompt_for_user():
+    while True:
+        try:
+            user_input = input("\nName or email (case insensitive): ") 
+        except (KeyboardInterrupt, EOFError):
+            return None
+        clean_input = user_input.strip().lower()
+        if clean_input != "":
+            return clean_input
+
+
+if __name__ == "__main__":
+    print("Utility to help generate 'Reviewers' string for Pull Requests. Use Ctrl+D or Ctrl+C to exit")
+    
+    stream = os.popen("git log | grep Reviewers")

Review Comment:
   How about this since you are `lstrip("Reviewers: ")` later in the code?
   ```python
       stream = os.popen('git log --grep "Reviewers: " --format=%b | grep "Reviewers: "')
   ```



##########
reviewers.py:
##########
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from collections import defaultdict
+import operator
+import os
+import re
+
+
+def prompt_for_user():
+    while True:
+        try:
+            user_input = input("\nName or email (case insensitive): ") 
+        except (KeyboardInterrupt, EOFError):
+            return None
+        clean_input = user_input.strip().lower()
+        if clean_input != "":
+            return clean_input
+
+
+if __name__ == "__main__":
+    print("Utility to help generate 'Reviewers' string for Pull Requests. Use Ctrl+D or Ctrl+C to exit")
+    
+    stream = os.popen("git log | grep Reviewers")
+    lines = stream.readlines()
+    all_reviewers = defaultdict(int)
+    for line in lines:
+        stripped = line.strip().lstrip("Reviewers: ")
+        reviewers = stripped.split(",")
+        for reviewer in reviewers:
+            all_reviewers[reviewer.strip()] += 1 
+    parsed_reviewers = []
+
+    for item in all_reviewers.items():
+        m = re.match("(?P<name>.*)\s<(?P<email>.*)>", item[0])
+        if m is not None and len(m.groups()) == 2:
+            if item[1] > 2:
+                parsed_reviewers.append((m.group("name"), m.group("email"), item[1]))
+    
+    selected_reviewers = []
+    while True:
+        if len(selected_reviewers) != 0:
+            print(f"Reviewers so far: {selected_reviewers}")
+        user_input = prompt_for_user()
+        if user_input is None:
+            break
+        candidates = []
+        for reviewer, email, count in parsed_reviewers:
+            if reviewer.lower().startswith(user_input) or email.lower().startswith(user_input):
+                candidates.append((reviewer, email, count))
+            if len(candidates) == 10:
+                break
+        if len(candidates) == 0:
+            continue
+
+        print("\nPossible matches (in order of most recent):")
+        for i, candidate in zip(range(10), candidates):
+            print(f"[{i+1}] {candidate[0]} {candidate[1]} ({candidate[2]})")

Review Comment:
   Can we print it using the standard `name <email>` address format? E.g.
   ```python
               print(f"[{i+1}] {candidate[0]} <{candidate[1]}> ({candidate[2]})")
   ```



##########
reviewers.py:
##########
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from collections import defaultdict
+import operator
+import os
+import re
+
+
+def prompt_for_user():
+    while True:
+        try:
+            user_input = input("\nName or email (case insensitive): ") 
+        except (KeyboardInterrupt, EOFError):
+            return None
+        clean_input = user_input.strip().lower()
+        if clean_input != "":
+            return clean_input
+
+
+if __name__ == "__main__":
+    print("Utility to help generate 'Reviewers' string for Pull Requests. Use Ctrl+D or Ctrl+C to exit")

Review Comment:
   Both Ctrl+C and Ctrl+D print the selected reviewers? If not, we should mention that.
   
   Either way, I think we should mention that they need to Ctrl+D to print the selected reviewers.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org