From 3ce9ece42fbd1248369c4bb5ba5d40cda60826fc Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 29 Jun 2015 13:30:59 +0300 Subject: [PATCH] Added Github Connection for fetching repo data --- SE_API/GitHub_API_Connector.py | 31 +++++++++++++++++++++++++++++++ SE_API/ProjectRoutes.py | 8 ++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 SE_API/GitHub_API_Connector.py diff --git a/SE_API/GitHub_API_Connector.py b/SE_API/GitHub_API_Connector.py new file mode 100644 index 0000000..78fbf85 --- /dev/null +++ b/SE_API/GitHub_API_Connector.py @@ -0,0 +1,31 @@ +__author__ = 'sagi' +import requests + + +def get_repo_general_info(repo_url): + url = 'https://api.github.com/repos/' + repo_url + req = requests.get(url) + return req.json() + + +def get_repo_stats(repo_url): + url = 'https://api.github.com/repos/' + repo_url + '/stats/contributors' + req = requests.get(url) + return req.json() + + +def get_repo_issues(repo_url): + url = 'https://api.github.com/repos/' + repo_url + '/issues' + req = requests.get(url) + return req.json() + + +def get_github_data(repo_url): + project_info = {'stats': None, 'issues': None, 'info': None} + + project_info['stats'] = get_repo_stats(repo_url) #first Call + project_info['info'] = get_repo_general_info(repo_url) + project_info['issues'] = get_repo_issues(repo_url) + project_info['stats'] = get_repo_stats(repo_url) #Second Call + + return project_info \ No newline at end of file diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 80a7839..7ef012a 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -21,6 +21,8 @@ from models.Project import Project from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * +from GitHub_API_Connector import get_github_data + project_routes = Blueprint("project_routes", __name__) auto = Autodoc() @@ -161,7 +163,7 @@ def getProjectsByCourse(courseId): 'courseId': 123456789,
'grade': 98,
'logo_url': 'http://location.domain.com/image.jpg',
- 'gitRepository': 'http://location.git.com/somthing',
+ 'gitRepository': 'repoOwner/repoName',
'membersId': ['bob', 'dylan', 'quentin', 'terentino'],
'id' : 1234567890
} @@ -174,7 +176,9 @@ def getProjectsByCourse(courseId): query.filter("courseId = ", int(courseId)) for p in query.run(): - arr.append(dict(json.loads(p.to_JSON()))) + proj = dict(json.loads(p.to_JSON())) + proj['info'] = get_github_data(p.gitRepository) + arr.append(proj) print arr if len(arr) != 0: return Response(response=json.dumps(arr),