summaryrefslogtreecommitdiff
path: root/linaro_metrics
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2017-01-25 13:29:59 -0600
committerAndy Doan <andy.doan@linaro.org>2017-01-26 23:00:26 -0600
commit3e34a14e8d38fdec7fdc96a61c5aa9d5874a40ed (patch)
tree840c565c9e3e90bbe4436b9811989075b91013bc /linaro_metrics
parent6ca3536b8e0c01258614ada5d2872325e7aa5515 (diff)
linaro-metrics: add logic to find author of PR
Github accounts have no mapping into Linaro's Crowd user database. However, by looking at the email address of the commit in Git, we can see if its a linked account. Change-Id: I9fa151c515cd5ad8bd06bb024aa04d5fad6f473d
Diffstat (limited to 'linaro_metrics')
-rwxr-xr-xlinaro_metrics/sync_github_changes.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/linaro_metrics/sync_github_changes.py b/linaro_metrics/sync_github_changes.py
index 528f04f..54661ef 100755
--- a/linaro_metrics/sync_github_changes.py
+++ b/linaro_metrics/sync_github_changes.py
@@ -17,6 +17,9 @@ django_setup() # must be called to get sys.path and django settings in place
from django.conf import settings
+from linaro_metrics.crowd import Crowd
+from linaro_metrics.parsemail import get_linaro_person
+
log = logging.getLogger('sync_github_changes')
GITHUB_REPOS = [
@@ -61,6 +64,16 @@ def get_pull_requests(owner, repo, last_update=None):
url = m.group(1)
+def get_author(crowd, pr):
+ resp = _get(pr['commits_url'])
+ data = json.loads(resp.read())
+ if not len(data):
+ # some PR's have no commits: https://github.com/docker/docker/pull/5894
+ return
+ email = data[0]['commit']['author']['email']
+ return get_linaro_person(crowd, email)
+
+
@contextlib.contextmanager
def repo_cache():
def dt_serialize(obj):
@@ -83,7 +96,9 @@ def repo_cache():
def main(args):
- with repo_cache() as repos:
+ crwd = Crowd(settings.CROWD_USER, settings.CROWD_PASS, settings.CROWD_URL)
+
+ with crwd.cached(settings.CROWD_CACHE), repo_cache() as repos:
for owner, repo, proj in GITHUB_REPOS:
repo_path = '%s/%s' % (owner, repo)
log.info('Looking at: %s', repo_path)
@@ -93,7 +108,10 @@ def main(args):
try:
for pr in get_pull_requests(owner, repo, last_update):
x += 1
- log.debug('TODO analyze pr: %r', pr)
+ auth = get_author(crwd, pr)
+ if auth:
+ log.debug('checking change: %d', pr['number'])
+ # TODO check the PR
repos[repo_path] = now
finally:
log.info('analayzed %d pull-requests', x)