Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools] Add PR reviews per team page #224

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tools-public/toolpad/pages/OverviewPage/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ spec:
name: text32
props:
value: Joy UI NPM KPIs
- component: Text
name: text34
props:
value: Team PR reviews activit
- component: PageColumn
name: pageColumn9
layout:
Expand Down Expand Up @@ -446,6 +450,17 @@ spec:
parameters: {}
content: View page
variant: text
- component: Button
name: button28
props:
content: View page
variant: text
onClick:
$$navigationAction:
page: muiTeamPullRequestReviews
parameters: {}
layout:
horizontalAlign: end
layout:
columnSize: 1
layout:
Expand Down
86 changes: 86 additions & 0 deletions tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/mui/mui-toolpad/v0.6.0/docs/schemas/v1/definitions.json#properties/Page

apiVersion: v1
kind: page
spec:
title: muiTeamPullRequestReviews
display: shell
content:
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
- component: Text
name: text2
props:
value: TEAM PR REVIEWS ACITVITY
variant: h3
- component: Text
name: text1
props:
value:
$$jsExpression: '`This charts shows PR reviews per team data, in comparison with
a benchmark data (if provided). Use the <code>repoId</code> &
<code>benchmarkId</code> query params by specifying the <a
href="https://ossinsight.io/explore/">OSS Insight</a> id. For the
most commons used repositories, like mui/material-ui, mui/base-ui,
mui/pigment-css, vercel/next.js you can directly use the repository
name.`'
mode: markdown
- component: Text
name: text
layout:
columnSize: 1
props:
value:
$$jsExpression: "`MUI repo: <b>${page.parameters.repoId ??
'mui/material-ui'}</b>, Benchmark repo:
<b>${page.parameters.benchmarkId !== '' ?
page.parameters.benchmarkId : '(not specified)'}</b>`"
mode: markdown
- component: Chart
name: muiPRReviewsPerTeam
layout:
columnSize: 1
props:
data:
- label: MUI repo data
kind: line
data:
$$jsExpression: getRepoDataQuery.data
color: '#2E96FF'
xKey: t_month
yKey: cnt
- label: Benchmark repo data
kind: line
data:
$$jsExpression: getBenchmarkRepoDataQuery.data
color: '#ff9800'
xKey: t_month
yKey: cnt
sx:
zIndex: 0
- component: codeComponent.Diff
name: diff
alias:
- gtOs1gW
parameters:
- name: repoId
value: '23083156'
- name: benchmarkId
value: ''
queries:
- name: getRepoDataQuery
mode: query
query:
function: functions.ts#getTeamPullRequestReviews
kind: local
parameters:
- name: repo
value:
$$jsExpression: page.parameters.repoId
- name: getBenchmarkRepoDataQuery
mode: query
query:
function: functions.ts#getTeamPullRequestReviews
kind: local
parameters:
- name: repo
value:
$$jsExpression: page.parameters.benchmarkId
56 changes: 56 additions & 0 deletions tools-public/toolpad/resources/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,62 @@ SELECT * FROM final_table
return data.data;
}

export async function getTeamPullRequestReviews(repo: string = 'mui/material-ui') {
if (repo === '') {
return [];
}

const repoMap = {
'mui/material-ui': 23083156,
'mui/base-ui': 762289766,
'mui/pigment-css': 715829513,
'vercel/next.js': 70107786,
'radix-ui/primitives': 273499522,
};

const repoParam = repoMap[repo] ?? repo;

const openQuery = `
WITH maintainers as (
SELECT
DISTINCT ge.actor_login
FROM
github_events ge
WHERE
ge.repo_id = ${repoParam}
AND ge.type = 'PullRequestEvent'
/* maintainers are defined as the ones that are allowed to merge PRs */
AND ge.action = 'closed'
AND ge.pr_merged = 1
AND ge.created_at >= '2016-01-01'
)
SELECT
DATE_FORMAT(created_at, '%Y-%m-01') AS t_month,
COUNT(*) AS cnt
FROM github_events ge
WHERE
type = 'PullRequestReviewEvent' AND
action = 'created' AND
repo_id = ${repoParam} AND
actor_login in (SELECT actor_login FROM maintainers)
AND actor_login NOT LIKE 'oliviertassinari' AND actor_login NOT LIKE 'esp1lon' AND actor_login NOT LIKE 'mnajdova'
AND created_at >= '2020-01-01'
GROUP BY 1 ORDER BY 1;
`;
const res = await fetch('https://api.ossinsight.io/q/playground', {
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ sql: openQuery, type: 'repo', id: `${repoParam}` }),
method: 'POST',
});
if (res.status !== 200) {
throw new Error(`HTTP ${res.status}: ${(await res.text()).slice(0, 500)}`);
}
const data = await res.json();
return data.data;
}

export async function queryCommitStatuses(repository: string) {
if (!process.env.GITHUB_TOKEN) {
throw new Error(`Env variable GITHUB_TOKEN not configured`);
Expand Down
Loading