diff --git a/configs/public_api/http_endpoints/config.json b/configs/public_api/http_endpoints/config.json index c376c2518a9..8c88ee729a1 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/siz", + "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/sizes", + "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": "", + "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-sizes.sql", + "type": "sql_endpoint", + "return_type": "json" + }, { "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.)", @@ -272,7 +316,7 @@ "return_type": "json" }, { - "name": "/users/pull_requests/language", + "name": "/users/pull_requests/languages", "description": "Retrieve the count and percentage of a GitHub user's opened pull requests in different programming languages. (If `from` and `to` are not specified, the default period is the past year.)", "method": "GET", "endpoint": "/users/pull_requests/used_languages", @@ -502,7 +546,7 @@ "name": "/repos/pull_requests/monthly/siz", "description": "Get monthly distribution of pull request sizes (XS, S, M, L, XL, XXL) for a specific repository.", "method": "GET", - "endpoint": "/repos/pull_requests/monthly/size", + "endpoint": "/repos/pull_requests/monthly/sizes", "data_source": { "cluster_id": 1379661944642684098 }, @@ -545,7 +589,7 @@ }, "tag": "Default", "batch_operation": 0, - "sql_file": "sql/GET-repos-pull_requests-monthly-size.sql", + "sql_file": "sql/GET-repos-pull_requests-monthly-sizes.sql", "type": "sql_endpoint", "return_type": "json" }, diff --git a/configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-size.sql b/configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-sizes.sql similarity index 100% rename from configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-size.sql rename to configs/public_api/http_endpoints/sql/GET-repos-pull_requests-monthly-sizes.sql diff --git a/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-sizes.sql b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-sizes.sql new file mode 100644 index 00000000000..0fccc55d4d5 --- /dev/null +++ b/configs/public_api/http_endpoints/sql/GET-users-pull_requests-monthly-sizes.sql @@ -0,0 +1,33 @@ +USE gharchive_dev; + +SELECT + t_month AS event_month, xs, s, m, l, xl, xxl, all_size +FROM ( + SELECT + t_month, + SUM(IF(changes < 10, 1, 0)) OVER(PARTITION BY t_month) AS xs, + SUM(IF(changes >= 10 AND changes < 30, 1, 0)) OVER(PARTITION BY t_month) AS s, + SUM(IF(changes >= 30 AND changes < 100, 1, 0)) OVER(PARTITION BY t_month) AS m, + SUM(IF(changes >= 100 AND changes < 500, 1, 0)) OVER(PARTITION BY t_month) AS l, + SUM(IF(changes >= 500 AND changes < 1000, 1, 0)) OVER(PARTITION BY t_month) AS xl, + SUM(IF(changes >= 1000, 1, 0)) OVER (PARTITION BY t_month) AS xxl, + COUNT(*) OVER (PARTITION BY t_month) AS all_size, + ROW_NUMBER() OVER (PARTITION BY t_month) AS row_num + FROM ( + SELECT + DATE_FORMAT(created_at, '%Y-%m-01') AS t_month, + 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 + ) sub +) AS sub +WHERE + row_num = 1 \ No newline at end of file