From 5f644305a698f0f056491bd6b43cdc0dbf3c7d3d Mon Sep 17 00:00:00 2001 From: "tidb-cloud-data-service[bot]" <134662589+tidb-cloud-data-service[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 06:49:17 +0000 Subject: [PATCH] feat: add monthly line of changes of PRs endpoint --- configs/public_api/http_endpoints/config.json | 48 ++++++++++++++++++- ...pull_requests-monthly-line_of_changes.sql} | 0 ...ET-users-pull_requests-monthly-actions.sql | 6 +-- ...-pull_requests-monthly-line_of_changes.sql | 20 ++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) rename configs/public_api/http_endpoints/sql/{GET-repos-pull_requests-monthly-loc.sql => GET-repos-pull_requests-monthly-line_of_changes.sql} (100%) create mode 100644 configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-line_of_changes.sql diff --git a/configs/public_api/http_endpoints/config.json b/configs/public_api/http_endpoints/config.json index a650f20e200..c376c2518a9 100644 --- a/configs/public_api/http_endpoints/config.json +++ b/configs/public_api/http_endpoints/config.json @@ -1,4 +1,48 @@ [ + { + "name": "/users/pull_requests/monthly/loc", + "description": "Retrieve a monthly summary of a GitHub user's opened and merged pull requests in the specified time range. (If `from` and `to` are not specified, the default period is the past year.)", + "method": "GET", + "endpoint": "/users/pull_requests/monthly/line_of_changes", + "data_source": { + "cluster_id": 1379661944642684098 + }, + "params": [ + { + "name": "username", + "type": "string", + "required": 1, + "default": "", + "description": "" + }, + { + "name": "from", + "type": "string", + "required": 0, + "default": "", + "description": "" + }, + { + "name": "to", + "type": "string", + "required": 0, + "default": "2099-12-31", + "description": "" + } + ], + "settings": { + "timeout": 30000, + "row_limit": 1000, + "cache_enabled": 0, + "cache_ttl": 0, + "enable_pagination": 0 + }, + "tag": "Default", + "batch_operation": 0, + "sql_file": "sql/GET-users-pull_requests-monthly-line_of_changes.sql", + "type": "sql_endpoint", + "return_type": "json" + }, { "name": "/users/pull_requests/monthly/act", "description": "Retrieve a monthly summary of a GitHub user's opened and merged pull requests in the specified time range. (If `from` and `to` are not specified, the default period is the past year.)", @@ -407,7 +451,7 @@ "name": "/repos/pull_requests/monthly/loc", "description": "Retrieve monthly pull request activity with additions, deletions, and net changes for a specific repository.", "method": "GET", - "endpoint": "/repos/pull_requests/monthly/loc", + "endpoint": "/repos/pull_requests/monthly/line_of_changes", "data_source": { "cluster_id": 1379661944642684098 }, @@ -450,7 +494,7 @@ }, "tag": "Default", "batch_operation": 0, - "sql_file": "sql/GET-repos-pull_requests-monthly-loc.sql", + "sql_file": "sql/GET-repos-pull_requests-monthly-line_of_changes.sql", "type": "sql_endpoint", "return_type": "json" }, diff --git a/configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-loc.sql b/configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-line_of_changes.sql similarity index 100% rename from configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-loc.sql rename to configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-line_of_changes.sql diff --git a/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-actions.sql b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-actions.sql index 73ca7a584d8..fe3e21e37a9 100644 --- a/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-actions.sql +++ b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-actions.sql @@ -32,9 +32,9 @@ WITH user AS ( AND action = 'opened' AND pr_merged = false AND - CASE WHEN ${from} = '' THEN (ge.created_at BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW()) - ELSE (ge.created_at >= ${from} AND ge.created_at <= ${to}) - END + CASE WHEN ${from} = '' THEN (ge.created_at BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW()) + ELSE (ge.created_at >= ${from} AND ge.created_at <= ${to}) + END GROUP BY 1 ORDER BY 1 ), event_months AS ( diff --git a/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-line_of_changes.sql b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-line_of_changes.sql new file mode 100644 index 00000000000..680de3ce1bc --- /dev/null +++ b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-line_of_changes.sql @@ -0,0 +1,20 @@ +USE gharchive_dev; + +SELECT + DATE_FORMAT(created_at, '%Y-%m-01') AS event_month, + SUM(additions) AS additions, + SUM(deletions) AS deletions, + SUM(additions + deletions) AS changes +FROM github_events ge +WHERE + creator_user_id = (SELECT id FROM github_users WHERE login = ${username} LIMIT 1) + AND type = 'PullRequestEvent' + AND action = 'closed' + AND pr_merged = true + AND + CASE WHEN ${from} = '' THEN (ge.created_at BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW()) + ELSE (ge.created_at >= ${from} AND ge.created_at <= ${to}) + END +GROUP BY 1 +ORDER BY 1 +;