From 7e4833ce80cdba9728892d8a8248ef587b2f8c2b Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Sun, 22 Nov 2026 12:29:42 +0000 Subject: [PATCH 01/30] Let remix owners sync with the original and keep pull request merges on the live remix head --- package.json | 2 +- src/community/api/git.js | 7 +- src/community/components/ForkStatus.jsx | 156 ++++++++ .../components/ForkStatus.module.css | 49 +++ src/community/components/MergeConflicts.jsx | 93 +++++ .../components/MergeConflicts.module.css | 9 + src/community/components/ProjectBranches.jsx | 100 ++--- .../components/ProjectBranches.module.css | 9 +- src/community/merge-session.js | 58 +++ src/community/pages/ProjectCode.jsx | 24 +- src/community/pages/ProjectCode.module.css | 33 -- src/community/pages/PullRequest.jsx | 29 +- src/community/translations/_sources.json | 353 ++++++++++-------- src/community/translations/en.json | 12 +- src/lib/community/api.js | 2 + test/unit/community-fork-status.test.jsx | 170 +++++++++ test/unit/community-git-merge-api.test.js | 30 ++ test/unit/community-merge-session.test.js | 69 ++++ 18 files changed, 902 insertions(+), 303 deletions(-) create mode 100644 src/community/components/ForkStatus.jsx create mode 100644 src/community/components/ForkStatus.module.css create mode 100644 src/community/components/MergeConflicts.jsx create mode 100644 src/community/components/MergeConflicts.module.css create mode 100644 src/community/merge-session.js create mode 100644 test/unit/community-fork-status.test.jsx create mode 100644 test/unit/community-git-merge-api.test.js create mode 100644 test/unit/community-merge-session.test.js diff --git a/package.json b/package.json index 45d4b45069b..f4baae8a2b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scratch-gui", - "version": "3.13.0", + "version": "3.14.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 43c7e5d2d2d..14115d3a464 100644 --- a/src/community/api/git.js +++ b/src/community/api/git.js @@ -82,8 +82,11 @@ export default { }), mergePull: (id, index) => request(`/projects/${id}/pulls/${index}/merge`, {method: 'POST'}), closePull: (id, index) => request(`/projects/${id}/pulls/${index}/close`, {method: 'POST'}), - uploadPullMerge: (id, {sb3, mergeTree, expectedHead, pullId}) => - uploadProject(id, sb3, null, null, {mergeTree, expectedHead, pullId}), + uploadPullMerge: (id, {sb3, mergeTree, expectedHead, pullId, sourceHead}) => + uploadProject(id, sb3, null, null, {mergeTree, expectedHead, pullId, mergeSourceHead: sourceHead}), + syncRemix: id => request(`/projects/${id}/remix/sync`, {method: 'POST', timeoutMs: SLOW_GET_TIMEOUT}), + uploadRemixSync: (id, {sb3, mergeTree, expectedHead, syncHead}) => + uploadProject(id, sb3, null, null, {mergeTree, expectedHead, syncHead}), uploadBranchMerge: (id, {sb3, mergeTree, sourceBranch, targetBranch, sourceHead, targetHead}) => uploadProject(id, sb3, null, null, { mergeTree, diff --git a/src/community/components/ForkStatus.jsx b/src/community/components/ForkStatus.jsx new file mode 100644 index 00000000000..d6b1a2062ad --- /dev/null +++ b/src/community/components/ForkStatus.jsx @@ -0,0 +1,156 @@ +import PropTypes from 'prop-types'; +import React, {useState} from 'react'; +import {Link} from 'react-router-dom'; +import {GitFork, RefreshCw} from 'lucide-react'; +import {useCommunityIntl as useCommunityText} from '../i18n.jsx'; +import api from '../api'; +import {buildProjectArtifactsFromFileEntries} from '../../lib/git/mwp.js'; +import { + materializeMerge, resolvedMergeFiles, unresolvedBinaryConflict, withBinaryChoice, withTextResolution +} from '../merge-session.js'; +import {remixDivergenceSentence, remixParentLabel} from '../remix-origin.js'; +import MergeConflicts from './MergeConflicts.jsx'; +import Button from './ui/Button.jsx'; +import Notice from './ui/Notice.jsx'; +import styles from './ForkStatus.module.css'; + +const ForkStatus = ({canContribute, canSync, contributeHref, hasUncommitted, onSynced, projectId, remixFrom}) => { + const {text: communityText} = useCommunityText(); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(''); + const [notice, setNotice] = useState(''); + const [session, setSession] = useState(null); + const original = remixParentLabel(remixFrom); + const showSync = canSync && remixFrom.behind > 0 && !session; + // eslint-disable-next-line max-len + const conflictLead = communityText('This remix and {value1} changed the same files. Edit the text conflicts and choose which version of each asset to keep.', {value1: original}); + + const upload = async (data, files) => { + const artifacts = await buildProjectArtifactsFromFileEntries( + [...files].map(([path, fileData]) => ({path, data: fileData})) + ); + await api.uploadRemixSync(projectId, { + sb3: artifacts.sb3, + mergeTree: artifacts.tree, + expectedHead: data.expectedHead, + syncHead: data.sourceHead + }); + setSession(null); + setNotice(communityText('Brought in the latest changes from {value1}.', {value1: original})); + if (onSynced) await onSynced(); + }; + + const sync = async () => { + if (busy) return; + setBusy(true); + setError(''); + setNotice(''); + try { + const data = await api.syncRemix(projectId); + if (data.merge.alreadyMerged) { + setNotice(communityText('This remix already has every change from {value1}.', {value1: original})); + if (onSynced) await onSynced(); + return; + } + const prepared = await materializeMerge(data); + if (prepared.conflicts.length || prepared.binaryConflicts.length) { + setSession({...prepared, data}); + } else { + await upload(data, prepared.files); + } + } catch (syncError) { + setError(syncError.message || communityText('Could not sync this remix.')); + } finally { + setBusy(false); + } + }; + + const resolve = async () => { + if (!session || busy) return; + setBusy(true); + setError(''); + try { + const unresolved = unresolvedBinaryConflict(session); + if (unresolved) throw new Error(communityText('Choose a version for {value1}.', {value1: unresolved.path})); + await upload(session.data, resolvedMergeFiles(session)); + } catch (resolveError) { + setError(resolveError.message || communityText('Could not sync this remix.')); + } finally { + setBusy(false); + } + }; + + return ( +
+
+

+

+ {canContribute ? ( + + {communityText('Contribute')} + + ) : null} + {showSync ? ( + + ) : null} +
+ {showSync && hasUncommitted ? ( +

+ {communityText('Commit your saved changes in the editor before syncing, so they are not replaced.')} +

+ ) : null} + {error ? {error} : null} + {notice ? setNotice('')}>{notice} : null} + {session ? ( + setSession(current => withTextResolution(current, path, content))} + onChoose={(path, choice) => setSession(current => withBinaryChoice(current, path, choice))} + onSubmit={resolve} + actions={( + + )} + /> + ) : null} +
+ ); +}; + +ForkStatus.propTypes = { + canContribute: PropTypes.bool, + canSync: PropTypes.bool, + contributeHref: PropTypes.string, + hasUncommitted: PropTypes.bool, + onSynced: PropTypes.func, + projectId: PropTypes.string.isRequired, + remixFrom: PropTypes.shape({ + ahead: PropTypes.number, + behind: PropTypes.number, + owner: PropTypes.string, + title: PropTypes.string + }).isRequired +}; + +export default ForkStatus; diff --git a/src/community/components/ForkStatus.module.css b/src/community/components/ForkStatus.module.css new file mode 100644 index 00000000000..59c0a02cf2e --- /dev/null +++ b/src/community/components/ForkStatus.module.css @@ -0,0 +1,49 @@ +.forkStatusGroup { + display: grid; + gap: var(--space-2); +} + +.forkStatus { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: var(--space-2) var(--space-3); + padding: var(--space-3) var(--space-4); + border-radius: var(--radius-sm); + background: var(--bg-card); + box-shadow: var(--card-shadow); + color: var(--text-dim); + font-size: var(--fs-sm); +} + +.forkMessage { + display: flex; + flex: 1 1 260px; + align-items: flex-start; + gap: var(--space-2); + min-width: 0; + margin: 0; +} + +.forkMessage svg { + flex: none; + margin-top: 2px; + color: var(--text-faint); +} + +.forkAction { + flex: none; + color: var(--accent-strong); + font-weight: 600; +} + +.forkAction:hover { + text-decoration: underline; +} + +.hint { + margin: 0; + padding: 0 var(--space-4); + color: var(--text-dim); + font-size: var(--fs-sm); +} diff --git a/src/community/components/MergeConflicts.jsx b/src/community/components/MergeConflicts.jsx new file mode 100644 index 00000000000..01627047492 --- /dev/null +++ b/src/community/components/MergeConflicts.jsx @@ -0,0 +1,93 @@ +import PropTypes from 'prop-types'; +import React from 'react'; +import {GitMerge} from 'lucide-react'; +import Button from './ui/Button.jsx'; +import SectionHeading from './ui/SectionHeading.jsx'; +import styles from './MergeConflicts.module.css'; + +const MergeConflicts = ({ + actions, + binaryConflicts, + busy, + busyLabel, + conflicts, + keepLabel, + lead, + onChoose, + onSubmit, + onTextChange, + submitLabel, + title, + useLabel +}) => ( +
+ + {conflicts.map(file => ( +