Added Github Connection for fetching repo data

This commit is contained in:
Sagi Dayan 2015-06-29 13:30:59 +03:00
parent ffa767fccd
commit 3ce9ece42f
2 changed files with 37 additions and 2 deletions

View file

@ -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

View file

@ -21,6 +21,8 @@ from models.Project import Project
from SE_API.Validation_Utils import * from SE_API.Validation_Utils import *
from SE_API.Respones_Utils import * from SE_API.Respones_Utils import *
from GitHub_API_Connector import get_github_data
project_routes = Blueprint("project_routes", __name__) project_routes = Blueprint("project_routes", __name__)
auto = Autodoc() auto = Autodoc()
@ -161,7 +163,7 @@ def getProjectsByCourse(courseId):
'courseId': 123456789,<br> 'courseId': 123456789,<br>
'grade': 98,<br> 'grade': 98,<br>
'logo_url': 'http://location.domain.com/image.jpg',<br> 'logo_url': 'http://location.domain.com/image.jpg',<br>
'gitRepository': 'http://location.git.com/somthing',<br> 'gitRepository': 'repoOwner/repoName',<br>
'membersId': ['bob', 'dylan', 'quentin', 'terentino'],<br> 'membersId': ['bob', 'dylan', 'quentin', 'terentino'],<br>
'id' : 1234567890<br> 'id' : 1234567890<br>
} }
@ -174,7 +176,9 @@ def getProjectsByCourse(courseId):
query.filter("courseId = ", int(courseId)) query.filter("courseId = ", int(courseId))
for p in query.run(): 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 print arr
if len(arr) != 0: if len(arr) != 0:
return Response(response=json.dumps(arr), return Response(response=json.dumps(arr),