diff --git a/package.json b/package.json
index 9faa850352a..b6b023c70c4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "scratch-gui",
- "version": "3.7.0",
+ "version": "3.8.0",
"private": true,
"description": "MistWarp editor, player, and community site",
"author": "MistWarp contributors",
diff --git a/src/community/api/git.js b/src/community/api/git.js
index f45bc95bdf8..9563ed718ea 100644
--- a/src/community/api/git.js
+++ b/src/community/api/git.js
@@ -36,6 +36,13 @@ export default {
`/projects/${id}/commits/${encodeURIComponent(sha)}/changes${projectAccessQuery()}`,
{cache: false, timeoutMs: SLOW_GET_TIMEOUT}
),
+ commitSummaries: (id, shas) => {
+ const params = new URLSearchParams(projectAccessQuery().replace(/^\?/, ''));
+ params.set('shas', shas.join(','));
+ return request(`/projects/${id}/commit-summaries?${params.toString()}`, {
+ cache: false, timeoutMs: SLOW_GET_TIMEOUT
+ });
+ },
commitTree: (id, sha) => request(
`/projects/${id}/commits/${encodeURIComponent(sha)}/tree${projectAccessQuery()}`,
{cache: false, timeoutMs: SLOW_GET_TIMEOUT}
diff --git a/src/community/commit-summary.js b/src/community/commit-summary.js
new file mode 100644
index 00000000000..f0a021b7254
--- /dev/null
+++ b/src/community/commit-summary.js
@@ -0,0 +1,99 @@
+const DEFAULT_MESSAGES = new Set(['', 'initial version', 'updated project', 'save project', 'untitled commit']);
+
+export const SUMMARY_BATCH = 50;
+export const SUMMARY_LIMIT = 100;
+
+export const commitSubject = message => String(message || '').split('\n')[0].trim();
+
+export const isDefaultCommitMessage = message => DEFAULT_MESSAGES.has(commitSubject(message).toLowerCase());
+
+const formatList = (names, locale) => {
+ try {
+ return new Intl.ListFormat(locale ? [locale] : [], {style: 'long', type: 'conjunction'}).format(names);
+ } catch {
+ return names.join(', ');
+ }
+};
+
+export const summaryPlace = (summary, text, locale) => {
+ const names = Array.isArray(summary?.sprites) ? summary.sprites.filter(Boolean) : [];
+ const count = Math.max(Number(summary?.spriteCount) || 0, names.length);
+ if (!count) return '';
+ if (count <= 3 && names.length === count) return formatList(names, locale);
+ return text('{value1} sprites', {value1: count});
+};
+
+const sum = values => values.reduce((total, value) => total + (Number(value) || 0), 0);
+
+export const commitSummarySentence = (summary, text, locale) => {
+ if (!summary || summary.ok === false || summary.legacy) return '';
+ const totals = summary.totals || {};
+ const scripts = totals.scripts || {};
+ const assets = totals.assets || {};
+ const scriptCount = sum([scripts.added, scripts.removed, scripts.changed, scripts.moved]);
+ const assetCount = sum([assets.added, assets.removed, assets.modified]);
+ const files = Number(summary.authoredFiles) || 0;
+ const place = summaryPlace(summary, text, locale);
+ if (scriptCount && place) {
+ if (scriptCount === Number(scripts.added)) {
+ return scriptCount === 1 ?
+ text('Added 1 script in {value1}', {value1: place}) :
+ text('Added {value1} scripts in {value2}', {value1: scriptCount, value2: place});
+ }
+ if (scriptCount === Number(scripts.removed)) {
+ return scriptCount === 1 ?
+ text('Removed 1 script in {value1}', {value1: place}) :
+ text('Removed {value1} scripts in {value2}', {value1: scriptCount, value2: place});
+ }
+ return scriptCount === 1 ?
+ text('Changed 1 script in {value1}', {value1: place}) :
+ text('Changed {value1} scripts in {value2}', {value1: scriptCount, value2: place});
+ }
+ if (assetCount && place) {
+ return assetCount === 1 ?
+ text('Changed 1 costume or sound in {value1}', {value1: place}) :
+ text('Changed {value1} costumes and sounds in {value2}', {value1: assetCount, value2: place});
+ }
+ if (assetCount) {
+ return assetCount === 1 ?
+ text('Changed 1 asset file') :
+ text('Changed {value1} asset files', {value1: assetCount});
+ }
+ if (Number(totals.items) && place) {
+ return text('Changed variables, lists or settings in {value1}', {value1: place});
+ }
+ if (summary.tooLarge && place) {
+ return text('Changed {value1}, too large to summarize', {value1: place});
+ }
+ if (files) {
+ return files === 1 ?
+ text('Changed 1 project file') :
+ text('Changed {value1} project files', {value1: files});
+ }
+ if (totals.stateOnly || Number(totals.state)) return text('Only saved state changed');
+ return text('No changes to how the project runs');
+};
+
+export const commitHeadline = (message, summary, text, locale) => {
+ const subject = commitSubject(message);
+ const sentence = commitSummarySentence(summary, text, locale);
+ if (isDefaultCommitMessage(subject) && sentence) return {title: sentence, detail: ''};
+ return {title: subject || text('Untitled commit'), detail: sentence};
+};
+
+export const pendingSummaryShas = (shas, known, limit = SUMMARY_LIMIT) => {
+ const seen = new Set();
+ const pending = [];
+ for (const sha of shas.slice(0, limit)) {
+ if (!/^[a-f0-9]{40}$/.test(String(sha)) || seen.has(sha) || known.has(sha)) continue;
+ seen.add(sha);
+ pending.push(sha);
+ }
+ return pending;
+};
+
+export const chunk = (values, size = SUMMARY_BATCH) => {
+ const chunks = [];
+ for (let index = 0; index < values.length; index += size) chunks.push(values.slice(index, index + size));
+ return chunks;
+};
diff --git a/src/community/components/GitGraph.jsx b/src/community/components/GitGraph.jsx
index 4e76ec6ef01..aa740aa5c0b 100644
--- a/src/community/components/GitGraph.jsx
+++ b/src/community/components/GitGraph.jsx
@@ -3,6 +3,7 @@ import {useCommunityIntl as useCommunityText} from '../i18n.jsx';
import React, {useMemo} from 'react';
import {Link} from 'react-router-dom';
import {safeDate} from '../format.js';
+import {commitHeadline} from '../commit-summary.js';
import UserLink from './UserLink.jsx';
import {LANE_WIDTH, PADDING, layoutGraph} from '../../lib/git/graph-layout.js';
import styles from './GitGraph.module.css';
@@ -15,7 +16,7 @@ const point = node => ({
y: (node.row * ROW_HEIGHT) + (ROW_HEIGHT / 2)
});
-const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectId = ''}) => {
+const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectId = '', summaries = null}) => {
const {text: communityText} = useCommunityText();
const layout = useMemo(() => layoutGraph(graph, currentBranch), [graph, currentBranch]);
if (!layout.rows.length) return null;
@@ -60,6 +61,8 @@ const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectI
graph.branchLogs?.find(entry => entry.branch === branch)?.oids?.[0] === node.sha);
const nodeDate = safeDate(node.date);
const commitUrl = projectId ? `/project/${projectId}/commits/${node.sha}` : '';
+ const summary = summaries?.[node.sha];
+ const headline = commitHeadline(node.message, summary, communityText, getCommunityLocale());
return (
{commitUrl ? (
@@ -68,7 +71,7 @@ const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectI
to={commitUrl}
aria-current={node.sha === currentHead ? 'page' : null}
aria-label={communityText('View commit {value1}', {
- value1: (node.message || node.sha).split('\n')[0]
+ value1: headline.title
})}
/>
) : null}
@@ -76,7 +79,7 @@ const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectI
{tipBranches.map(branch => (
{branch}
))}
- {(node.message || 'Untitled commit').split('\n')[0]}
+ {headline.title}
{node.sha.slice(0, 7)}
@@ -90,6 +93,9 @@ const GitGraph = ({graph, currentBranch = 'main', onRestore, restoring, projectI
{nodeDate.toLocaleString(getCommunityLocale())}
) : null}
+ {headline.detail ? (
+
{headline.detail}
+ ) : null}
{onRestore && node.sha !== currentHead ? (