Skip to content

Commit

Permalink
feat: add monthly sizes of prs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tidb-cloud-data-service[bot] authored Nov 25, 2023
1 parent 5f64430 commit 4b29802
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
50 changes: 47 additions & 3 deletions configs/public_api/http_endpoints/config.json
Original file line number Diff line number Diff line change
@@ -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.)",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b29802

Please sign in to comment.