[ 
https://issues.apache.org/jira/browse/BEAM-4790?focusedWorklogId=124161&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-124161
 ]

ASF GitHub Bot logged work on BEAM-4790:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jul/18 18:19
            Start Date: 17/Jul/18 18:19
    Worklog Time Spent: 10m 
      Work Description: udim closed pull request #5951: [BEAM-4790] Replace 
Github reviewer auto-assignment with suggest_reviewers.py script
URL: https://github.com/apache/beam/pull/5951
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/CODEOWNERS b/CODEOWNERS_
similarity index 94%
rename from CODEOWNERS
rename to CODEOWNERS_
index 3a125c5b4c4..f9efcf164c7 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS_
@@ -15,10 +15,10 @@
 # limitations under the License.
 #
 
-# This file is used for auto-assigning reviewers to PRs.
-#
-# The last matching rule wins. For details, see:
-# https://help.github.com/articles/about-codeowners/
+# This file is used for suggesting reviewers for PRs.
+# The last matching rule wins.
+# See https://help.github.com/articles/about-codeowners/ for path pattern
+# examples.
 
 # Per-language reviewers.
 *.go @herohde
@@ -26,9 +26,9 @@
 *.py @pabloem @robertwb @aaltay @charlesccychen
 
 # SDK components reviewers.
-/sdks/go/ @herohde
+/sdks/go @herohde
 
-/sdks/java/ @aaltay @kennknowles
+/sdks/java @aaltay @kennknowles
 /sdks/java/core @lukecwik
 #/sdks/java/extensions
 /sdks/java/extensions/google-cloud-platform-core @lukecwik @chamikaramj
@@ -71,7 +71,7 @@
 #/sdks/java/maven-archetypes
 /sdks/java/javadoc @melap
 
-/sdks/python/ @aaltay @charlesccychen
+/sdks/python @aaltay @charlesccychen
 /sdks/python/scripts @aaltay
 /sdks/python/container @herohde @aaltay @charlesccychen
 /sdks/python/apache_beam/runners @pabloem @charlesccychen
diff --git a/suggest_reviewers.py b/suggest_reviewers.py
new file mode 100755
index 00000000000..7272c84a573
--- /dev/null
+++ b/suggest_reviewers.py
@@ -0,0 +1,100 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from __future__ import print_function
+
+import argparse
+import collections
+import fnmatch
+import logging
+import requests
+import random
+import string
+
+CODEOWNERS_FILE = 'CODEOWNERS_'
+
+
+class Codeowners(object):
+
+  def __init__(self, codeowners_file):
+    self.path_owner_map = collections.OrderedDict()
+    for line in open(codeowners_file):
+      line = line.split('#', 1)[0].strip()
+      if not line:
+        continue
+      path, owners = line.split(' ', 1)
+      self.path_owner_map[path] = owners.split()
+
+  def _get_reviewers_for_path(self, path):
+    res = []
+    for path_pattern, owners in self.path_owner_map.iteritems():
+      if '*' not in path_pattern:
+        path_pattern += '*'
+        if not path_pattern.startswith('/'):
+          path_pattern = '*/' + path_pattern
+      if fnmatch.fnmatch(path, path_pattern):
+        res = (path_pattern, owners)
+    return res
+
+  def get_reviewers(self, paths, random_seed):
+    random.seed(random_seed)
+    reviewers = set()
+    for path in paths:
+      path_pattern, candidates = self._get_reviewers_for_path(path)
+      if not candidates:
+        logging.warning('No candidate reviewers for path: %s', path)
+        continue
+      selected_candidate = candidates[random.randint(0, len(candidates) - 1)]
+      logging.info('Selected reviewer %s for: %s (path_pattern: %s)',
+                   selected_candidate, path, path_pattern)
+      reviewers.add(selected_candidate)
+
+    return reviewers
+
+
+class PullRequest(object):
+
+  def __init__(self, number):
+    self.number = number
+    url = 'https://api.github.com/repos/apache/beam/pulls/%d/files' % number
+    self.files = []
+    for file_json in requests.get(url).json():
+      self.files.append('/' + file_json['filename'])
+
+
+def main():
+  logging.getLogger().setLevel(logging.INFO)
+  parser = argparse.ArgumentParser()
+  parser.add_argument(
+      '--pr',
+      type=int,
+      required=True,
+      help='Github pull request number to suggest reviewers for.')
+  args = parser.parse_args()
+
+  codeowners = Codeowners(CODEOWNERS_FILE)
+  pr = PullRequest(args.pr)
+  reviewers = codeowners.get_reviewers(pr.files, random_seed=pr.number)
+  if reviewers:
+    print('Suggested reviewers: %s' % ', '.join(reviewers))
+  else:
+    print('No suggested reviewers. :(')
+
+
+if __name__ == '__main__':
+  main()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 124161)
    Time Spent: 1h  (was: 50m)

> Make it easier to select coder reviewers for PRs
> ------------------------------------------------
>
>                 Key: BEAM-4790
>                 URL: https://issues.apache.org/jira/browse/BEAM-4790
>             Project: Beam
>          Issue Type: Improvement
>          Components: project-management
>            Reporter: Udi Meiri
>            Assignee: Udi Meiri
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> The original idea was to use Github's CODEOWNERS feature, but that turned out 
> to not work well for Apache Beam.
> Thread: 
> https://lists.apache.org/thread.html/9cc3191b21489c855ed502beade6d453b18e26eec46cb2c3dfe810e9@%3Cdev.beam.apache.org%3E
> Document discussing this idea:
> https://docs.google.com/document/d/184Tn0ONJ2ENHBVrhIes4seVuBSkww7xX5xb5W2VZwm8/edit#heading=h.l7mcrg761zp8
> Mailing list thread:
> https://lists.apache.org/thread.html/6138d08c551e254b5f13b26c6ba06579a49a4694f4d13ad6d164689a@%3Cdev.beam.apache.org%3E



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to