From f3a06ff74eedf07dcff48e99a8f87edb7e47e05b Mon Sep 17 00:00:00 2001 From: mnajdova Date: Mon, 28 Oct 2024 11:25:36 +0100 Subject: [PATCH 1/8] [tools-public] Scaffold Core team page --- .../toolpad/pages/OverviewPage/page.yml | 15 ++++++++ .../pages/muiTeamPullRequestReviews/page.yml | 34 +++++++++++++++++++ tools-public/toolpad/resources/functions.ts | 29 ++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml diff --git a/tools-public/toolpad/pages/OverviewPage/page.yml b/tools-public/toolpad/pages/OverviewPage/page.yml index 0b17cd0c..0d418cf5 100644 --- a/tools-public/toolpad/pages/OverviewPage/page.yml +++ b/tools-public/toolpad/pages/OverviewPage/page.yml @@ -406,6 +406,10 @@ spec: name: text32 props: value: Joy UI NPM KPIs + - component: Text + name: text34 + props: + value: Material UI - team stats - component: PageColumn name: pageColumn9 layout: @@ -447,6 +451,17 @@ spec: parameters: {} content: View page variant: text + - component: Button + name: button28 + props: + variant: text + content: View page + onClick: + $$navigationAction: + page: gtOs1gW + parameters: {} + layout: + horizontalAlign: end props: visible: $$jsExpression: | diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml new file mode 100644 index 00000000..65625c17 --- /dev/null +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: page +spec: + id: gtOs1gW + title: muiTeamPullRequestReviews + display: shell + content: + - component: PageRow + name: pageRow1 + children: + - component: Text + name: text + props: + value: Material UI - team repo stats + - component: PageRow + name: pageRow + children: + - component: Chart + name: muiPRReviewsPerTeam + props: + data: + - label: Number of reviews + kind: bar + data: + $$jsExpression: | + query.data + color: "#1976d2" + xKey: t_month + yKey: cnt + queries: + - name: query + query: + function: functions.ts#getTeamPullRequestReviews + kind: local diff --git a/tools-public/toolpad/resources/functions.ts b/tools-public/toolpad/resources/functions.ts index 191fd05e..8c08ec83 100644 --- a/tools-public/toolpad/resources/functions.ts +++ b/tools-public/toolpad/resources/functions.ts @@ -106,6 +106,35 @@ SELECT * FROM final_table return data.data; } +export async function getTeamPullRequestReviews() { + const openQuery = ` +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 = 23083156 AND + actor_id in (4512430, 16889233, 18292247, 7225802, 4997971, 717550, 2109932) + # actor_login IN ('mnajdova', 'siriwatknp', 'Janpot', 'DiegoAndai', 'mj12albert', 'aarongarciah', 'brijeshb42') +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: '23083156' }), + 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`); From 830af16f4d0fa8eb0c94ab04e4238cb12fe6c41e Mon Sep 17 00:00:00 2001 From: mnajdova Date: Tue, 29 Oct 2024 14:30:32 +0100 Subject: [PATCH 2/8] add metric for other repos --- .../toolpad/pages/OverviewPage/page.yml | 15 ++++ .../pages/muiTeamPullRequestReviews/page.yml | 80 +++++++++++++------ tools-public/toolpad/resources/functions.ts | 14 ++-- 3 files changed, 81 insertions(+), 28 deletions(-) diff --git a/tools-public/toolpad/pages/OverviewPage/page.yml b/tools-public/toolpad/pages/OverviewPage/page.yml index c7362db9..90514c2c 100644 --- a/tools-public/toolpad/pages/OverviewPage/page.yml +++ b/tools-public/toolpad/pages/OverviewPage/page.yml @@ -405,6 +405,10 @@ spec: name: text32 props: value: Joy UI NPM KPIs + - component: Text + name: text34 + props: + value: MUI Core PR reviews per team - component: PageColumn name: pageColumn9 layout: @@ -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: diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml index 65625c17..7d7cc9df 100644 --- a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -1,34 +1,68 @@ +# 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: - id: gtOs1gW title: muiTeamPullRequestReviews display: shell content: - - component: PageRow - name: pageRow1 - children: - - component: Text - name: text - props: - value: Material UI - team repo stats - - component: PageRow - name: pageRow - children: - - component: Chart - name: muiPRReviewsPerTeam - props: + - component: Text + name: text + layout: + columnSize: 1 + props: + value: Material UI - team repo stats + - component: Chart + name: muiPRReviewsPerTeam + layout: + columnSize: 1 + props: + data: + - label: mui/material-ui + kind: bar data: - - label: Number of reviews - kind: bar - data: - $$jsExpression: | - query.data - color: "#1976d2" - xKey: t_month - yKey: cnt + $$jsExpression: materialUIReviewsQuery.data + color: '#1976d2' + xKey: t_month + yKey: cnt + - label: mui/base-ui + kind: bar + data: + $$jsExpression: baseUIReviewsQuery.data + color: '#4caf50' + xKey: t_month + yKey: cnt + - label: mui/pigment-css + kind: bar + data: + $$jsExpression: pigmentCSSReviewsQuery.data + color: '#B800D8' + xKey: t_month + yKey: cnt + sx: + zIndex: 0 + - component: codeComponent.Diff + name: diff queries: - - name: query + - name: materialUIReviewsQuery + query: + function: functions.ts#getTeamPullRequestReviews + kind: local + - name: baseUIReviewsQuery + mode: query + query: + function: functions.ts#getTeamPullRequestReviews + kind: local + parameters: + - name: repo + value: mui/base-ui + - name: pigmentCSSReviewsQuery + mode: query query: function: functions.ts#getTeamPullRequestReviews kind: local + parameters: + - name: repo + value: mui/pigment-css + alias: + - gtOs1gW diff --git a/tools-public/toolpad/resources/functions.ts b/tools-public/toolpad/resources/functions.ts index 0c00b736..fcbb06c4 100644 --- a/tools-public/toolpad/resources/functions.ts +++ b/tools-public/toolpad/resources/functions.ts @@ -107,7 +107,12 @@ SELECT * FROM final_table return data.data; } -export async function getTeamPullRequestReviews() { +export async function getTeamPullRequestReviews(repo: string = 'mui/material-ui') { + const repoMap = { + 'mui/material-ui': 23083156, + 'mui/base-ui': 762289766, + 'mui/pigment-css': 715829513, + } const openQuery = ` SELECT DATE_FORMAT(created_at, '%Y-%m-01') AS t_month, @@ -116,16 +121,15 @@ FROM github_events ge WHERE type = 'PullRequestReviewEvent' AND action = 'created' AND - repo_id = 23083156 AND - actor_id in (4512430, 16889233, 18292247, 7225802, 4997971, 717550, 2109932) - # actor_login IN ('mnajdova', 'siriwatknp', 'Janpot', 'DiegoAndai', 'mj12albert', 'aarongarciah', 'brijeshb42') + repo_id = ${repoMap[repo]} AND + actor_login IN ('mnajdova', 'siriwatknp', 'Janpot', 'DiegoAndai', 'mj12albert', 'aarongarciah', 'brijeshb42', 'michaldudak', 'colmtuite', 'atomiks', 'vladmoroz') 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: '23083156' }), + body: JSON.stringify({ sql: openQuery, type: 'repo', id: `${repoMap[repo]}` }), method: 'POST', }); if (res.status !== 200) { From 16cae813dfa569953d9c427d474f04fc008a1e10 Mon Sep 17 00:00:00 2001 From: mnajdova Date: Tue, 29 Oct 2024 14:49:56 +0100 Subject: [PATCH 3/8] prettier --- tools-public/toolpad/resources/functions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools-public/toolpad/resources/functions.ts b/tools-public/toolpad/resources/functions.ts index fcbb06c4..9c33d875 100644 --- a/tools-public/toolpad/resources/functions.ts +++ b/tools-public/toolpad/resources/functions.ts @@ -112,7 +112,7 @@ export async function getTeamPullRequestReviews(repo: string = 'mui/material-ui' 'mui/material-ui': 23083156, 'mui/base-ui': 762289766, 'mui/pigment-css': 715829513, - } + }; const openQuery = ` SELECT DATE_FORMAT(created_at, '%Y-%m-01') AS t_month, @@ -139,7 +139,6 @@ GROUP BY 1 ORDER BY 1; return data.data; } - export async function queryCommitStatuses(repository: string) { if (!process.env.GITHUB_TOKEN) { throw new Error(`Env variable GITHUB_TOKEN not configured`); From eb68db8cbd0e74d1c9d6df1e34fdaad799e9dcb9 Mon Sep 17 00:00:00 2001 From: mnajdova Date: Tue, 29 Oct 2024 14:53:33 +0100 Subject: [PATCH 4/8] improve label --- tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml index 7d7cc9df..8c917c83 100644 --- a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -11,7 +11,7 @@ spec: layout: columnSize: 1 props: - value: Material UI - team repo stats + value: PR reviews by team members - component: Chart name: muiPRReviewsPerTeam layout: From 9a77bc364ef610a28ff282bfdcf80c2caadd6488 Mon Sep 17 00:00:00 2001 From: mnajdova Date: Fri, 1 Nov 2024 13:01:15 +0100 Subject: [PATCH 5/8] add repoId & benchmarkId page params, improve chart --- .../pages/muiTeamPullRequestReviews/page.yml | 65 +++++++++++-------- tools-public/toolpad/resources/functions.ts | 29 ++++++++- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml index 8c917c83..9ce35dfb 100644 --- a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -6,63 +6,76 @@ spec: title: muiTeamPullRequestReviews display: shell content: + - 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 repoId & + benchmarkId query params by specifying the OSS Insight 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: PR reviews by team members + value: + $$jsExpression: "`MUI repo: ${page.parameters.repoId ?? + 'mui/material-ui'}, Benchmark repo: + ${page.parameters.benchmarkId !== '' ? + page.parameters.benchmarkId : '(not specified)'}`" + mode: markdown - component: Chart name: muiPRReviewsPerTeam layout: columnSize: 1 props: data: - - label: mui/material-ui - kind: bar - data: - $$jsExpression: materialUIReviewsQuery.data - color: '#1976d2' - xKey: t_month - yKey: cnt - - label: mui/base-ui - kind: bar + - label: Benchmark repo data + kind: line data: - $$jsExpression: baseUIReviewsQuery.data - color: '#4caf50' + $$jsExpression: getBenchmarkRepoDataQuery.data + color: '#ff9800' xKey: t_month yKey: cnt - - label: mui/pigment-css - kind: bar + - label: MUI repo data + kind: line data: - $$jsExpression: pigmentCSSReviewsQuery.data - color: '#B800D8' + $$jsExpression: getRepoDataQuery.data + color: '#2E96FF' 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: materialUIReviewsQuery - query: - function: functions.ts#getTeamPullRequestReviews - kind: local - - name: baseUIReviewsQuery + - name: getRepoDataQuery mode: query query: function: functions.ts#getTeamPullRequestReviews kind: local parameters: - name: repo - value: mui/base-ui - - name: pigmentCSSReviewsQuery + value: + $$jsExpression: page.parameters.repoId + - name: getBenchmarkRepoDataQuery mode: query query: function: functions.ts#getTeamPullRequestReviews kind: local parameters: - name: repo - value: mui/pigment-css - alias: - - gtOs1gW + value: + $$jsExpression: page.parameters.benchmarkId diff --git a/tools-public/toolpad/resources/functions.ts b/tools-public/toolpad/resources/functions.ts index 9c33d875..f4bd195c 100644 --- a/tools-public/toolpad/resources/functions.ts +++ b/tools-public/toolpad/resources/functions.ts @@ -108,12 +108,34 @@ SELECT * FROM final_table } 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 @@ -121,15 +143,16 @@ FROM github_events ge WHERE type = 'PullRequestReviewEvent' AND action = 'created' AND - repo_id = ${repoMap[repo]} AND - actor_login IN ('mnajdova', 'siriwatknp', 'Janpot', 'DiegoAndai', 'mj12albert', 'aarongarciah', 'brijeshb42', 'michaldudak', 'colmtuite', 'atomiks', 'vladmoroz') + 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' 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: `${repoMap[repo]}` }), + body: JSON.stringify({ sql: openQuery, type: 'repo', id: `${repoParam}` }), method: 'POST', }); if (res.status !== 200) { From 800a1c55d10b3e884a2b104119ff1e5f76fc1dfc Mon Sep 17 00:00:00 2001 From: Marija Najdova Date: Fri, 1 Nov 2024 16:01:34 +0100 Subject: [PATCH 6/8] Update tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml Signed-off-by: Marija Najdova --- .../toolpad/pages/muiTeamPullRequestReviews/page.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml index 9ce35dfb..042624ff 100644 --- a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -6,6 +6,11 @@ spec: title: muiTeamPullRequestReviews display: shell content: + - component: Text + name: text2 + props: + value: TEAM PR REVIEWS ACITVITY + variant: h3 - component: Text name: text1 props: From ef1f14d534feae49d0e9750a28f5d14ab9c51510 Mon Sep 17 00:00:00 2001 From: mnajdova Date: Fri, 1 Nov 2024 16:19:28 +0100 Subject: [PATCH 7/8] improve page name & data order --- tools-public/toolpad/pages/OverviewPage/page.yml | 2 +- .../toolpad/pages/muiTeamPullRequestReviews/page.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools-public/toolpad/pages/OverviewPage/page.yml b/tools-public/toolpad/pages/OverviewPage/page.yml index 90514c2c..bed55d13 100644 --- a/tools-public/toolpad/pages/OverviewPage/page.yml +++ b/tools-public/toolpad/pages/OverviewPage/page.yml @@ -408,7 +408,7 @@ spec: - component: Text name: text34 props: - value: MUI Core PR reviews per team + value: Team PR reviews activit - component: PageColumn name: pageColumn9 layout: diff --git a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml index 042624ff..9aa9bd4e 100644 --- a/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml +++ b/tools-public/toolpad/pages/muiTeamPullRequestReviews/page.yml @@ -40,18 +40,18 @@ spec: columnSize: 1 props: data: - - label: Benchmark repo data + - label: MUI repo data kind: line data: - $$jsExpression: getBenchmarkRepoDataQuery.data - color: '#ff9800' + $$jsExpression: getRepoDataQuery.data + color: '#2E96FF' xKey: t_month yKey: cnt - - label: MUI repo data + - label: Benchmark repo data kind: line data: - $$jsExpression: getRepoDataQuery.data - color: '#2E96FF' + $$jsExpression: getBenchmarkRepoDataQuery.data + color: '#ff9800' xKey: t_month yKey: cnt sx: From 7948c0f3f18928f94e84fd3be9222ba9067f808d Mon Sep 17 00:00:00 2001 From: mnajdova Date: Fri, 1 Nov 2024 16:26:44 +0100 Subject: [PATCH 8/8] add start date --- tools-public/toolpad/resources/functions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tools-public/toolpad/resources/functions.ts b/tools-public/toolpad/resources/functions.ts index f4bd195c..a310dfc0 100644 --- a/tools-public/toolpad/resources/functions.ts +++ b/tools-public/toolpad/resources/functions.ts @@ -146,6 +146,7 @@ WHERE 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', {