summaryrefslogtreecommitdiff
path: root/linaro_metrics/sync_github_changes.py
diff options
context:
space:
mode:
Diffstat (limited to 'linaro_metrics/sync_github_changes.py')
-rwxr-xr-xlinaro_metrics/sync_github_changes.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/linaro_metrics/sync_github_changes.py b/linaro_metrics/sync_github_changes.py
index 3298220..96b2aac 100755
--- a/linaro_metrics/sync_github_changes.py
+++ b/linaro_metrics/sync_github_changes.py
@@ -22,6 +22,7 @@ from patchwork.models import Patch, Project, State
from linaro_metrics.crowd import Crowd
from linaro_metrics.models import TeamCredit
from linaro_metrics.parsemail import get_linaro_person
+from linaro_metrics import team_project_credit
log = logging.getLogger('sync_github_changes')
@@ -49,6 +50,12 @@ GITHUB_REPOS = [
]
+class Commit(object):
+ def __init__(self, sha, message):
+ self.id = sha
+ self.message = message
+
+
def _get(url):
headers = {'Authorization': 'token %s' % settings.GITHUB_OAUTH_TOKEN}
request = urllib2.Request(url, headers=headers)
@@ -85,13 +92,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):
+def get_commits(pull_request):
+ resp = _get(pull_request['commits_url'])
+ return json.loads(resp.read())
+
+
+def get_author(crowd, commits):
+ if not len(commits):
# some PR's have no commits: https://github.com/docker/docker/pull/5894
return
- email = data[0]['commit']['author']['email']
+ email = commits[0]['commit']['author']['email']
return get_linaro_person(crowd, email)
@@ -157,6 +167,13 @@ def repo_cache():
json.dump(data, f, default=dt_serialize)
+def create_tags(crowd, project, commits):
+ for commit in commits:
+ c = Commit(commit['sha'], commit['commit']['message'])
+ team_project_credit.update_commit_callback(
+ crowd, project, None, c, False)
+
+
def main(args):
crwd = Crowd(settings.CROWD_USER, settings.CROWD_PASS, settings.CROWD_URL)
@@ -170,10 +187,13 @@ def main(args):
try:
for pr in get_pull_requests(owner, repo, last_update):
x += 1
- auth = get_author(crwd, pr)
+ commits = get_commits(pr)
+ auth = get_author(crwd, commits)
if auth:
log.debug('checking change: %d', pr['number'])
create_or_update(proj, owner, repo, auth, pr)
+ project = Project.objects.get(name=proj)
+ create_tags(crwd, project, commits)
repos[repo_path] = now
finally:
log.info('analayzed %d pull-requests', x)