Skip to content

Commit

Permalink
feat: add monthly line of changes 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 399fbb4 commit 5f64430
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
48 changes: 46 additions & 2 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/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.)",
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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
;

0 comments on commit 5f64430

Please sign in to comment.