@stoked-ui/github 0.0.0-a.0 → 0.1.0-alpha.11.2

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.
Files changed (87) hide show
  1. package/GithubBranch/GithubBranch.d.ts +12 -0
  2. package/GithubBranch/GithubBranch.js +177 -0
  3. package/GithubBranch/index.d.ts +2 -0
  4. package/GithubBranch/index.js +2 -0
  5. package/GithubBranch/package.json +6 -0
  6. package/GithubCalendar/GithubCalendar.d.ts +6 -2
  7. package/GithubCalendar/GithubCalendar.js +70 -28
  8. package/GithubCommit/GithubCommit.d.ts +11 -0
  9. package/GithubCommit/GithubCommit.js +170 -0
  10. package/GithubCommit/index.d.ts +2 -0
  11. package/GithubCommit/index.js +2 -0
  12. package/GithubCommit/package.json +6 -0
  13. package/GithubEvents/EventTypes/PullRequest/PullRequestEvent.js +1 -1
  14. package/GithubEvents/GithubEvents.d.ts +4 -24
  15. package/GithubEvents/GithubEvents.js +141 -220
  16. package/apiHandlers/createGithubBranchHandler.d.ts +12 -0
  17. package/apiHandlers/createGithubBranchHandler.js +41 -0
  18. package/apiHandlers/createGithubCommitHandler.d.ts +12 -0
  19. package/apiHandlers/createGithubCommitHandler.js +39 -0
  20. package/apiHandlers/createGithubContributionsHandler.d.ts +15 -0
  21. package/apiHandlers/createGithubContributionsHandler.js +41 -0
  22. package/apiHandlers/createGithubEventsHandler.d.ts +15 -0
  23. package/apiHandlers/createGithubEventsHandler.js +50 -0
  24. package/apiHandlers/getBranchCompareDetails.d.ts +9 -0
  25. package/apiHandlers/getBranchCompareDetails.js +29 -0
  26. package/apiHandlers/getCommitDetails.d.ts +8 -0
  27. package/apiHandlers/getCommitDetails.js +34 -0
  28. package/apiHandlers/getGithubContributions.d.ts +8 -0
  29. package/apiHandlers/getGithubContributions.js +126 -0
  30. package/apiHandlers/getGithubEvents.d.ts +25 -0
  31. package/apiHandlers/getGithubEvents.js +142 -0
  32. package/apiHandlers/getPullRequestDetails.js +2 -2
  33. package/apiHandlers/githubApi.d.ts +17 -0
  34. package/apiHandlers/githubApi.js +155 -0
  35. package/apiHandlers/index.d.ts +9 -0
  36. package/apiHandlers/index.js +9 -1
  37. package/components/GithubContributorsList.d.ts +8 -0
  38. package/components/GithubContributorsList.js +72 -0
  39. package/components/fetchGithubViewData.d.ts +1 -0
  40. package/components/fetchGithubViewData.js +10 -0
  41. package/index.d.ts +7 -3
  42. package/index.js +6 -4
  43. package/modern/GithubBranch/GithubBranch.js +177 -0
  44. package/modern/GithubBranch/index.js +2 -0
  45. package/modern/GithubCalendar/GithubCalendar.js +70 -28
  46. package/modern/GithubCommit/GithubCommit.js +170 -0
  47. package/modern/GithubCommit/index.js +2 -0
  48. package/modern/GithubEvents/EventTypes/PullRequest/PullRequestEvent.js +1 -1
  49. package/modern/GithubEvents/GithubEvents.js +141 -220
  50. package/modern/apiHandlers/createGithubBranchHandler.js +41 -0
  51. package/modern/apiHandlers/createGithubCommitHandler.js +39 -0
  52. package/modern/apiHandlers/createGithubContributionsHandler.js +41 -0
  53. package/modern/apiHandlers/createGithubEventsHandler.js +50 -0
  54. package/modern/apiHandlers/getBranchCompareDetails.js +29 -0
  55. package/modern/apiHandlers/getCommitDetails.js +34 -0
  56. package/modern/apiHandlers/getGithubContributions.js +126 -0
  57. package/modern/apiHandlers/getGithubEvents.js +142 -0
  58. package/modern/apiHandlers/getPullRequestDetails.js +2 -2
  59. package/modern/apiHandlers/githubApi.js +155 -0
  60. package/modern/apiHandlers/index.js +9 -1
  61. package/modern/components/GithubContributorsList.js +72 -0
  62. package/modern/components/fetchGithubViewData.js +10 -0
  63. package/modern/index.js +6 -4
  64. package/node/GithubBranch/GithubBranch.js +185 -0
  65. package/node/GithubBranch/index.js +9 -0
  66. package/node/GithubCalendar/GithubCalendar.js +70 -28
  67. package/node/GithubCommit/GithubCommit.js +178 -0
  68. package/node/GithubCommit/index.js +9 -0
  69. package/node/GithubEvents/EventTypes/PullRequest/PullRequestEvent.js +1 -1
  70. package/node/GithubEvents/GithubEvents.js +148 -223
  71. package/node/apiHandlers/createGithubBranchHandler.js +48 -0
  72. package/node/apiHandlers/createGithubCommitHandler.js +46 -0
  73. package/node/apiHandlers/createGithubContributionsHandler.js +48 -0
  74. package/node/apiHandlers/createGithubEventsHandler.js +57 -0
  75. package/node/apiHandlers/getBranchCompareDetails.js +35 -0
  76. package/node/apiHandlers/getCommitDetails.js +40 -0
  77. package/node/apiHandlers/getGithubContributions.js +132 -0
  78. package/node/apiHandlers/getGithubEvents.js +149 -0
  79. package/node/apiHandlers/getPullRequestDetails.js +2 -2
  80. package/node/apiHandlers/githubApi.js +168 -0
  81. package/node/apiHandlers/index.js +64 -1
  82. package/node/components/GithubContributorsList.js +80 -0
  83. package/node/components/fetchGithubViewData.js +16 -0
  84. package/node/index.js +77 -2
  85. package/package.json +2 -5
  86. package/stoked-ui-github-0.1.0-alpha.11.2.tgz +0 -0
  87. package/types/github.d.ts +75 -11
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = GithubBranch;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
+ var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
11
+ var _CircularProgress2 = _interopRequireDefault(require("@mui/material/CircularProgress"));
12
+ var _Link = _interopRequireDefault(require("@mui/material/Link"));
13
+ var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
14
+ var _PullRequestView = _interopRequireDefault(require("../GithubEvents/EventTypes/PullRequest/PullRequestView"));
15
+ var _getBranchCompareDetails = _interopRequireDefault(require("../apiHandlers/getBranchCompareDetails"));
16
+ var _GithubContributorsList = _interopRequireDefault(require("../components/GithubContributorsList"));
17
+ var _fetchGithubViewData = _interopRequireDefault(require("../components/fetchGithubViewData"));
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ var _CircularProgress;
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
+ function getStatusColor(status) {
22
+ switch (status) {
23
+ case 'ahead':
24
+ case 'identical':
25
+ return 'success';
26
+ case 'behind':
27
+ return 'warning';
28
+ case 'diverged':
29
+ return 'info';
30
+ default:
31
+ return 'default';
32
+ }
33
+ }
34
+ async function loadBranchData({
35
+ apiUrl,
36
+ owner,
37
+ repo,
38
+ base,
39
+ head
40
+ }) {
41
+ if (apiUrl) {
42
+ return (0, _fetchGithubViewData.default)(apiUrl, {
43
+ owner,
44
+ repo,
45
+ base,
46
+ head
47
+ });
48
+ }
49
+ return (0, _getBranchCompareDetails.default)({
50
+ owner,
51
+ repo,
52
+ base,
53
+ head
54
+ });
55
+ }
56
+ function GithubBranch({
57
+ owner,
58
+ repo,
59
+ base,
60
+ head,
61
+ apiUrl,
62
+ private: privateMode = false,
63
+ data
64
+ }) {
65
+ const [branchData, setBranchData] = React.useState(data || null);
66
+ const [loading, setLoading] = React.useState(!data && !privateMode);
67
+ const [error, setError] = React.useState(null);
68
+ React.useEffect(() => {
69
+ if (privateMode) {
70
+ setBranchData(data || null);
71
+ setLoading(false);
72
+ setError(data ? null : 'Private mode requires pre-generated snapshot data.');
73
+ return undefined;
74
+ }
75
+ if (data) {
76
+ setBranchData(data);
77
+ setLoading(false);
78
+ setError(null);
79
+ return undefined;
80
+ }
81
+ let active = true;
82
+ setLoading(true);
83
+ setError(null);
84
+ setBranchData(null);
85
+ loadBranchData({
86
+ apiUrl,
87
+ owner,
88
+ repo,
89
+ base,
90
+ head
91
+ }).then(nextData => {
92
+ if (!active) {
93
+ return;
94
+ }
95
+ setBranchData(nextData);
96
+ }).catch(nextError => {
97
+ if (!active) {
98
+ return;
99
+ }
100
+ setError(nextError instanceof Error ? nextError.message : 'Failed to load branch data.');
101
+ }).finally(() => {
102
+ if (active) {
103
+ setLoading(false);
104
+ }
105
+ });
106
+ return () => {
107
+ active = false;
108
+ };
109
+ }, [apiUrl, base, data, head, owner, privateMode, repo]);
110
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
111
+ sx: {
112
+ p: 2
113
+ },
114
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
115
+ sx: {
116
+ mb: 2
117
+ },
118
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
119
+ sx: {
120
+ display: 'flex',
121
+ flexWrap: 'wrap',
122
+ gap: 1,
123
+ mb: 1.5
124
+ },
125
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
126
+ label: `${owner}/${repo}`,
127
+ size: "small",
128
+ color: "primary",
129
+ variant: "outlined"
130
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
131
+ label: head,
132
+ size: "small"
133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
134
+ label: `base: ${base}`,
135
+ size: "small",
136
+ variant: "outlined"
137
+ }), branchData ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
138
+ label: branchData.status,
139
+ size: "small",
140
+ color: getStatusColor(branchData.status)
141
+ }) : null]
142
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
143
+ variant: "h6",
144
+ component: "h2",
145
+ sx: {
146
+ mb: 1
147
+ },
148
+ children: branchData != null && branchData.url ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Link.default, {
149
+ href: branchData.url,
150
+ target: "_blank",
151
+ rel: "noopener noreferrer",
152
+ underline: "hover",
153
+ children: branchData.headRef
154
+ }) : head
155
+ }), branchData ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Typography.default, {
156
+ variant: "body2",
157
+ color: "text.secondary",
158
+ children: ["Comparing against ", branchData.baseRef, ". ", branchData.aheadBy, " ahead, ", branchData.behindBy, ' ', "behind, ", branchData.totalCommits, " commit", branchData.totalCommits === 1 ? '' : 's', " in the comparison."]
159
+ }) : null]
160
+ }), loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
161
+ sx: {
162
+ display: 'flex',
163
+ justifyContent: 'center',
164
+ py: 4
165
+ },
166
+ children: _CircularProgress || (_CircularProgress = /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress2.default, {}))
167
+ }) : null, error ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
168
+ color: "error",
169
+ sx: {
170
+ mb: 2
171
+ },
172
+ children: error
173
+ }) : null, branchData ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
174
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_GithubContributorsList.default, {
175
+ contributors: branchData.contributors,
176
+ title: "Contributors"
177
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PullRequestView.default, {
178
+ title: "",
179
+ number: 0,
180
+ commits: branchData.commits,
181
+ files: branchData.files
182
+ })]
183
+ }) : null]
184
+ });
185
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _GithubBranch = _interopRequireDefault(require("./GithubBranch"));
9
+ var _default = exports.default = _GithubBranch.default;
@@ -13,11 +13,45 @@ var _styles = require("@mui/material/styles");
13
13
  var _common = require("@stoked-ui/common");
14
14
  var _jsxRuntime = require("react/jsx-runtime");
15
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
- const defaultActivityData = {
17
- total: {},
18
- contributions: [],
19
- countLabel: 'Loading...'
20
- };
16
+ function formatActivityDate(date) {
17
+ const year = date.getFullYear();
18
+ const month = String(date.getMonth() + 1).padStart(2, '0');
19
+ const day = String(date.getDate()).padStart(2, '0');
20
+ return `${year}-${month}-${day}`;
21
+ }
22
+ function createFallbackActivityData() {
23
+ const year = new Date().getFullYear();
24
+ const start = new Date(year, 0, 1);
25
+ const end = new Date(year, 11, 31);
26
+ const contributions = [];
27
+ for (const date = new Date(start); date <= end; date.setDate(date.getDate() + 1)) {
28
+ contributions.push({
29
+ date: formatActivityDate(date),
30
+ count: 0,
31
+ level: 0
32
+ });
33
+ }
34
+ return {
35
+ total: {
36
+ [String(year)]: 0
37
+ },
38
+ contributions,
39
+ countLabel: 'Contribution data unavailable',
40
+ totalWeeks: Math.ceil(contributions.length / 7)
41
+ };
42
+ }
43
+ function buildCountLabel(total) {
44
+ const totalKeys = Object.keys(total).sort();
45
+ const all = Object.values(total).reduce((acc, curr) => acc + curr, 0);
46
+ if (totalKeys.length === 0) {
47
+ return `${all} contributions`;
48
+ }
49
+ return `${all} contributions from ${totalKeys[0]} to ${totalKeys[totalKeys.length - 1]}`;
50
+ }
51
+ function buildApiUrl(apiUrl, githubUser) {
52
+ const separator = apiUrl.includes('?') ? '&' : '?';
53
+ return `${apiUrl}${separator}username=${encodeURIComponent(githubUser)}`;
54
+ }
21
55
  function sleep(duration) {
22
56
  return new Promise(resolve => {
23
57
  setTimeout(() => {
@@ -26,6 +60,8 @@ function sleep(duration) {
26
60
  });
27
61
  }
28
62
  function GithubCalendar({
63
+ apiUrl,
64
+ githubUser,
29
65
  windowMode = false,
30
66
  containerMode = false,
31
67
  blockSize: inputBlockSize = 12,
@@ -33,7 +69,7 @@ function GithubCalendar({
33
69
  startImage = undefined
34
70
  }) {
35
71
  const [activityTheme, setActivityTheme] = React.useState('light');
36
- const [activityData, setActivityData] = React.useState(defaultActivityData);
72
+ const [activityData, setActivityData] = React.useState(() => createFallbackActivityData());
37
73
  const [activityLoading, setActivityLoading] = React.useState(true);
38
74
  const [activityHover, setActivityHover] = React.useState(false);
39
75
  const [activityLabels, setActivityLabels] = React.useState(false);
@@ -87,7 +123,10 @@ function GithubCalendar({
87
123
  const fetchActivityData = async () => {
88
124
  setActivityLoading(true);
89
125
  try {
90
- const response = await fetch('https://github-contributions-api.jogruber.de/v4/brian-stoker?yr=last');
126
+ if (!githubUser) {
127
+ throw new Error('githubUser is required');
128
+ }
129
+ const response = await fetch(apiUrl ? buildApiUrl(apiUrl, githubUser) : `https://github-contributions-api.jogruber.de/v4/${encodeURIComponent(githubUser)}?yr=last`);
91
130
  if (!response.ok) {
92
131
  throw new Error(`API error: ${response.status}`);
93
132
  }
@@ -101,40 +140,43 @@ function GithubCalendar({
101
140
  }
102
141
  return 0;
103
142
  }
104
- const earliestDate = data.contributions.filter(item => item.count > 0) // Filter items with count > 0
105
- .reduce((earliest, current) => {
106
- return !earliest || new Date(current.date) < new Date(earliest.date) ? current : earliest;
107
- }, null);
108
- const today = new Date();
109
- const year = today.getFullYear();
110
- const month = String(today.getMonth() + 1).padStart(2, '0'); // Month is 0-indexed
111
- const day = String(today.getDate()).padStart(2, '0');
112
- const formattedDate = `${year}-${month}-${day}`;
113
- const contribs = data.contributions.filter(contrib => contrib.date < formattedDate && (!earliestDate || contrib.date >= earliestDate.date));
114
- data.contributions = contribs.sort(compare);
143
+ const contributions = Array.isArray(data.contributions) ? data.contributions : [];
144
+ const contribs = [...contributions].sort(compare);
145
+ if (contribs.length === 0) {
146
+ throw new Error('Contribution API returned no usable activity data');
147
+ }
115
148
  const allJansSet = contribs.map(contrib => {
116
149
  return contrib.date.slice(2, 7);
117
150
  }).filter(yymm => yymm.slice(-2) === '01');
118
151
  const allJans = new Set(allJansSet);
119
152
  console.log('allJans', [...allJans]);
120
- const all = Object.values(data.total).reduce((acc, curr) => acc + curr, 0);
121
- const totalKeys = Object.keys(data.total);
122
- data.countLabel = `${all} contributions from ${totalKeys[0]} to ${totalKeys[totalKeys.length - 1]}`;
123
- data.totalWeeks = data.contributions.length / 7;
153
+ const total = data.total && Object.keys(data.total).length > 0 ? data.total : contribs.reduce((acc, contribution) => {
154
+ const year = contribution.date.slice(0, 4);
155
+ acc[year] = (acc[year] || 0) + contribution.count;
156
+ return acc;
157
+ }, {});
158
+ const countLabel = data.countLabel || buildCountLabel(total);
159
+ const totalWeeks = Math.ceil(contribs.length / 7);
160
+ const nextActivityData = {
161
+ total,
162
+ contributions: contribs,
163
+ countLabel,
164
+ totalWeeks
165
+ };
124
166
  if (inputBlockSize) {
125
- data.blockSize = inputBlockSize;
167
+ nextActivityData.blockSize = inputBlockSize;
126
168
  } else if (windowMode) {
127
- data.blockSize = Math.max(10, Math.floor(windowWidth / data.totalWeeks));
169
+ nextActivityData.blockSize = Math.max(10, Math.floor(windowWidth / totalWeeks));
128
170
  } else {
129
171
  if (elemSize.width) {
130
- data.blockSize = Math.max(10, Math.floor(elemSize.width / data.totalWeeks));
172
+ nextActivityData.blockSize = Math.max(10, Math.floor(elemSize.width / totalWeeks));
131
173
  }
132
174
  }
133
- setActivityData(data);
175
+ setActivityData(nextActivityData);
134
176
  } catch (err) {
135
177
  console.error(`Error fetching activity data: ${err instanceof Error ? err.message : String(err)}`);
136
178
  // Use fallback data if API fails
137
- setActivityData(defaultActivityData);
179
+ setActivityData(createFallbackActivityData());
138
180
  } finally {
139
181
  setActivityLoading(false);
140
182
  }
@@ -188,7 +230,7 @@ function GithubCalendar({
188
230
  }
189
231
  }
190
232
  };
191
- }, []);
233
+ }, [apiUrl, fx, githubUser]);
192
234
  const handleResize = () => {
193
235
  var _elementRef$current2;
194
236
  // Clear all animations first
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = GithubCommit;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
+ var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
11
+ var _CircularProgress2 = _interopRequireDefault(require("@mui/material/CircularProgress"));
12
+ var _Link = _interopRequireDefault(require("@mui/material/Link"));
13
+ var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
14
+ var _PullRequestView = _interopRequireDefault(require("../GithubEvents/EventTypes/PullRequest/PullRequestView"));
15
+ var _getCommitDetails = _interopRequireDefault(require("../apiHandlers/getCommitDetails"));
16
+ var _GithubContributorsList = _interopRequireDefault(require("../components/GithubContributorsList"));
17
+ var _fetchGithubViewData = _interopRequireDefault(require("../components/fetchGithubViewData"));
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ var _CircularProgress;
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
+ function formatCommitDate(value) {
22
+ if (!value) {
23
+ return '';
24
+ }
25
+ return new Date(value).toLocaleString();
26
+ }
27
+ async function loadCommitData({
28
+ apiUrl,
29
+ owner,
30
+ repo,
31
+ commitRef
32
+ }) {
33
+ if (apiUrl) {
34
+ return (0, _fetchGithubViewData.default)(apiUrl, {
35
+ owner,
36
+ repo,
37
+ ref: commitRef
38
+ });
39
+ }
40
+ return (0, _getCommitDetails.default)({
41
+ owner,
42
+ repo,
43
+ ref: commitRef
44
+ });
45
+ }
46
+ function GithubCommit({
47
+ owner,
48
+ repo,
49
+ commitRef,
50
+ apiUrl,
51
+ private: privateMode = false,
52
+ data
53
+ }) {
54
+ const [commitData, setCommitData] = React.useState(data || null);
55
+ const [loading, setLoading] = React.useState(!data && !privateMode);
56
+ const [error, setError] = React.useState(null);
57
+ React.useEffect(() => {
58
+ if (privateMode) {
59
+ setCommitData(data || null);
60
+ setLoading(false);
61
+ setError(data ? null : 'Private mode requires pre-generated snapshot data.');
62
+ return undefined;
63
+ }
64
+ if (data) {
65
+ setCommitData(data);
66
+ setLoading(false);
67
+ setError(null);
68
+ return undefined;
69
+ }
70
+ let active = true;
71
+ setLoading(true);
72
+ setError(null);
73
+ setCommitData(null);
74
+ loadCommitData({
75
+ apiUrl,
76
+ owner,
77
+ repo,
78
+ commitRef
79
+ }).then(nextData => {
80
+ if (!active) {
81
+ return;
82
+ }
83
+ setCommitData(nextData);
84
+ }).catch(nextError => {
85
+ if (!active) {
86
+ return;
87
+ }
88
+ setError(nextError instanceof Error ? nextError.message : 'Failed to load commit data.');
89
+ }).finally(() => {
90
+ if (active) {
91
+ setLoading(false);
92
+ }
93
+ });
94
+ return () => {
95
+ active = false;
96
+ };
97
+ }, [apiUrl, commitRef, data, owner, privateMode, repo]);
98
+ const commitBody = commitData && commitData.message !== commitData.summary ? commitData.message.replace(commitData.summary, '').trim() : '';
99
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
100
+ sx: {
101
+ p: 2
102
+ },
103
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
104
+ sx: {
105
+ mb: 2
106
+ },
107
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
108
+ sx: {
109
+ display: 'flex',
110
+ flexWrap: 'wrap',
111
+ gap: 1,
112
+ mb: 1.5
113
+ },
114
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
115
+ label: `${owner}/${repo}`,
116
+ size: "small",
117
+ color: "primary",
118
+ variant: "outlined"
119
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
120
+ label: (commitData == null ? void 0 : commitData.shortRef) || commitRef,
121
+ size: "small"
122
+ }), commitData ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
123
+ label: `${commitData.stats.changedFiles} file${commitData.stats.changedFiles === 1 ? '' : 's'} changed`,
124
+ size: "small",
125
+ variant: "outlined"
126
+ }) : null]
127
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
128
+ variant: "h6",
129
+ component: "h2",
130
+ sx: {
131
+ mb: 1
132
+ },
133
+ children: commitData != null && commitData.url ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Link.default, {
134
+ href: commitData.url,
135
+ target: "_blank",
136
+ rel: "noopener noreferrer",
137
+ underline: "hover",
138
+ children: commitData.summary
139
+ }) : commitRef
140
+ }), commitBody ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
141
+ variant: "body2",
142
+ color: "text.secondary",
143
+ sx: {
144
+ whiteSpace: 'pre-line',
145
+ mb: 1
146
+ },
147
+ children: commitBody
148
+ }) : null, commitData != null && commitData.committedAt ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Typography.default, {
149
+ variant: "body2",
150
+ color: "text.secondary",
151
+ children: ["Committed ", formatCommitDate(commitData.committedAt)]
152
+ }) : null]
153
+ }), loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
154
+ sx: {
155
+ display: 'flex',
156
+ justifyContent: 'center',
157
+ py: 4
158
+ },
159
+ children: _CircularProgress || (_CircularProgress = /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress2.default, {}))
160
+ }) : null, error ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
161
+ color: "error",
162
+ sx: {
163
+ mb: 2
164
+ },
165
+ children: error
166
+ }) : null, commitData ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
167
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_GithubContributorsList.default, {
168
+ contributors: [commitData.contributor],
169
+ title: "Contributor"
170
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PullRequestView.default, {
171
+ title: "",
172
+ number: 0,
173
+ commits: commitData.commits,
174
+ files: commitData.files
175
+ })]
176
+ }) : null]
177
+ });
178
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _GithubCommit = _interopRequireDefault(require("./GithubCommit"));
9
+ var _default = exports.default = _GithubCommit.default;
@@ -15,7 +15,7 @@ var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
15
15
  var _Button = _interopRequireDefault(require("@mui/material/Button"));
16
16
  var _CallMade = _interopRequireDefault(require("@mui/icons-material/CallMade"));
17
17
  var _PullRequestView = _interopRequireDefault(require("./PullRequestView"));
18
- var _apiHandlers = require("packages/sui-github/src/apiHandlers");
18
+ var _apiHandlers = require("../../../apiHandlers");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
20
  var _CheckoutIcon, _Typography2, _Typography3, _CircularProgress; // import Stack from '@mui/material/Stack';
21
21
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }