<pre style='margin:0'>
Rainer Müller (raimue) pushed a commit to branch master
in repository trac.macports.org.

</pre>
<p><a href="https://github.com/macports/trac.macports.org/commit/ace841927035be6809da1036e99bcc4cafab003e">https://github.com/macports/trac.macports.org/commit/ace841927035be6809da1036e99bcc4cafab003e</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit ace841927035be6809da1036e99bcc4cafab003e
</span>Author: Rainer Müller <raimue@macports.org>
AuthorDate: Wed Nov 9 00:52:51 2016 +0100

<span style='display:block; white-space:pre;color:#404040;'>    trac-github-update: reduce GitHub queries
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Only ask GitHub if we do not already know the information.
</span>---
 plugins/hooks/trac-github-update.py | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/plugins/hooks/trac-github-update.py b/plugins/hooks/trac-github-update.py
</span><span style='display:block; white-space:pre;color:#808080;'>index 00f8bd8..d1fec81 100755
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/plugins/hooks/trac-github-update.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/plugins/hooks/trac-github-update.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -90,15 +90,19 @@ class GitHubAPI(object):
</span>         self.github = Github(githubtoken)
         self.cache = {}
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    def get_user(self, username):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    def get_user(self, username, knownname=None, knownemail=None):
</span>         if username in self.cache:
             return self.cache[username]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        name = self.github.get_user(username).name
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        name = knownname
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if not name:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            name = self.github.get_user(username).name
</span>         # GitHub only lists the primary email address in the payload. We do not
         # want to expose it to the public. The profile may not have any public
         # address. Use a static sender email instead.
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        email = "%s@users.noreply.github.com" % (username,)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        if name:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        email = knownemail
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if not email:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            email = "%s@users.noreply.github.com" % (username,)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if name and email:
</span>             self.cache[username] = (name, email)
             return self.cache[username]
         return (None, None)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -136,7 +140,7 @@ class GitHubWebhookEnvironment(GenericEnvironment):
</span>                 result = username
         return result
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    def _get_username_email(self, username):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    def _get_username_email(self, username, knownname=None, knownemail=None):
</span>         result = None
         # Get name and email from Trac DB
         name, email = self._tracdb.get_user(username)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -144,7 +148,7 @@ class GitHubWebhookEnvironment(GenericEnvironment):
</span>             result = "%s <%s>" % (name, email)
         # If user was not in Trac DB, ask GitHub API
         if not result:
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            name, email = self._github.get_user(username)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            name, email = self._github.get_user(username, knownname, knownemail)
</span>             if name:
                 result = "%s <%s>" % (name, email)
             else:
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -160,7 +164,15 @@ class GitHubWebhookEnvironment(GenericEnvironment):
</span>                 commit = self._commits[change.rev.sha1]
                 if 'username' in commit['author']:
                     username = commit['author']['username']
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    author = self._get_username_email(username)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    if 'name' in commit['author']:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        knownname = commit['author']['name']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        knownname = None
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    if 'email' in commit['author']:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        knownemail = commit['author']['email']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        knownemail = None
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    author = self._get_username_email(username, knownname, knownemail)
</span>                 if not author:
                     author = "%s <%s>" % (commit['author']['name'], commit['author']['email'])
                 return author.encode('utf-8')
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -201,7 +213,15 @@ class GitHubWebhookEnvironment(GenericEnvironment):
</span>         if 'username' in author and 'username' in committer:
             if author['username'] != committer['username']:
                 username = commit['committer']['username']
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                reply_to_committer = self._get_username_email(username)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                if 'name' in commit['committer']:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    knownname = commit['committer']['name']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    knownname = None
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                if 'email' in commit['committer']:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    knownemail = commit['committer']['email']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    knownemail = None
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                reply_to_committer = self._get_username_email(username, knownname, knownemail)
</span>         else:
             if author['email'] != committer['email']:
                 name = commit['committer']['name']
</pre><pre style='margin:0'>

</pre>