diff --git a/augur/routes/contributor_reports.py b/augur/routes/contributor_reports.py index e0f8949c9c..b201bb767a 100644 --- a/augur/routes/contributor_reports.py +++ b/augur/routes/contributor_reports.py @@ -356,11 +356,14 @@ def get_repo_id_start_date_and_end_date(): now = datetime.datetime.now() - repo_id = int(request.args.get('repo_id')) + repo_id = request.args.get('repo_id') start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) - return repo_id, start_date, end_date + if repo_id: + return int(repo_id), start_date, end_date + + return None, None, None def filter_out_repeats_without_required_contributions_in_required_time(repeat_list, repeats_df, required_time, first_list): @@ -572,6 +575,12 @@ def new_contributors_bar(): repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + group_by, required_contributions, required_time = get_new_cntrb_bar_chart_query_params() input_df = new_contributor_data_collection(repo_id=repo_id, required_contributions=required_contributions) @@ -737,6 +746,12 @@ def new_contributors_stacked_bar(): repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + group_by, required_contributions, required_time = get_new_cntrb_bar_chart_query_params() input_df = new_contributor_data_collection(repo_id=repo_id, required_contributions=required_contributions) @@ -931,10 +946,16 @@ def new_contributors_stacked_bar(): @server.app.route('/{}/contributor_reports/returning_contributors_pie_chart/'.format(server.api_version), methods=["GET"]) - def returning_contributor_pie_chart(): + def returning_contributors_pie_chart(): repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + required_contributions = int(request.args.get('required_contributions', 4)) required_time = int(request.args.get('required_time', 365)) @@ -1058,10 +1079,16 @@ def returning_contributor_pie_chart(): @server.app.route('/{}/contributor_reports/returning_contributors_stacked_bar/'.format(server.api_version), methods=["GET"]) - def returning_contributor_stacked_bar(): + def returning_contributors_stacked_bar(): repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + group_by = str(request.args.get('group_by', "quarter")) required_contributions = int(request.args.get('required_contributions', 4)) required_time = int(request.args.get('required_time', 365)) diff --git a/augur/routes/pull_request_reports.py b/augur/routes/pull_request_reports.py index 7ffc8fc0b6..2e7b479020 100644 --- a/augur/routes/pull_request_reports.py +++ b/augur/routes/pull_request_reports.py @@ -421,14 +421,37 @@ def filter_data(df, needed_columns, not_null_columns=[]): print("Developer error, not null columns should be a subset of needed columns") return df - @server.app.route('/{}/pull_request_reports/average_commits_per_PR/'.format(server.api_version), methods=["GET"]) - def average_commits_per_PR(): + def get_repo_id_start_date_and_end_date(): + + """ Gets the repo_id, start_date, and end_date from the GET requests array + + :return: repo_id - id of the repo data is being retrieved for + :return: start_date - earliest time on visualization. Defaults to the January 1st of last year + :return: end_date - latest time on visualization. Defaults to current date + """ now = datetime.datetime.now() - repo_id = int(request.args.get('repo_id')) + repo_id = request.args.get('repo_id') start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) + + if repo_id: + return int(repo_id), start_date, end_date + + return None, None, None + + @server.app.route('/{}/pull_request_reports/average_commits_per_PR/'.format(server.api_version), methods=["GET"]) + def average_commits_per_PR(): + + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + group_by = str(request.args.get('group_by', "month")) return_json = request.args.get('return_json', "false") @@ -567,11 +590,14 @@ def average_commits_per_PR(): @server.app.route('/{}/pull_request_reports/average_comments_per_PR/'.format(server.api_version), methods=["GET"]) def average_comments_per_PR(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") df_type = get_df_tuple_locations() @@ -747,11 +773,14 @@ def average_comments_per_PR(): methods=["GET"]) def PR_counts_by_merged_status(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") x_axis = 'closed_year' @@ -937,11 +966,14 @@ def PR_counts_by_merged_status(): methods=["GET"]) def mean_response_times_for_PR(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") df_type = get_df_tuple_locations() @@ -1234,11 +1266,14 @@ def add_legend(location, orientation, side): methods=["GET"]) def mean_days_between_PR_comments(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") time_unit = 'Days' @@ -1399,11 +1434,14 @@ def mean_days_between_PR_comments(): @server.app.route('/{}/pull_request_reports/PR_time_to_first_response/'.format(server.api_version), methods=["GET"]) def PR_time_to_first_response(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") remove_outliers = str(request.args.get('remove_outliers', "true")) @@ -1533,11 +1571,14 @@ def PR_time_to_first_response(): methods=["GET"]) def average_PR_events_for_closed_PRs(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() + + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) return_json = request.args.get('return_json', "false") include_comments = str(request.args.get('include_comments', True)) @@ -1719,11 +1760,14 @@ def average_PR_events_for_closed_PRs(): @server.app.route('/{}/pull_request_reports/Average_PR_duration/'.format(server.api_version), methods=["GET"]) def Average_PR_duration(): - now = datetime.datetime.now() + repo_id, start_date, end_date = get_repo_id_start_date_and_end_date() - repo_id = int(request.args.get('repo_id')) - start_date = str(request.args.get('start_date', "{}-01-01".format(now.year - 1))) - end_date = str(request.args.get('end_date', "{}-{}-{}".format(now.year, now.month, now.day))) + if repo_id is None: + return Response(response="repo_id not specified. Use this endpoint to get a list of available repos: " + "http:///api/unstable/repos", + mimetype='application/json', + status=400) + group_by = str(request.args.get('group_by', "month")) return_json = request.args.get('return_json', "false") remove_outliers = str(request.args.get('remove_outliers', "true"))