Skip to content

Commit

Permalink
queries: add last 28 days queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini256 committed Aug 15, 2023
1 parent e4634dc commit 0fe8162
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 56 deletions.
22 changes: 22 additions & 0 deletions configs/queries/analyze-event-trends/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cacheHours": 1,
"params": [
{
"name": "repoId",
"replaces": "${repoId}",
"pattern": "^[1-9]\\d*$"
},
{
"name": "from",
"replaces": "${from}",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2000-01-01"
},
{
"name": "to",
"replaces": "${to}",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"default": "2099-12-31"
}
]
}
11 changes: 11 additions & 0 deletions configs/queries/analyze-event-trends/template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT
DATE_FORMAT(created_at, '%Y-%m-01') AS event_month,
COUNT(*) AS events
FROM github_events
WHERE
repo_id = ${repoId}
AND created_at >= '${from}'
AND created_at < '${to}'
GROUP BY event_month
ORDER BY event_month
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cacheHours": 1,
"params": [
{
"name": "repoId",
"replaces": "41986369",
"pattern": "^[1-9]\\d*$"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
WITH opened_prs AS (
SELECT
COUNT(*) AS prs
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PullRequestEvent'
AND action = 'opened'
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
), merged_prs AS (
SELECT
COUNT(*) AS prs
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PullRequestEvent'
AND action = 'closed'
AND pr_merged = true
-- PR was merged in the last 28 days.
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
-- PR was created in the last 28 days.
AND ge.pr_or_issue_created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
), opened_issues AS (
SELECT
COUNT(*) AS issues
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'IssuesEvent'
AND action = 'opened'
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
), closed_issues AS (
SELECT
COUNT(*) AS issues
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'IssuesEvent'
AND action = 'closed'
-- Issue was closed in the last 28 days.
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
-- Issue was opened in the last 28 days.
AND ge.pr_or_issue_created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
), reviewed_prs AS (
SELECT
COUNT(DISTINCT number) AS prs
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PullRequestReviewEvent'
AND action = 'created'
-- PR was reviewed in the last 28 days.
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
-- PR was created in the last 28 days.
AND ge.pr_or_issue_created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
)
SELECT
mp.prs / op.prs * 100 AS pr_merged_ratio,
rp.prs / op.prs * 100 AS pr_reviewed_ratio,
ci.issues / oi.issues * 100 AS issue_closed_ratio
FROM
opened_prs op,
merged_prs mp,
reviewed_prs rp,
opened_issues oi,
closed_issues ci
6 changes: 6 additions & 0 deletions configs/queries/analyze-recent-top-contributors/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"name": "repoId",
"replaces": "41986369",
"pattern": "^[1-9]\\d*$"
},
{
"name": "limit",
"replaces": "9999999999",
"pattern": "^[1-9]\\d*$",
"default": 5
}
]
}
64 changes: 13 additions & 51 deletions configs/queries/analyze-recent-top-contributors/template.sql
Original file line number Diff line number Diff line change
@@ -1,62 +1,24 @@
WITH prs AS (
WITH contributions AS (
SELECT
actor_login, COUNT(*) AS events
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PullRequestEvent'
AND action = 'opened'
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
AND actor_login NOT LIKE '%bot' AND actor_login NOT LIKE '%[bot]' AND actor_login NOT IN (SELECT login FROM blacklist_users bu)
GROUP BY actor_login
), issues AS (
SELECT
actor_login, COUNT(*) AS events
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'IssuesEvent'
AND action = 'opened'
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
AND actor_login NOT LIKE '%bot' AND actor_login NOT LIKE '%[bot]' AND actor_login NOT IN (SELECT login FROM blacklist_users bu)
GROUP BY actor_login
), reviews AS (
SELECT
actor_login, COUNT(*) AS events
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PullRequestReviewEvent'
AND action = 'created'
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
AND actor_login NOT LIKE '%bot' AND actor_login NOT LIKE '%[bot]' AND actor_login NOT IN (SELECT login FROM blacklist_users bu)
GROUP BY actor_login
), pushes AS (
SELECT
actor_login, COUNT(*) AS events
FROM
github_events ge
WHERE
repo_id = 41986369
AND type = 'PushEvent'
AND action = ''
AND (
(type = 'PullRequestEvent' AND action = 'opened') OR
(type = 'IssuesEvent' AND action = 'opened') OR
(type = 'IssueCommentEvent' AND action = 'created') OR
(type = 'PullRequestReviewEvent' AND action = 'created') OR
(type = 'PullRequestReviewCommentEvent' AND action = 'created') OR
(type = 'PushEvent' AND action = '')
)
AND ge.created_at > DATE_SUB(CURRENT_DATE(), INTERVAL 28 DAY)
AND actor_login NOT LIKE '%bot' AND actor_login NOT LIKE '%[bot]' AND actor_login NOT IN (SELECT login FROM blacklist_users bu)
GROUP BY actor_login
)
SELECT actor_login, SUM(sub.events) AS events
FROM (
SELECT * FROM prs
UNION
SELECT * FROM issues
UNION
SELECT * FROM reviews
UNION
SELECT * FROM pushes
) sub
SELECT actor_login, c.events AS events
FROM contributions c
GROUP BY actor_login
ORDER BY SUM(sub.events) DESC
LIMIT 5
ORDER BY c.events DESC
LIMIT 9999999999
4 changes: 0 additions & 4 deletions configs/queries/foo/bar/params.json

This file was deleted.

1 change: 0 additions & 1 deletion configs/queries/foo/bar/template.sql

This file was deleted.

0 comments on commit 0fe8162

Please sign in to comment.