@stoked-ui/github 0.0.0-a.0 → 0.1.0-alpha.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GithubBranch/GithubBranch.d.ts +12 -0
- package/GithubBranch/GithubBranch.js +177 -0
- package/GithubBranch/index.d.ts +2 -0
- package/GithubBranch/index.js +2 -0
- package/GithubBranch/package.json +6 -0
- package/GithubCalendar/GithubCalendar.d.ts +6 -2
- package/GithubCalendar/GithubCalendar.js +70 -28
- package/GithubCommit/GithubCommit.d.ts +11 -0
- package/GithubCommit/GithubCommit.js +170 -0
- package/GithubCommit/index.d.ts +2 -0
- package/GithubCommit/index.js +2 -0
- package/GithubCommit/package.json +6 -0
- package/GithubEvents/GithubEvents.d.ts +4 -24
- package/GithubEvents/GithubEvents.js +141 -220
- package/apiHandlers/createGithubBranchHandler.d.ts +12 -0
- package/apiHandlers/createGithubBranchHandler.js +41 -0
- package/apiHandlers/createGithubCommitHandler.d.ts +12 -0
- package/apiHandlers/createGithubCommitHandler.js +39 -0
- package/apiHandlers/createGithubContributionsHandler.d.ts +15 -0
- package/apiHandlers/createGithubContributionsHandler.js +41 -0
- package/apiHandlers/createGithubEventsHandler.d.ts +15 -0
- package/apiHandlers/createGithubEventsHandler.js +50 -0
- package/apiHandlers/getBranchCompareDetails.d.ts +9 -0
- package/apiHandlers/getBranchCompareDetails.js +29 -0
- package/apiHandlers/getCommitDetails.d.ts +8 -0
- package/apiHandlers/getCommitDetails.js +34 -0
- package/apiHandlers/getGithubContributions.d.ts +8 -0
- package/apiHandlers/getGithubContributions.js +126 -0
- package/apiHandlers/getGithubEvents.d.ts +25 -0
- package/apiHandlers/getGithubEvents.js +142 -0
- package/apiHandlers/getPullRequestDetails.js +2 -2
- package/apiHandlers/githubApi.d.ts +17 -0
- package/apiHandlers/githubApi.js +155 -0
- package/apiHandlers/index.d.ts +9 -0
- package/apiHandlers/index.js +9 -1
- package/components/GithubContributorsList.d.ts +8 -0
- package/components/GithubContributorsList.js +72 -0
- package/components/fetchGithubViewData.d.ts +1 -0
- package/components/fetchGithubViewData.js +10 -0
- package/index.d.ts +6 -1
- package/index.js +5 -2
- package/modern/GithubBranch/GithubBranch.js +177 -0
- package/modern/GithubBranch/index.js +2 -0
- package/modern/GithubCalendar/GithubCalendar.js +70 -28
- package/modern/GithubCommit/GithubCommit.js +170 -0
- package/modern/GithubCommit/index.js +2 -0
- package/modern/GithubEvents/GithubEvents.js +141 -220
- package/modern/apiHandlers/createGithubBranchHandler.js +41 -0
- package/modern/apiHandlers/createGithubCommitHandler.js +39 -0
- package/modern/apiHandlers/createGithubContributionsHandler.js +41 -0
- package/modern/apiHandlers/createGithubEventsHandler.js +50 -0
- package/modern/apiHandlers/getBranchCompareDetails.js +29 -0
- package/modern/apiHandlers/getCommitDetails.js +34 -0
- package/modern/apiHandlers/getGithubContributions.js +126 -0
- package/modern/apiHandlers/getGithubEvents.js +142 -0
- package/modern/apiHandlers/getPullRequestDetails.js +2 -2
- package/modern/apiHandlers/githubApi.js +155 -0
- package/modern/apiHandlers/index.js +9 -1
- package/modern/components/GithubContributorsList.js +72 -0
- package/modern/components/fetchGithubViewData.js +10 -0
- package/modern/index.js +5 -2
- package/node/GithubBranch/GithubBranch.js +185 -0
- package/node/GithubBranch/index.js +9 -0
- package/node/GithubCalendar/GithubCalendar.js +70 -28
- package/node/GithubCommit/GithubCommit.js +178 -0
- package/node/GithubCommit/index.js +9 -0
- package/node/GithubEvents/GithubEvents.js +148 -223
- package/node/apiHandlers/createGithubBranchHandler.js +48 -0
- package/node/apiHandlers/createGithubCommitHandler.js +46 -0
- package/node/apiHandlers/createGithubContributionsHandler.js +48 -0
- package/node/apiHandlers/createGithubEventsHandler.js +57 -0
- package/node/apiHandlers/getBranchCompareDetails.js +35 -0
- package/node/apiHandlers/getCommitDetails.js +40 -0
- package/node/apiHandlers/getGithubContributions.js +132 -0
- package/node/apiHandlers/getGithubEvents.js +149 -0
- package/node/apiHandlers/getPullRequestDetails.js +2 -2
- package/node/apiHandlers/githubApi.js +168 -0
- package/node/apiHandlers/index.js +64 -1
- package/node/components/GithubContributorsList.js +80 -0
- package/node/components/fetchGithubViewData.js +16 -0
- package/node/index.js +77 -2
- package/package.json +6 -6
- package/types/github.d.ts +75 -11
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GithubBranchData } from '../types/github';
|
|
3
|
+
export interface GithubBranchProps {
|
|
4
|
+
owner: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
base: string;
|
|
7
|
+
head: string;
|
|
8
|
+
apiUrl?: string;
|
|
9
|
+
private?: boolean;
|
|
10
|
+
data?: GithubBranchData;
|
|
11
|
+
}
|
|
12
|
+
export default function GithubBranch({ owner, repo, base, head, apiUrl, private: privateMode, data, }: GithubBranchProps): React.JSX.Element;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var _CircularProgress;
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import Box from '@mui/material/Box';
|
|
4
|
+
import Chip from '@mui/material/Chip';
|
|
5
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
6
|
+
import Link from '@mui/material/Link';
|
|
7
|
+
import Typography from '@mui/material/Typography';
|
|
8
|
+
import PullRequestView from '../GithubEvents/EventTypes/PullRequest/PullRequestView';
|
|
9
|
+
import getBranchCompareDetails from '../apiHandlers/getBranchCompareDetails';
|
|
10
|
+
import GithubContributorsList from '../components/GithubContributorsList';
|
|
11
|
+
import fetchGithubViewData from '../components/fetchGithubViewData';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
function getStatusColor(status) {
|
|
14
|
+
switch (status) {
|
|
15
|
+
case 'ahead':
|
|
16
|
+
case 'identical':
|
|
17
|
+
return 'success';
|
|
18
|
+
case 'behind':
|
|
19
|
+
return 'warning';
|
|
20
|
+
case 'diverged':
|
|
21
|
+
return 'info';
|
|
22
|
+
default:
|
|
23
|
+
return 'default';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function loadBranchData({
|
|
27
|
+
apiUrl,
|
|
28
|
+
owner,
|
|
29
|
+
repo,
|
|
30
|
+
base,
|
|
31
|
+
head
|
|
32
|
+
}) {
|
|
33
|
+
if (apiUrl) {
|
|
34
|
+
return fetchGithubViewData(apiUrl, {
|
|
35
|
+
owner,
|
|
36
|
+
repo,
|
|
37
|
+
base,
|
|
38
|
+
head
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return getBranchCompareDetails({
|
|
42
|
+
owner,
|
|
43
|
+
repo,
|
|
44
|
+
base,
|
|
45
|
+
head
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export default function GithubBranch({
|
|
49
|
+
owner,
|
|
50
|
+
repo,
|
|
51
|
+
base,
|
|
52
|
+
head,
|
|
53
|
+
apiUrl,
|
|
54
|
+
private: privateMode = false,
|
|
55
|
+
data
|
|
56
|
+
}) {
|
|
57
|
+
const [branchData, setBranchData] = React.useState(data || null);
|
|
58
|
+
const [loading, setLoading] = React.useState(!data && !privateMode);
|
|
59
|
+
const [error, setError] = React.useState(null);
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (privateMode) {
|
|
62
|
+
setBranchData(data || null);
|
|
63
|
+
setLoading(false);
|
|
64
|
+
setError(data ? null : 'Private mode requires pre-generated snapshot data.');
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (data) {
|
|
68
|
+
setBranchData(data);
|
|
69
|
+
setLoading(false);
|
|
70
|
+
setError(null);
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
let active = true;
|
|
74
|
+
setLoading(true);
|
|
75
|
+
setError(null);
|
|
76
|
+
setBranchData(null);
|
|
77
|
+
loadBranchData({
|
|
78
|
+
apiUrl,
|
|
79
|
+
owner,
|
|
80
|
+
repo,
|
|
81
|
+
base,
|
|
82
|
+
head
|
|
83
|
+
}).then(nextData => {
|
|
84
|
+
if (!active) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setBranchData(nextData);
|
|
88
|
+
}).catch(nextError => {
|
|
89
|
+
if (!active) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
setError(nextError instanceof Error ? nextError.message : 'Failed to load branch data.');
|
|
93
|
+
}).finally(() => {
|
|
94
|
+
if (active) {
|
|
95
|
+
setLoading(false);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
active = false;
|
|
100
|
+
};
|
|
101
|
+
}, [apiUrl, base, data, head, owner, privateMode, repo]);
|
|
102
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
103
|
+
sx: {
|
|
104
|
+
p: 2
|
|
105
|
+
},
|
|
106
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
107
|
+
sx: {
|
|
108
|
+
mb: 2
|
|
109
|
+
},
|
|
110
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
111
|
+
sx: {
|
|
112
|
+
display: 'flex',
|
|
113
|
+
flexWrap: 'wrap',
|
|
114
|
+
gap: 1,
|
|
115
|
+
mb: 1.5
|
|
116
|
+
},
|
|
117
|
+
children: [/*#__PURE__*/_jsx(Chip, {
|
|
118
|
+
label: `${owner}/${repo}`,
|
|
119
|
+
size: "small",
|
|
120
|
+
color: "primary",
|
|
121
|
+
variant: "outlined"
|
|
122
|
+
}), /*#__PURE__*/_jsx(Chip, {
|
|
123
|
+
label: head,
|
|
124
|
+
size: "small"
|
|
125
|
+
}), /*#__PURE__*/_jsx(Chip, {
|
|
126
|
+
label: `base: ${base}`,
|
|
127
|
+
size: "small",
|
|
128
|
+
variant: "outlined"
|
|
129
|
+
}), branchData ? /*#__PURE__*/_jsx(Chip, {
|
|
130
|
+
label: branchData.status,
|
|
131
|
+
size: "small",
|
|
132
|
+
color: getStatusColor(branchData.status)
|
|
133
|
+
}) : null]
|
|
134
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
|
135
|
+
variant: "h6",
|
|
136
|
+
component: "h2",
|
|
137
|
+
sx: {
|
|
138
|
+
mb: 1
|
|
139
|
+
},
|
|
140
|
+
children: branchData != null && branchData.url ? /*#__PURE__*/_jsx(Link, {
|
|
141
|
+
href: branchData.url,
|
|
142
|
+
target: "_blank",
|
|
143
|
+
rel: "noopener noreferrer",
|
|
144
|
+
underline: "hover",
|
|
145
|
+
children: branchData.headRef
|
|
146
|
+
}) : head
|
|
147
|
+
}), branchData ? /*#__PURE__*/_jsxs(Typography, {
|
|
148
|
+
variant: "body2",
|
|
149
|
+
color: "text.secondary",
|
|
150
|
+
children: ["Comparing against ", branchData.baseRef, ". ", branchData.aheadBy, " ahead, ", branchData.behindBy, ' ', "behind, ", branchData.totalCommits, " commit", branchData.totalCommits === 1 ? '' : 's', " in the comparison."]
|
|
151
|
+
}) : null]
|
|
152
|
+
}), loading ? /*#__PURE__*/_jsx(Box, {
|
|
153
|
+
sx: {
|
|
154
|
+
display: 'flex',
|
|
155
|
+
justifyContent: 'center',
|
|
156
|
+
py: 4
|
|
157
|
+
},
|
|
158
|
+
children: _CircularProgress || (_CircularProgress = /*#__PURE__*/_jsx(CircularProgress, {}))
|
|
159
|
+
}) : null, error ? /*#__PURE__*/_jsx(Typography, {
|
|
160
|
+
color: "error",
|
|
161
|
+
sx: {
|
|
162
|
+
mb: 2
|
|
163
|
+
},
|
|
164
|
+
children: error
|
|
165
|
+
}) : null, branchData ? /*#__PURE__*/_jsxs(React.Fragment, {
|
|
166
|
+
children: [/*#__PURE__*/_jsx(GithubContributorsList, {
|
|
167
|
+
contributors: branchData.contributors,
|
|
168
|
+
title: "Contributors"
|
|
169
|
+
}), /*#__PURE__*/_jsx(PullRequestView, {
|
|
170
|
+
title: "",
|
|
171
|
+
number: 0,
|
|
172
|
+
commits: branchData.commits,
|
|
173
|
+
files: branchData.files
|
|
174
|
+
})]
|
|
175
|
+
}) : null]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
interface GithubCalendarProps {
|
|
2
|
+
apiUrl?: string;
|
|
3
|
+
githubUser: string;
|
|
2
4
|
windowMode?: boolean;
|
|
3
5
|
containerMode?: boolean;
|
|
4
6
|
blockSize?: number;
|
|
5
7
|
fx?: 'punch' | 'highlight';
|
|
6
8
|
startImage?: string;
|
|
7
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export default function GithubCalendar({ apiUrl, githubUser, windowMode, containerMode, blockSize: inputBlockSize, fx, startImage }: GithubCalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -6,11 +6,45 @@ import { useTheme } from '@mui/material/styles';
|
|
|
6
6
|
import { useResize } from '@stoked-ui/common';
|
|
7
7
|
import { useResizeWindow } from '@stoked-ui/common';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
9
|
+
function formatActivityDate(date) {
|
|
10
|
+
const year = date.getFullYear();
|
|
11
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
12
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
13
|
+
return `${year}-${month}-${day}`;
|
|
14
|
+
}
|
|
15
|
+
function createFallbackActivityData() {
|
|
16
|
+
const year = new Date().getFullYear();
|
|
17
|
+
const start = new Date(year, 0, 1);
|
|
18
|
+
const end = new Date(year, 11, 31);
|
|
19
|
+
const contributions = [];
|
|
20
|
+
for (const date = new Date(start); date <= end; date.setDate(date.getDate() + 1)) {
|
|
21
|
+
contributions.push({
|
|
22
|
+
date: formatActivityDate(date),
|
|
23
|
+
count: 0,
|
|
24
|
+
level: 0
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
total: {
|
|
29
|
+
[String(year)]: 0
|
|
30
|
+
},
|
|
31
|
+
contributions,
|
|
32
|
+
countLabel: 'Contribution data unavailable',
|
|
33
|
+
totalWeeks: Math.ceil(contributions.length / 7)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function buildCountLabel(total) {
|
|
37
|
+
const totalKeys = Object.keys(total).sort();
|
|
38
|
+
const all = Object.values(total).reduce((acc, curr) => acc + curr, 0);
|
|
39
|
+
if (totalKeys.length === 0) {
|
|
40
|
+
return `${all} contributions`;
|
|
41
|
+
}
|
|
42
|
+
return `${all} contributions from ${totalKeys[0]} to ${totalKeys[totalKeys.length - 1]}`;
|
|
43
|
+
}
|
|
44
|
+
function buildApiUrl(apiUrl, githubUser) {
|
|
45
|
+
const separator = apiUrl.includes('?') ? '&' : '?';
|
|
46
|
+
return `${apiUrl}${separator}username=${encodeURIComponent(githubUser)}`;
|
|
47
|
+
}
|
|
14
48
|
function sleep(duration) {
|
|
15
49
|
return new Promise(resolve => {
|
|
16
50
|
setTimeout(() => {
|
|
@@ -19,6 +53,8 @@ function sleep(duration) {
|
|
|
19
53
|
});
|
|
20
54
|
}
|
|
21
55
|
export default function GithubCalendar({
|
|
56
|
+
apiUrl,
|
|
57
|
+
githubUser,
|
|
22
58
|
windowMode = false,
|
|
23
59
|
containerMode = false,
|
|
24
60
|
blockSize: inputBlockSize = 12,
|
|
@@ -26,7 +62,7 @@ export default function GithubCalendar({
|
|
|
26
62
|
startImage = undefined
|
|
27
63
|
}) {
|
|
28
64
|
const [activityTheme, setActivityTheme] = React.useState('light');
|
|
29
|
-
const [activityData, setActivityData] = React.useState(
|
|
65
|
+
const [activityData, setActivityData] = React.useState(() => createFallbackActivityData());
|
|
30
66
|
const [activityLoading, setActivityLoading] = React.useState(true);
|
|
31
67
|
const [activityHover, setActivityHover] = React.useState(false);
|
|
32
68
|
const [activityLabels, setActivityLabels] = React.useState(false);
|
|
@@ -80,7 +116,10 @@ export default function GithubCalendar({
|
|
|
80
116
|
const fetchActivityData = async () => {
|
|
81
117
|
setActivityLoading(true);
|
|
82
118
|
try {
|
|
83
|
-
|
|
119
|
+
if (!githubUser) {
|
|
120
|
+
throw new Error('githubUser is required');
|
|
121
|
+
}
|
|
122
|
+
const response = await fetch(apiUrl ? buildApiUrl(apiUrl, githubUser) : `https://github-contributions-api.jogruber.de/v4/${encodeURIComponent(githubUser)}?yr=last`);
|
|
84
123
|
if (!response.ok) {
|
|
85
124
|
throw new Error(`API error: ${response.status}`);
|
|
86
125
|
}
|
|
@@ -94,40 +133,43 @@ export default function GithubCalendar({
|
|
|
94
133
|
}
|
|
95
134
|
return 0;
|
|
96
135
|
}
|
|
97
|
-
const
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const year = today.getFullYear();
|
|
103
|
-
const month = String(today.getMonth() + 1).padStart(2, '0'); // Month is 0-indexed
|
|
104
|
-
const day = String(today.getDate()).padStart(2, '0');
|
|
105
|
-
const formattedDate = `${year}-${month}-${day}`;
|
|
106
|
-
const contribs = data.contributions.filter(contrib => contrib.date < formattedDate && (!earliestDate || contrib.date >= earliestDate.date));
|
|
107
|
-
data.contributions = contribs.sort(compare);
|
|
136
|
+
const contributions = Array.isArray(data.contributions) ? data.contributions : [];
|
|
137
|
+
const contribs = [...contributions].sort(compare);
|
|
138
|
+
if (contribs.length === 0) {
|
|
139
|
+
throw new Error('Contribution API returned no usable activity data');
|
|
140
|
+
}
|
|
108
141
|
const allJansSet = contribs.map(contrib => {
|
|
109
142
|
return contrib.date.slice(2, 7);
|
|
110
143
|
}).filter(yymm => yymm.slice(-2) === '01');
|
|
111
144
|
const allJans = new Set(allJansSet);
|
|
112
145
|
console.log('allJans', [...allJans]);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
146
|
+
const total = data.total && Object.keys(data.total).length > 0 ? data.total : contribs.reduce((acc, contribution) => {
|
|
147
|
+
const year = contribution.date.slice(0, 4);
|
|
148
|
+
acc[year] = (acc[year] || 0) + contribution.count;
|
|
149
|
+
return acc;
|
|
150
|
+
}, {});
|
|
151
|
+
const countLabel = data.countLabel || buildCountLabel(total);
|
|
152
|
+
const totalWeeks = Math.ceil(contribs.length / 7);
|
|
153
|
+
const nextActivityData = {
|
|
154
|
+
total,
|
|
155
|
+
contributions: contribs,
|
|
156
|
+
countLabel,
|
|
157
|
+
totalWeeks
|
|
158
|
+
};
|
|
117
159
|
if (inputBlockSize) {
|
|
118
|
-
|
|
160
|
+
nextActivityData.blockSize = inputBlockSize;
|
|
119
161
|
} else if (windowMode) {
|
|
120
|
-
|
|
162
|
+
nextActivityData.blockSize = Math.max(10, Math.floor(windowWidth / totalWeeks));
|
|
121
163
|
} else {
|
|
122
164
|
if (elemSize.width) {
|
|
123
|
-
|
|
165
|
+
nextActivityData.blockSize = Math.max(10, Math.floor(elemSize.width / totalWeeks));
|
|
124
166
|
}
|
|
125
167
|
}
|
|
126
|
-
setActivityData(
|
|
168
|
+
setActivityData(nextActivityData);
|
|
127
169
|
} catch (err) {
|
|
128
170
|
console.error(`Error fetching activity data: ${err instanceof Error ? err.message : String(err)}`);
|
|
129
171
|
// Use fallback data if API fails
|
|
130
|
-
setActivityData(
|
|
172
|
+
setActivityData(createFallbackActivityData());
|
|
131
173
|
} finally {
|
|
132
174
|
setActivityLoading(false);
|
|
133
175
|
}
|
|
@@ -181,7 +223,7 @@ export default function GithubCalendar({
|
|
|
181
223
|
}
|
|
182
224
|
}
|
|
183
225
|
};
|
|
184
|
-
}, []);
|
|
226
|
+
}, [apiUrl, fx, githubUser]);
|
|
185
227
|
const handleResize = () => {
|
|
186
228
|
var _elementRef$current2;
|
|
187
229
|
// Clear all animations first
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GithubCommitData } from '../types/github';
|
|
3
|
+
export interface GithubCommitProps {
|
|
4
|
+
owner: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
commitRef: string;
|
|
7
|
+
apiUrl?: string;
|
|
8
|
+
private?: boolean;
|
|
9
|
+
data?: GithubCommitData;
|
|
10
|
+
}
|
|
11
|
+
export default function GithubCommit({ owner, repo, commitRef, apiUrl, private: privateMode, data, }: GithubCommitProps): React.JSX.Element;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var _CircularProgress;
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import Box from '@mui/material/Box';
|
|
4
|
+
import Chip from '@mui/material/Chip';
|
|
5
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
6
|
+
import Link from '@mui/material/Link';
|
|
7
|
+
import Typography from '@mui/material/Typography';
|
|
8
|
+
import PullRequestView from '../GithubEvents/EventTypes/PullRequest/PullRequestView';
|
|
9
|
+
import getCommitDetails from '../apiHandlers/getCommitDetails';
|
|
10
|
+
import GithubContributorsList from '../components/GithubContributorsList';
|
|
11
|
+
import fetchGithubViewData from '../components/fetchGithubViewData';
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
function formatCommitDate(value) {
|
|
14
|
+
if (!value) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
return new Date(value).toLocaleString();
|
|
18
|
+
}
|
|
19
|
+
async function loadCommitData({
|
|
20
|
+
apiUrl,
|
|
21
|
+
owner,
|
|
22
|
+
repo,
|
|
23
|
+
commitRef
|
|
24
|
+
}) {
|
|
25
|
+
if (apiUrl) {
|
|
26
|
+
return fetchGithubViewData(apiUrl, {
|
|
27
|
+
owner,
|
|
28
|
+
repo,
|
|
29
|
+
ref: commitRef
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return getCommitDetails({
|
|
33
|
+
owner,
|
|
34
|
+
repo,
|
|
35
|
+
ref: commitRef
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export default function GithubCommit({
|
|
39
|
+
owner,
|
|
40
|
+
repo,
|
|
41
|
+
commitRef,
|
|
42
|
+
apiUrl,
|
|
43
|
+
private: privateMode = false,
|
|
44
|
+
data
|
|
45
|
+
}) {
|
|
46
|
+
const [commitData, setCommitData] = React.useState(data || null);
|
|
47
|
+
const [loading, setLoading] = React.useState(!data && !privateMode);
|
|
48
|
+
const [error, setError] = React.useState(null);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
if (privateMode) {
|
|
51
|
+
setCommitData(data || null);
|
|
52
|
+
setLoading(false);
|
|
53
|
+
setError(data ? null : 'Private mode requires pre-generated snapshot data.');
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (data) {
|
|
57
|
+
setCommitData(data);
|
|
58
|
+
setLoading(false);
|
|
59
|
+
setError(null);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
let active = true;
|
|
63
|
+
setLoading(true);
|
|
64
|
+
setError(null);
|
|
65
|
+
setCommitData(null);
|
|
66
|
+
loadCommitData({
|
|
67
|
+
apiUrl,
|
|
68
|
+
owner,
|
|
69
|
+
repo,
|
|
70
|
+
commitRef
|
|
71
|
+
}).then(nextData => {
|
|
72
|
+
if (!active) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
setCommitData(nextData);
|
|
76
|
+
}).catch(nextError => {
|
|
77
|
+
if (!active) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
setError(nextError instanceof Error ? nextError.message : 'Failed to load commit data.');
|
|
81
|
+
}).finally(() => {
|
|
82
|
+
if (active) {
|
|
83
|
+
setLoading(false);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
active = false;
|
|
88
|
+
};
|
|
89
|
+
}, [apiUrl, commitRef, data, owner, privateMode, repo]);
|
|
90
|
+
const commitBody = commitData && commitData.message !== commitData.summary ? commitData.message.replace(commitData.summary, '').trim() : '';
|
|
91
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
92
|
+
sx: {
|
|
93
|
+
p: 2
|
|
94
|
+
},
|
|
95
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
96
|
+
sx: {
|
|
97
|
+
mb: 2
|
|
98
|
+
},
|
|
99
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
100
|
+
sx: {
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flexWrap: 'wrap',
|
|
103
|
+
gap: 1,
|
|
104
|
+
mb: 1.5
|
|
105
|
+
},
|
|
106
|
+
children: [/*#__PURE__*/_jsx(Chip, {
|
|
107
|
+
label: `${owner}/${repo}`,
|
|
108
|
+
size: "small",
|
|
109
|
+
color: "primary",
|
|
110
|
+
variant: "outlined"
|
|
111
|
+
}), /*#__PURE__*/_jsx(Chip, {
|
|
112
|
+
label: (commitData == null ? void 0 : commitData.shortRef) || commitRef,
|
|
113
|
+
size: "small"
|
|
114
|
+
}), commitData ? /*#__PURE__*/_jsx(Chip, {
|
|
115
|
+
label: `${commitData.stats.changedFiles} file${commitData.stats.changedFiles === 1 ? '' : 's'} changed`,
|
|
116
|
+
size: "small",
|
|
117
|
+
variant: "outlined"
|
|
118
|
+
}) : null]
|
|
119
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
|
120
|
+
variant: "h6",
|
|
121
|
+
component: "h2",
|
|
122
|
+
sx: {
|
|
123
|
+
mb: 1
|
|
124
|
+
},
|
|
125
|
+
children: commitData != null && commitData.url ? /*#__PURE__*/_jsx(Link, {
|
|
126
|
+
href: commitData.url,
|
|
127
|
+
target: "_blank",
|
|
128
|
+
rel: "noopener noreferrer",
|
|
129
|
+
underline: "hover",
|
|
130
|
+
children: commitData.summary
|
|
131
|
+
}) : commitRef
|
|
132
|
+
}), commitBody ? /*#__PURE__*/_jsx(Typography, {
|
|
133
|
+
variant: "body2",
|
|
134
|
+
color: "text.secondary",
|
|
135
|
+
sx: {
|
|
136
|
+
whiteSpace: 'pre-line',
|
|
137
|
+
mb: 1
|
|
138
|
+
},
|
|
139
|
+
children: commitBody
|
|
140
|
+
}) : null, commitData != null && commitData.committedAt ? /*#__PURE__*/_jsxs(Typography, {
|
|
141
|
+
variant: "body2",
|
|
142
|
+
color: "text.secondary",
|
|
143
|
+
children: ["Committed ", formatCommitDate(commitData.committedAt)]
|
|
144
|
+
}) : null]
|
|
145
|
+
}), loading ? /*#__PURE__*/_jsx(Box, {
|
|
146
|
+
sx: {
|
|
147
|
+
display: 'flex',
|
|
148
|
+
justifyContent: 'center',
|
|
149
|
+
py: 4
|
|
150
|
+
},
|
|
151
|
+
children: _CircularProgress || (_CircularProgress = /*#__PURE__*/_jsx(CircularProgress, {}))
|
|
152
|
+
}) : null, error ? /*#__PURE__*/_jsx(Typography, {
|
|
153
|
+
color: "error",
|
|
154
|
+
sx: {
|
|
155
|
+
mb: 2
|
|
156
|
+
},
|
|
157
|
+
children: error
|
|
158
|
+
}) : null, commitData ? /*#__PURE__*/_jsxs(React.Fragment, {
|
|
159
|
+
children: [/*#__PURE__*/_jsx(GithubContributorsList, {
|
|
160
|
+
contributors: [commitData.contributor],
|
|
161
|
+
title: "Contributor"
|
|
162
|
+
}), /*#__PURE__*/_jsx(PullRequestView, {
|
|
163
|
+
title: "",
|
|
164
|
+
number: 0,
|
|
165
|
+
commits: commitData.commits,
|
|
166
|
+
files: commitData.files
|
|
167
|
+
})]
|
|
168
|
+
}) : null]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RequestError } from '@octokit/request-error';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
repo?: string;
|
|
8
|
-
action?: string;
|
|
9
|
-
date?: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
};
|
|
12
|
-
export declare function githubEventsQuery({ query, githubUser, githubToken }: {
|
|
13
|
-
query: EventsQuery;
|
|
14
|
-
githubUser: string;
|
|
15
|
-
githubToken?: string;
|
|
16
|
-
}): Promise<{
|
|
17
|
-
events: GitHubEvent[];
|
|
18
|
-
total: number;
|
|
19
|
-
repositories: string[];
|
|
20
|
-
actionTypes: string[];
|
|
21
|
-
page: number;
|
|
22
|
-
per_page: number;
|
|
23
|
-
total_pages: number;
|
|
24
|
-
total_fetched_events: number;
|
|
25
|
-
max_pages_fetched: number;
|
|
26
|
-
}>;
|
|
3
|
+
import { githubEventsQuery } from '../apiHandlers/getGithubEvents';
|
|
4
|
+
import type { EventsQuery } from '../apiHandlers/getGithubEvents';
|
|
5
|
+
export { githubEventsQuery };
|
|
6
|
+
export type { EventsQuery };
|
|
27
7
|
export interface GetEventsParams {
|
|
28
8
|
githubUser: string;
|
|
29
9
|
githubToken?: string;
|