From 0778941850024ecce37c5d0dbce0e4f939f8be37 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sat, 1 Aug 2015 17:34:53 +0300 Subject: [PATCH 1/2] Project Info Cron Job - Fixing Bad data requests --- SE_API/GitHub_API_Connector.py | 53 ++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/SE_API/GitHub_API_Connector.py b/SE_API/GitHub_API_Connector.py index 052f3fd..ae68412 100644 --- a/SE_API/GitHub_API_Connector.py +++ b/SE_API/GitHub_API_Connector.py @@ -10,23 +10,31 @@ githubKeys = GitHubAPI_Keys() def get_repo_general_info(repo_url): url = 'https://api.github.com/repos/' + repo_url + '?client_id='+githubKeys.getId()+'&client_secret=' + githubKeys.getSecret() req = requests.get(url) + if req.status_code == 202: + return None return req.json() def get_repo_stats(repo_url): url = 'https://api.github.com/repos/' + repo_url + '/stats/contributors' + '?client_id='+githubKeys.getId()+'&client_secret=' + githubKeys.getSecret() req = requests.get(url) + if req.status_code == 202: + return None return req.json() def get_repo_issues(repo_url): url = 'https://api.github.com/repos/' + repo_url + '/issues' + '?client_id=' + githubKeys.getId() + '&client_secret=' + githubKeys.getSecret() req = requests.get(url) + if req.status_code == 202: + return None return req.json() def get_repo_weekly_commits(repo_url): url = 'https://api.github.com/repos/' + repo_url + '/stats/participation' + '?client_id=' + githubKeys.getId() + '&client_secret=' + githubKeys.getSecret() req = requests.get(url) + if req.status_code == 202: + return None week_obj = {} week_obj['data'] = [] try: @@ -50,6 +58,8 @@ def get_repo_weekly_commits(repo_url): def get_repo_commits(repo_url): url = 'https://api.github.com/repos/' + repo_url + '/commits' + '?client_id=' + githubKeys.getId() + '&client_secret=' + githubKeys.getSecret() req = requests.get(url) + if req.status_code == 202: + return None return req.json() def make_macro(stats, info, project_id): @@ -84,11 +94,44 @@ def get_issue_num(issues, user): def get_github_data(repo_url, project_id): project_info = {'stats': {}} - github_stats = get_repo_stats(repo_url) #first Call - project_info['info'] = get_repo_general_info(repo_url) - issues = get_repo_issues(repo_url) - weekly_commits = get_repo_weekly_commits(repo_url) - github_stats = get_repo_stats(repo_url) #Second Call + info_stats = {'stats': False, 'info': False, 'issues': False, 'commits': False} + all_good = False + # github_stats = get_repo_stats(repo_url) #first Call + # if github_stats is not None: + # info_stats['stats'] = True + # project_info['info'] = get_repo_general_info(repo_url) + # if project_info['info'] is not None: + # info_stats['info'] = True + # issues = get_repo_issues(repo_url) + # if issues is not None: + # info_stats['issues'] = True + # weekly_commits = get_repo_weekly_commits(repo_url) + # if issues is not None: + # info_stats['commits'] = True + + while not all_good: + if not info_stats['stats']: + github_stats = get_repo_stats(repo_url) + if github_stats is not None: + info_stats['stats'] = True + if not info_stats['info']: + project_info['info'] = get_repo_general_info(repo_url) + if project_info['info'] is not None: + info_stats['info'] = True + if not info_stats['issues']: + issues = get_repo_issues(repo_url) + if issues is not None: + info_stats['issues'] = True + if not info_stats['commits']: + weekly_commits = get_repo_weekly_commits(repo_url) + if issues is not None: + info_stats['commits'] = True + all_good = True + for stat in info_stats: + if not info_stats[stat]: + all_good = False + + github_stats = get_repo_stats(repo_url) #Second Call project_info['stats']['macro'] = make_macro(github_stats, project_info['info'], project_id) project_info['stats']['micro'] = make_micro(github_stats, issues) project_info['stats']['weekly_commits'] = weekly_commits From 3a97a0474e44e558564317eb5e8e18189fe3b916 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sat, 1 Aug 2015 17:49:01 +0300 Subject: [PATCH 2/2] Fixed Syntax error in Project.html --- templates/views/project.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/views/project.html b/templates/views/project.html index b880935..b41b3ee 100644 --- a/templates/views/project.html +++ b/templates/views/project.html @@ -1,10 +1,10 @@
-
+

{{project.projectName}}

-
-
+
+