From fde0ebe4ea025cc61cc10dd9dc76eb9ec4fe68f0 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 15:11:06 +0530 Subject: [PATCH 01/10] refactor issue_duration metric implementation Signed-off-by: Parth Sharma --- augur/datasources/augur_db/augur_db.py | 120 ++++++++++++++----------- 1 file changed, 68 insertions(+), 52 deletions(-) diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index 9537c8c12f..2c4c5ef012 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -138,11 +138,11 @@ def pull_requests_merge_contributor_new(self, repo_group_id, repo_id=None, perio if repo_id: commitNewContributor = s.sql.text(""" - SELECT date_trunc(:period, new_date::DATE) as commit_date, + SELECT date_trunc(:period, new_date::DATE) as commit_date, COUNT(cmt_author_email) FROM ( SELECT cmt_author_email, MIN(TO_TIMESTAMP(cmt_author_date,'YYYY-MM-DD')) AS new_date FROM commits WHERE - repo_id = :repo_id + repo_id = :repo_id AND TO_TIMESTAMP(cmt_author_date,'YYYY-MM-DD') BETWEEN :begin_date AND :end_date AND cmt_author_email IS NOT NULL GROUP BY cmt_author_email ) as abc GROUP BY commit_date @@ -152,11 +152,11 @@ def pull_requests_merge_contributor_new(self, repo_group_id, repo_id=None, perio 'end_date': end_date}) else: commitNewContributor = s.sql.text(""" - SELECT date_trunc(:period, new_date::DATE) as commit_date, + SELECT date_trunc(:period, new_date::DATE) as commit_date, COUNT(cmt_author_email) FROM ( SELECT cmt_author_email, MIN(TO_TIMESTAMP(cmt_author_date,'YYYY-MM-DD')) AS new_date FROM commits WHERE - repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) AND TO_TIMESTAMP(cmt_author_date,'YYYY-MM-DD') BETWEEN :begin_date AND :end_date AND cmt_author_email IS NOT NULL GROUP BY cmt_author_email ) as abc GROUP BY commit_date @@ -218,7 +218,7 @@ def issues_first_time_opened(self, repo_group_id, repo_id=None, period='day', be FROM issues WHERE - repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) AND created_at BETWEEN :begin_date AND :end_date GROUP BY gh_user_id ) as abc @@ -256,8 +256,8 @@ def issues_first_time_closed(self, repo_group_id, repo_id=None, period='day', be SELECT cntrb_id, MIN(created_at) AS new_date FROM issue_events WHERE - issue_id IN - (SELECT issue_id FROM issues + issue_id IN + (SELECT issue_id FROM issues WHERE repo_id = :repo_id) AND action = 'closed' GROUP BY cntrb_id ) AS iss_close @@ -273,12 +273,12 @@ def issues_first_time_closed(self, repo_group_id, repo_id=None, period='day', be SELECT cntrb_id, MIN(created_at) AS new_date FROM issue_events WHERE - issue_id IN - (SELECT issue_id FROM issues + issue_id IN + (SELECT issue_id FROM issues WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id)) AND action = 'closed' GROUP BY cntrb_id ) AS iss_close - GROUP BY issue_date + GROUP BY issue_date """) results = pd.read_sql(issuesClosedSQL, self.db, params={'repo_group_id': repo_group_id, 'period': period, 'begin_date': begin_date, 'end_date': end_date}) @@ -355,31 +355,31 @@ def contributors(self, repo_group_id, repo_id=None, period='day', begin_date=Non if repo_id: contributorsSQL = s.sql.text(""" - SELECT id AS user, SUM(commits) AS commits, SUM(issues) AS issues, SUM(commit_comments) AS commit_comments, - SUM(issue_comments) AS issue_comments, SUM(pull_requests) AS pull_requests, + SELECT id AS user, SUM(commits) AS commits, SUM(issues) AS issues, SUM(commit_comments) AS commit_comments, + SUM(issue_comments) AS issue_comments, SUM(pull_requests) AS pull_requests, SUM(pull_request_comments) AS pull_request_comments, SUM(a.commits + a.issues + a.commit_comments + a.issue_comments + a.pull_requests + a.pull_request_comments) AS total FROM ( (SELECT gh_user_id AS id, 0 AS commits, COUNT(*) AS issues, 0 AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments FROM issues - WHERE repo_id = :repo_id - AND created_at BETWEEN :begin_date AND :end_date AND gh_user_id IS NOT NULL + WHERE repo_id = :repo_id + AND created_at BETWEEN :begin_date AND :end_date AND gh_user_id IS NOT NULL GROUP BY gh_user_id) - UNION ALL + UNION ALL (SELECT cmt_ght_author_id AS id, COUNT(*) AS commits, 0 AS issues, 0 AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments FROM commits - WHERE repo_id = :repo_id + WHERE repo_id = :repo_id AND cmt_ght_author_id IS NOT NULL AND cmt_committer_date BETWEEN :begin_date AND :end_date GROUP BY cmt_ght_author_id) UNION ALL - (SELECT user_id AS id, 0 AS commits, 0 AS issues, COUNT(*) AS commit_comments, + (SELECT user_id AS id, 0 AS commits, 0 AS issues, COUNT(*) AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments - FROM commit_comment_ref - WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id = :repo_id ) + FROM commit_comment_ref + WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id = :repo_id ) AND created_at BETWEEN :begin_date AND :end_date AND user_id IS NOT NULL - GROUP BY user_id) + GROUP BY user_id) ) a GROUP BY a.id ORDER BY total DESC """) @@ -387,31 +387,31 @@ def contributors(self, repo_group_id, repo_id=None, period='day', begin_date=Non 'begin_date': begin_date, 'end_date': end_date}) else: contributorsSQL = s.sql.text(""" - SELECT id AS user, SUM(commits) AS commits, SUM(issues) AS issues, SUM(commit_comments) AS commit_comments, - SUM(issue_comments) AS issue_comments, SUM(pull_requests) AS pull_requests, + SELECT id AS user, SUM(commits) AS commits, SUM(issues) AS issues, SUM(commit_comments) AS commit_comments, + SUM(issue_comments) AS issue_comments, SUM(pull_requests) AS pull_requests, SUM(pull_request_comments) AS pull_request_comments, SUM(a.commits + a.issues + a.commit_comments + a.issue_comments + a.pull_requests + a.pull_request_comments) AS total FROM ( (SELECT gh_user_id AS id, 0 AS commits, COUNT(*) AS issues, 0 AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments FROM issues - WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) - AND created_at BETWEEN :begin_date AND :end_date AND gh_user_id IS NOT NULL + WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + AND created_at BETWEEN :begin_date AND :end_date AND gh_user_id IS NOT NULL GROUP BY gh_user_id) - UNION ALL + UNION ALL (SELECT cmt_ght_author_id AS id, COUNT(*) AS commits, 0 AS issues, 0 AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments FROM commits - WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) AND cmt_ght_author_id IS NOT NULL AND cmt_committer_date BETWEEN :begin_date AND :end_date GROUP BY cmt_ght_author_id) UNION ALL - (SELECT user_id AS id, 0 AS commits, 0 AS issues, COUNT(*) AS commit_comments, + (SELECT user_id AS id, 0 AS commits, 0 AS issues, COUNT(*) AS commit_comments, 0 AS issue_comments, 0 AS pull_requests, 0 AS pull_request_comments - FROM commit_comment_ref - WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id)) + FROM commit_comment_ref + WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id)) AND created_at BETWEEN :begin_date AND :end_date AND user_id IS NOT NULL - GROUP BY user_id) + GROUP BY user_id) ) a GROUP BY a.id ORDER BY total DESC """) @@ -480,19 +480,19 @@ def contributors_new(self, repo_group_id, repo_id=None, period='day', begin_date FROM ( (SELECT gh_user_id AS id, MIN(created_at) AS created_at FROM issues - WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) AND created_at BETWEEN :begin_date AND :end_date AND gh_user_id IS NOT NULL GROUP BY gh_user_id) UNION ALL (SELECT cmt_ght_author_id AS id, MIN(TO_TIMESTAMP(cmt_author_date,'YYYY-MM-DD')) AS created_at FROM commits - WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) + WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id) AND cmt_ght_author_id IS NOT NULL AND TO_TIMESTAMP(cmt_author_date, 'YYYY-MM-DD') BETWEEN :begin_date AND :end_date GROUP BY cmt_ght_author_id) UNION ALL (SELECT user_id AS id, MIN(created_at) AS created_at FROM commit_comment_ref - WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id)) + WHERE cmt_id in (SELECT cmt_id FROM commits WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id=:repo_group_id)) AND created_at BETWEEN :begin_date AND :end_date AND user_id IS NOT NULL GROUP BY user_id) UNION ALL @@ -664,22 +664,38 @@ def issues_closed(self, repo_group_id, repo_id=None, period='day', begin_date=No return results @annotate(tag='issue-duration') - def issue_duration(self, repo_url): + def issue_duration(self, repo_group_id, repo_id=None): """Returns the duration of each issue. - :param repo_url: The repository's URL + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None :return: DataFrame of issue id with the corresponding duration """ - issue_duration_SQL = s.sql.text(""" - SELECT issue_id, (closed_at - created_at) AS duration - FROM issues - WHERE repo_id = (SELECT repo_id FROM repo WHERE repo_git LIKE :repourl LIMIT 1) - AND closed_at IS NOT NULL - ORDER BY issue_id; - """) + if not repo_id: + issue_duration_SQL = s.sql.text(""" + SELECT repo_id, issue_id, (closed_at - created_at) AS duration + FROM issues + WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id) + AND closed_at IS NOT NULL + ORDER BY repo_id, issue_id + """) - results = pd.read_sql(issue_duration_SQL, self.db, params={'repourl': f'%{repo_url}%'}) - return results + results = pd.read_sql(issue_duration_SQL, self.db, params={'repo_group_id': repo_group_id}) + results['duration'] = results['duration'].astype(str) + return results + + else: + issue_duration_SQL = s.sql.text(""" + SELECT issue_id, (closed_at - created_at) AS duration + FROM issues + WHERE repo_id = :repo_id + AND closed_at IS NOT NULL + ORDER BY issue_id; + """) + + results = pd.read_sql(issue_duration_SQL, self.db, params={'repo_id': repo_id}) + results['duration'] = results['duration'].astype(str) + return results @annotate(tag='issue-backlog') def issue_backlog(self, repo_group_id, repo_id=None): @@ -760,20 +776,20 @@ def downloaded_repos(self): repo.description, repo.repo_git AS url, repo.repo_status, - a.commits_all_time, + a.commits_all_time, b.issues_all_time , rg_name FROM repo - left outer join - (select repo_id, COUNT ( commits.cmt_id ) AS commits_all_time from commits group by repo_id ) a on + left outer join + (select repo_id, COUNT ( commits.cmt_id ) AS commits_all_time from commits group by repo_id ) a on repo.repo_id = a.repo_id - left outer join - (select repo_id, count ( issues.issue_id) as issues_all_time from issues group by repo_id) b - on - repo.repo_id = b.repo_id + left outer join + (select repo_id, count ( issues.issue_id) as issues_all_time from issues group by repo_id) b + on + repo.repo_id = b.repo_id JOIN repo_groups ON repo_groups.repo_group_id = repo.repo_group_id - order by commits_all_time desc + order by commits_all_time desc """) results = pd.read_sql(downloadedReposSQL, self.db) results['url'] = results['url'].apply(lambda datum: datum.split('//')[1]) From 1da1c525c6715cf7fc324b05a04dbf86dbaaaea2 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 15:32:55 +0530 Subject: [PATCH 02/10] add route for 'issue-duration' Signed-off-by: Parth Sharma --- augur/datasources/augur_db/routes.py | 49 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index ba0a917514..cb7444d3b3 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -23,7 +23,7 @@ def downloaded_repos(): return Response(response=drs, status=200, mimetype="application/json") - + server.updateMetricMetadata(function=augur_db.downloaded_repos, endpoint='/{}/repos'.format(server.api_version), metric_type='git') @@ -248,6 +248,51 @@ def downloaded_repos(): """ server.addRepoMetric(augur_db.issues_closed, 'issues-closed') + """ + @api {get} /repo-groups/:repo_group_id/issue-duration Issue Duration + @apiName issue-duration + @apiGroup Evolution + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21682, + "issue_id": 41786, + "duration": "0 days 00:56:26.000000000" + }, + { + "repo_id": 21682, + "issue_id": 41787, + "duration": "0 days 13:25:04.000000000" + } + ] + """ + server.addRepoGroupMetric(augur_db.issue_duration, 'issue-duration') + + """ + @api {get} /repo-groups/:repo_group_id/repos/:repo_id/issue-backlog Issue Duration + @apiName issue-duration + @apiGroup Evolution + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID. + @apiParma {String} repo_id Repository ID. + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21682, + "issue_id": 41792, + "duration": "2 days 19:13:23.000000000" + }, + { + "repo_id": 21682, + "issue_id": 41793, + "duration": "0 days 00:11:26.000000000" + } + ] + """ + server.addRepoMetric(augur_db.issue_duration, 'issue-duration') + """ @api {get} /repo-groups/:repo_group_id/issue-backlog Issue Backlog @apiName issue-backlog @@ -389,7 +434,7 @@ def downloaded_repos(): augur_db.issues_first_time_opened, 'issues-first-time-opened') """ - @api {get} /repo-groups/:repo_group_id/repos/:repo_id/issues-first-time-opened New Contributors of Issues(Repo) + @api {get} /repo-groups/:repo_group_id/repos/:repo_id/issues-first-time-opened New Contributors of Issues(Repo) @apiName New Contributors of Issues(Repo) @apiGroup Evolution @apiDescription CHAOSS Metric Definition From 8059b802a71b8818d47b94b86b00bcba1e54e82d Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 19:58:55 +0530 Subject: [PATCH 03/10] add issues_active metric implementation Signed-off-by: Parth Sharma --- augur/datasources/augur_db/augur_db.py | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index 2c4c5ef012..86e3e74e0a 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -612,6 +612,56 @@ def issues_new(self, repo_group_id, repo_id=None, period='day', begin_date=None, 'begin_date': begin_date, 'end_date': end_date}) return results + @annotate(tag='issues-active') + def issues_active(self, repo_group_id, repo_id=None, period='day', begin_date=None, end_date=None): + """Returns a timeseries of issues active. + + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None + :param period: To set the periodicity to 'day', 'week', 'month' or 'year', defaults to 'day' + :param begin_date: Specifies the begin date, defaults to '1970-1-1 00:00:00' + :param end_date: Specifies the end date, defaults to datetime.now() + :return: DataFrame of issues active/period + """ + if not begin_date: + begin_date = '1970-1-1 00:00:00' + if not end_date: + end_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + + if not repo_id: + issues_active_SQL = s.sql.text(""" + SELECT + date_trunc(:period, issue_events.created_at) as date, + repo_id, + COUNT(issues.issue_id) AS issues + FROM issues + JOIN issue_events ON issues.issue_id = issue_events.issue_id + WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id) + AND issue_events.created_at BETWEEN to_timestamp(:begin_date, 'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(:end_date, 'YYYY-MM-DD HH24:MI:SS') + GROUP BY date, repo_id + ORDER BY repo_id, date + """) + + results = pd.read_sql(issues_active_SQL, self.db, params={'repo_group_id': repo_group_id, 'period':period, + 'begin_date': begin_date, 'end_date':end_date}) + return results + + else: + issues_active_SQL = s.sql.text(""" + SELECT + date_trunc(:period, issue_events.created_at) as date, + COUNT(issues.issue_id) AS issues + FROM issues + JOIN issue_events ON issues.issue_id = issue_events.issue_id + WHERE repo_id = :repo_id + AND issue_events.created_at BETWEEN to_timestamp(:begin_date, 'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(:end_date, 'YYYY-MM-DD HH24:MI:SS') + GROUP BY date, repo_id + ORDER BY repo_id, date + """) + + results = pd.read_sql(issues_active_SQL, self.db, params={'repo_id': repo_id, 'period':period, + 'begin_date': begin_date, 'end_date':end_date}) + return results @annotate(tag='issues-closed') def issues_closed(self, repo_group_id, repo_id=None, period='day', begin_date=None, end_date=None): From 624e5c12f6eaa4b14be2055ed5ee9c5b9a83db5d Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 20:06:43 +0530 Subject: [PATCH 04/10] add routes for issues_active metric Signed-off-by: Parth Sharma --- augur/datasources/augur_db/routes.py | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index cb7444d3b3..d280e0771b 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -219,6 +219,55 @@ def downloaded_repos(): """ server.addRepoMetric(augur_db.issues_new, 'issues-new') + """ + @api {get} /repo-groups/:repo_group_id/issues-active Issues Active + @apiName issues-active + @apiGroup Evolution + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID + @apiParam {string} period Periodicity specification. Possible values: 'day', 'week', 'month', 'year'. Defaults to 'day' + @apiParam {string} begin_date Beginning date specification. Possible values: '2018', '2018-05', '2019-05-01', ..., ' 2017-03-02 05:34:19'. Defaults to '1970-1-1 0:0:0' + @apiParam {string} end_date Ending date specification. Possible values: '2018', '2018-05', '2019-05-01', ..., ' 2017-03-02 05:34:19'. Defaults to current date & time. + @apiSuccessExample {json} Success-Response: + [ + { + "date": "2019-05-01T00:00:00.000Z", + "repo_id": 21326, + "issues": 27 + }, + { + "date": "2019-05-01T00:00:00.000Z", + "repo_id": 21327, + "issues": 54 + } + ] + """ + server.addRepoGroupMetric(augur_db.issues_active, 'issues-active') + + """ + @api {get} /repo-groups/:repo_group_id/issues-active Issues Active + @apiName issues-active + @apiGroup Evolution + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID. + @apiParma {String} repo_id Repository ID. + @apiParam {string} period Periodicity specification. Possible values: 'day', 'week', 'month', 'year'. Defaults to 'day' + @apiParam {string} begin_date Beginning date specification. Possible values: '2018', '2018-05', '2019-05-01', ..., ' 2017-03-02 05:34:19'. Defaults to '1970-1-1 0:0:0' + @apiParam {string} end_date Ending date specification. Possible values: '2018', '2018-05', '2019-05-01', ..., ' 2017-03-02 05:34:19'. Defaults to current date & time. + @apiSuccessExample {json} Success-Response: + [ + { + "date": "2015-07-01T00:00:00.000Z", + "issues": 32 + }, + { + "date": "2015-08-01T00:00:00.000Z", + "issues": 62 + } + ] + """ + server.addRepoMetric(augur_db.issues_active, 'issues-active') + """ @api {get} /repo-groups/:repo_group_id/issues-closed Issues Closed @apiName issues-closed From c5a0ddd1819c8d96ef96185c5a1611c4da9eb573 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 20:30:53 +0530 Subject: [PATCH 05/10] add 'cii-best-practices-badge' metric Signed-off-by: Parth Sharma --- augur/datasources/augur_db/augur_db.py | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index 86e3e74e0a..a366710e41 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -778,6 +778,38 @@ def issue_backlog(self, repo_group_id, repo_id=None): result = pd.read_sql(issue_backlog_SQL, self.db, params={'repo_id': repo_id}) return result + ##################################### + ### RISK ### + ##################################### + + @annotate(tag='cii-best-practices-badge') + def cii_best_practices_badge(self, repo_group_id, repo_id=None): + """Returns the CII best practices badge level + + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None + :return: CII best parctices badge level + """ + if not repo_id: + cii_best_practices_badge_SQL = s.sql.text(""" + SELECT repo_id, badge_level + FROM repo_badging + WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id) + """) + + results = pd.read_sql(cii_best_practices_badge_SQL, self.db, params={'repo_group_id': repo_group_id}) + return results + + else: + cii_best_practices_badge_SQL = s.sql.text(""" + SELECT badge_level + FROM repo_badging + WHERE repo_id = :repo_id + """) + + results = pd.read_sql(cii_best_practices_badge_SQL, self.db, params={'repo_id': repo_id}) + return results + ##################################### ### EXPERIMENTAL ### ##################################### From f8be96ccf48ead9749d5830e31c3d778022af297 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 20:38:46 +0530 Subject: [PATCH 06/10] add route for 'cii-best-practices-badge' Signed-off-by: Parth Sharma --- augur/datasources/augur_db/routes.py | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index d280e0771b..45b3cf7283 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -712,3 +712,43 @@ def downloaded_repos(): """ server.addRepoMetric( augur_db.contributors_new, 'contributors-new') + + ##################################### + ### RISK ### + ##################################### + + """ + @api {get} /repo-groups/:repo_group_id/cii-best-practices-badge CII Best Practices Badge + @apiName cii-best-practices-badge + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21277, + "badge_level": "passing" + }, + { + "repo_id": 21252, + "badge_level": "in_progress" + } + ] + """ + server.addRepoGroupMetric(augur_db.cii_best_practices_badge, 'cii-best-practices-badge') + + """ + @api {get} /repo-groups/:repo_group_id/cii-best-practices-badge CII Best Practices Badge + @apiName cii-best-practices-badge + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID. + @apiParma {String} repo_id Repository ID. + @apiSuccessExample {json} Success-Response: + [ + { + "badge_level": "gold" + } + ] + """ + server.addRepoMetric(augur_db.cii_best_practices_badge, 'cii-best-practices-badge') \ No newline at end of file From a6c189250f23ccf971281bb8fda3dca23210f98e Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 20:46:26 +0530 Subject: [PATCH 07/10] add 'languages' metric implementation Signed-off-by: Parth Sharma --- augur/datasources/augur_db/augur_db.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index a366710e41..466a65a4e9 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -810,6 +810,34 @@ def cii_best_practices_badge(self, repo_group_id, repo_id=None): results = pd.read_sql(cii_best_practices_badge_SQL, self.db, params={'repo_id': repo_id}) return results + @annotate(tag='languages') + def languages(self, repo_group_id, repo_id=None): + """Returns the implementation languages + + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None + :return: Implementation languages + """ + if not repo_id: + languages_SQL = s.sql.text(""" + SELECT repo_id, primary_language + FROM repo + WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id) + """) + + results = pd.read_sql(languages_SQL, self.db, params={'repo_group_id': repo_group_id}) + return results + + else: + languages_SQL = s.sql.text(""" + SELECT primary_language + FROM repo + WHERE repo_id = :repo_id + """) + + results = pd.read_sql(languages_SQL, self.db, params={'repo_id': repo_id}) + return results + ##################################### ### EXPERIMENTAL ### ##################################### From e3589473f576d3e5451a8ec9cd54189dd1d289f7 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Wed, 19 Jun 2019 20:59:30 +0530 Subject: [PATCH 08/10] add routes for 'languages' Signed-off-by: Parth Sharma --- augur/datasources/augur_db/routes.py | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index 45b3cf7283..f928be7d8b 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -751,4 +751,40 @@ def downloaded_repos(): } ] """ - server.addRepoMetric(augur_db.cii_best_practices_badge, 'cii-best-practices-badge') \ No newline at end of file + server.addRepoMetric(augur_db.cii_best_practices_badge, 'cii-best-practices-badge') + + """ + @api {get} /repo-groups/:repo_group_id/languages Languages + @apiName languages + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21277, + "primary_language": "Go" + }, + { + "repo_id": 21252, + "primary_language": "PHP" + } + ] + """ + server.addRepoGroupMetric(augur_db.languages, 'languages') + + """ + @api {get} /repo-groups/:repo_group_id/languages Languages + @apiName languages + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID. + @apiParma {String} repo_id Repository ID. + @apiSuccessExample {json} Success-Response: + [ + { + "primary_language":"PHP" + } + ] + """ + server.addRepoMetric(augur_db.languages, 'languages') From 6e4b92e01d47cb2fca87f8aea0a3c560b66d7d38 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Thu, 20 Jun 2019 17:55:08 +0530 Subject: [PATCH 09/10] add 'license_declared' metric implementation Signed-off-by: Parth Sharma --- augur/datasources/augur_db/augur_db.py | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/augur/datasources/augur_db/augur_db.py b/augur/datasources/augur_db/augur_db.py index 466a65a4e9..7dfcbf776f 100644 --- a/augur/datasources/augur_db/augur_db.py +++ b/augur/datasources/augur_db/augur_db.py @@ -838,6 +838,34 @@ def languages(self, repo_group_id, repo_id=None): results = pd.read_sql(languages_SQL, self.db, params={'repo_id': repo_id}) return results + @annotate(tag='license-declared') + def license_declared(self, repo_group_id, repo_id=None): + """Returns the declared license + + :param repo_group_id: The repository's repo_group_id + :param repo_id: The repository's repo_id, defaults to None + :return: Declared License + """ + if not repo_id: + license_declared_SQL = s.sql.text(""" + SELECT repo_id, license + FROM repo_badging + WHERE repo_id IN (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id); + """) + + results = pd.read_sql(license_declared_SQL, self.db, params={'repo_group_id': repo_group_id}) + return results + + else: + license_declared_SQL = s.sql.text(""" + SELECT license + FROM repo_badging + WHERE repo_id = :repo_id; + """) + + results = pd.read_sql(license_declared_SQL, self.db, params={'repo_id': repo_id}) + return results + ##################################### ### EXPERIMENTAL ### ##################################### From 1115e25591a67bdbb77cd4f61108ac0ef6250709 Mon Sep 17 00:00:00 2001 From: Parth Sharma Date: Thu, 20 Jun 2019 18:01:12 +0530 Subject: [PATCH 10/10] add routes for 'license_declared' Signed-off-by: Parth Sharma --- augur/datasources/augur_db/routes.py | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/augur/datasources/augur_db/routes.py b/augur/datasources/augur_db/routes.py index f928be7d8b..550e5485ce 100644 --- a/augur/datasources/augur_db/routes.py +++ b/augur/datasources/augur_db/routes.py @@ -788,3 +788,39 @@ def downloaded_repos(): ] """ server.addRepoMetric(augur_db.languages, 'languages') + + """ + @api {get} /repo-groups/:repo_group_id/license-declared License Declared + @apiName license-declared + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID + @apiSuccessExample {json} Success-Response: + [ + { + "repo_id": 21277, + "license": "Apache-2.0" + }, + { + "repo_id": 21252, + "license": "Apache-2.0" + } + ] + """ + server.addRepoGroupMetric(augur_db.license_declared, 'license-declared') + + """ + @api {get} /repo-groups/:repo_group_id/license-declared License Declared + @apiName license-declared + @apiGroup Risk + @apiDescription CHAOSS Metric Definition + @apiParam {String} repo_group_id Repository Group ID. + @apiParma {String} repo_id Repository ID. + @apiSuccessExample {json} Success-Response: + [ + { + "license": "Apache-2.0" + } + ] + """ + server.addRepoMetric(augur_db.license_declared, 'license-declared')